Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db): add extensions to search_path #2143

Merged
merged 8 commits into from May 14, 2024
Merged

Conversation

t1mmen
Copy link
Contributor

@t1mmen t1mmen commented May 11, 2024

Describe your changes

Self-hosted using Supabase/Postgres also needs extensions in search_path to access uuid_generate_v4, else migrations fail.

  • Add extensions to search_path

Issue ticket number and link

Checklist before requesting a review (skip if just adding/editing APIs & templates)

Unsure how I'd test this, but given the ~same change didn't have tests, I'm hoping this is OK.


Docker logs pointing at problem:

2024-05-11 13:21:41 Node.js v20.12.2
2024-05-11 13:21:48 2024-05-11T20:21:48.268Z [INFO] [Server] Migrating database ...
2024-05-11 13:21:48 migration file "20230324135032_alter_secret_from_account.cjs" failed
2024-05-11 13:21:48 migration failed with error: alter table "_nango_accounts" alter column "secret_key" set default uuid_generate_v4() - function uuid_generate_v4() does not exist
2024-05-11 13:21:51 2024-05-11T20:21:51.994Z [INFO] [Server] Migrating database ...
2024-05-11 13:21:52 migration file "20230324135032_alter_secret_from_account.cjs" failed
2024-05-11 13:21:52 migration failed with error: alter table "_nango_accounts" alter column "secret_key" set default uuid_generate_v4() - function uuid_generate_v4() does not exist
2024-05-11 13:21:56 2024-05-11T20:21:56.083Z [INFO] [Server] Migrating database ...
2024-05-11 13:21:56 migration file "20230324135032_alter_secret_from_account.cjs" failed
2024-05-11 13:21:56 migration failed with error: alter table "_nango_accounts" alter column "secret_key" set default uuid_generate_v4() - function uuid_generate_v4() does not exist
2024-05-11 13:21:45 node:internal/process/esm_loader:34
2024-05-11 13:21:45       internalBinding('errors').triggerUncaughtException(
2024-05-11 13:21:45                                 ^
2024-05-11 13:21:45 
2024-05-11 13:21:45 error: function uuid_generate_v4() does not exist
2024-05-11 13:21:45     at Parser.parseErrorMessage (/usr/nango-server/src/node_modules/pg-protocol/dist/parser.js:287:98)
2024-05-11 13:21:45     at Parser.handlePacket (/usr/nango-server/src/node_modules/pg-protocol/dist/parser.js:126:29)
2024-05-11 13:21:45     at Parser.parse (/usr/nango-server/src/node_modules/pg-protocol/dist/parser.js:39:38)
2024-05-11 13:21:45     at Socket.<anonymous> (/usr/nango-server/src/node_modules/pg-protocol/dist/index.js:11:42)
2024-05-11 13:21:45     at Socket.emit (node:events:518:28)
2024-05-11 13:21:45     at Socket.emit (node:domain:488:12)
2024-05-11 13:21:45     at Socket.emit (/usr/nango-server/src/node_modules/dd-trace/packages/datadog-instrumentations/src/net.js:69:25)
2024-05-11 13:21:45     at addChunk (node:internal/streams/readable:559:12)
2024-05-11 13:21:45     at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
2024-05-11 13:21:45     at Readable.push (node:internal/streams/readable:390:5)
2024-05-11 13:21:45     at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
2024-05-11 13:21:45     at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
2024-05-11 13:21:45   length: 207,
2024-05-11 13:21:45   severity: 'ERROR',
2024-05-11 13:21:45   code: '42883',
2024-05-11 13:21:45   detail: undefined,
2024-05-11 13:21:45   hint: 'No function matches the given name and argument types. You might need to add explicit type casts.',
2024-05-11 13:21:45   position: undefined,
2024-05-11 13:21:45   internalPosition: undefined,
2024-05-11 13:21:45   internalQuery: undefined,
2024-05-11 13:21:45   where: undefined,
2024-05-11 13:21:45   schema: undefined,
2024-05-11 13:21:45   table: undefined,
2024-05-11 13:21:45   column: undefined,
2024-05-11 13:21:45   dataType: undefined,
2024-05-11 13:21:45   constraint: undefined,
2024-05-11 13:21:45   file: 'parse_func.c',
2024-05-11 13:21:45   line: '629',
2024-05-11 13:21:45   routine: 'ParseFuncOrColumn'
2024-05-11 13:21:45 }

Verifying the location of extension:
CleanShot 2024-05-11 at 13 36 42

### Describe your changes

References NAN-757

Ref NangoHQ#2002, self-hosted using Supabase/Postgres also needs `extensions` in `search_path` to access `uuid_generate_v4`

* Add `extensions` to `search_path`
@t1mmen
Copy link
Contributor Author

t1mmen commented May 13, 2024

Fixed merge conflicts. With the introduction of defaultSchema, you may want to consider an extraSchemas or similar to be configured (as presumably, this "which schema has extensions" problem will re-appear for other db configs/cloud providers)

@bodinsamuel
Copy link
Contributor

Hey @t1mmen thanks for your contribution, this is definitely a topic that will pop regularly with custom install.
I was going to say that, can you make searchPath an array and add to this array NANGO_DB_ADDITIONAL_SEARCH_PATH (or something clear like this) if it's filled? We want to keep DB_SCHEMA and public as the default to avoid breaking change
happy to take over if you want ☺️

@bodinsamuel bodinsamuel self-requested a review May 13, 2024 18:29
@t1mmen
Copy link
Contributor Author

t1mmen commented May 13, 2024

@bodinsamuel Done, I think.

  • I kept public hard-coded to avoid breaking any backwards compatibility.
  • Used NANGO_DB_ADDITIONAL_SCHEMAS to keep naming more consistent with NANGO_DB_SCHEMA (instead of ...SEARCH_PATH)
  • Not 100% sure on the passing of the new env var to docker, but seemed sensible, so added them.

Copy link
Contributor

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems perfect to me thanks 💪🏻
I'll let the rest of the team catch up with the PR and we can merge this!

@bodinsamuel bodinsamuel enabled auto-merge (squash) May 14, 2024 08:47
@bodinsamuel bodinsamuel merged commit 1b1c768 into NangoHQ:master May 14, 2024
17 of 19 checks passed
bodinsamuel added a commit that referenced this pull request May 14, 2024
## Describe your changes

Follow up of #2143 

Didn't realize when reviewing that it could not be an array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants