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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# NANGO_DB_PORT=<PICK-A-PORT>
# NANGO_DB_NAME=<PICK-A-DB-NAME>
# NANGO_DB_SCHEMA=<PICK-A-SCHEMA-NAME>
# NANGO_DB_ADDITIONAL_SCHEMAS=<PICK-A-SEARCH-PATH>,<PICK-ANOTHER-SEARCH-PATH>
# NANGO_DB_SSL=<PICK-TRUE-OR-FALSE>
# Override these 2 variables to configure the database connection pool / tune it for your needs i.e. serverless databases.
# NANGO_DB_POOL_MIN=<PICK-INT-OR-SKIP>
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ services:
- NANGO_DB_HOST=${NANGO_DB_HOST}
- NANGO_DB_NAME=${NANGO_DB_NAME}
- NANGO_DB_SSL=${NANGO_DB_SSL}
- NANGO_DB_ADDITIONAL_SCHEMAS=${NANGO_DB_ADDITIONAL_SCHEMAS}
- NANGO_DB_POOL_MIN=${NANGO_DB_POOL_MIN}
- NANGO_DB_POOL_MAX=${NANGO_DB_POOL_MAX}
- RECORDS_DATABASE_URL=${RECORDS_DATABASE_URL:-postgresql://nango:nango@nango-db:5432/nango}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
- NANGO_DB_HOST=${NANGO_DB_HOST}
- NANGO_DB_NAME=${NANGO_DB_NAME}
- NANGO_DB_SSL=${NANGO_DB_SSL}
- NANGO_DB_ADDITIONAL_SCHEMAS=${NANGO_DB_ADDITIONAL_SCHEMAS}
- NANGO_DB_POOL_MIN=${NANGO_DB_POOL_MIN}
- NANGO_DB_POOL_MAX=${NANGO_DB_POOL_MAX}
- NANGO_PORT=${NANGO_PORT:-3003}
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/lib/db/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { metrics, retry } from '@nangohq/utils';
import type { Pool } from 'tarn';

const defaultSchema = process.env['NANGO_DB_SCHEMA'] || 'nango';
const additionalSchemas = process.env['NANGO_DB_ADDITIONAL_SCHEMAS']
? process.env['NANGO_DB_ADDITIONAL_SCHEMAS'].split(',').map((schema: string) => schema.trim())
: [];

export function getDbConfig({ timeoutMs }: { timeoutMs: number }): Knex.Config {
return {
Expand All @@ -22,7 +25,7 @@ export function getDbConfig({ timeoutMs }: { timeoutMs: number }): Knex.Config {
max: parseInt(process.env['NANGO_DB_POOL_MAX'] || '50')
},
// SearchPath needs the current db and public because extension can only be installed once per DB
searchPath: [defaultSchema, 'public']
searchPath: [defaultSchema, 'public', ...additionalSchemas]
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/utils/lib/environment/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const ENVS = z.object({
NANGO_ENCRYPTION_KEY: z.string().optional(),
NANGO_DB_MIGRATION_FOLDER: z.string().optional(),
NANGO_DB_SCHEMA: z.string().optional().default('nango'),
NANGO_DB_ADDITIONAL_SCHEMAS: z.array(z.string()).optional(),

// Records
RECORDS_DATABASE_URL: z.string().url().optional().default('postgres://nango:nango@localhost:5432/nango'), //TODO remove default and deal with default value in the records package (ie: envVar || mainDB || localhost )
Expand Down
Loading