Skip to content

Commit

Permalink
fix(db): drop NANGO_DB_MIGRATION_FOLDER (#2901)
Browse files Browse the repository at this point in the history
## Describe your changes

- Drop NANGO_DB_MIGRATION_FOLDER
I'm not sure why it was necessary but it has caused multiple issues
until now, without clear advantage. Tested locally and the new docker
image.
  • Loading branch information
bodinsamuel authored Oct 25, 2024
1 parent 83b033e commit 4c14316
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ services:
container_name: nango-server
platform: linux/amd64
environment:
- NANGO_DB_MIGRATION_FOLDER=/usr/nango-server/src/packages/database/lib/migrations
- NANGO_ENCRYPTION_KEY=${NANGO_ENCRYPTION_KEY}
- NANGO_DB_USER=${NANGO_DB_USER}
- NANGO_DB_PASSWORD=${NANGO_DB_PASSWORD}
Expand Down
1 change: 0 additions & 1 deletion packages/cli/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ services:
container_name: nango-server
platform: linux/amd64
environment:
- NANGO_DB_MIGRATION_FOLDER=/usr/nango-server/src/packages/database/lib/migrations
- NANGO_ENCRYPTION_KEY=${NANGO_ENCRYPTION_KEY}
- NANGO_DB_USER=${NANGO_DB_USER}
- NANGO_DB_PASSWORD=${NANGO_DB_PASSWORD}
Expand Down
10 changes: 7 additions & 3 deletions packages/database/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import path from 'node:path';
import knex from 'knex';
import type { Knex } from 'knex';
import { retry } from '@nangohq/utils';
import { defaultSchema, getDbConfig } from './getConfig.js';

// Note: we are in dist when it executes but migrations are not compiled
const directory = path.join(import.meta.dirname, '../lib/migrations');

export class KnexDatabase {
knex: Knex;

Expand All @@ -11,7 +15,7 @@ export class KnexDatabase {
this.knex = knex(dbConfig);
}

async migrate(directory: string): Promise<any> {
async migrate(): Promise<any> {
return retry(
async () =>
await this.knex.migrate.latest({
Expand Down Expand Up @@ -49,15 +53,15 @@ export const multipleMigrations = async (): Promise<void> => {
await db.knex.raw(`CREATE SCHEMA IF NOT EXISTS ${db.schema()}`);

const [_, pendingMigrations] = await db.knex.migrate.list({
directory: String(process.env['NANGO_DB_MIGRATION_FOLDER'])
directory
});

if (pendingMigrations.length === 0) {
console.log('No pending migrations, skipping migration step.');
} else {
console.log('Migrations pending, running migrations.');
await db.knex.migrate.latest({
directory: String(process.env['NANGO_DB_MIGRATION_FOLDER'])
directory
});
console.log('Migrations completed.');
}
Expand Down
1 change: 0 additions & 1 deletion packages/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM node:20.12.2-slim

ENV SERVER_RUN_MODE=DOCKERIZED
ENV NANGO_DB_MIGRATION_FOLDER=./packages/database/lib/migrations

RUN apt-get update \
&& apt-get install -y ca-certificates \
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/utils/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { KnexDatabase } from '@nangohq/database';
export default async function migrate(db: KnexDatabase): Promise<void> {
logger.info('Migrating database ...');
await db.knex.raw(`CREATE SCHEMA IF NOT EXISTS ${db.schema()}`);
await db.migrate(process.env['NANGO_DB_MIGRATION_FOLDER'] || '../database/lib/migrations');
await db.migrate();
await encryptionManager.encryptDatabaseIfNeeded();
logger.info('✅ Migrated database');
}
1 change: 0 additions & 1 deletion packages/utils/lib/environment/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export const ENVS = z.object({
'To learn more about NANGO_ENCRYPTION_KEY, please read the doc at https://docs.nango.dev/host/self-host/self-hosting-instructions#encrypt-sensitive-data'
})
.optional(),
NANGO_DB_MIGRATION_FOLDER: z.string().optional(),
NANGO_DB_SCHEMA: z.string().optional().default('nango'),
NANGO_DB_ADDITIONAL_SCHEMAS: z.string().optional(),

Expand Down
1 change: 0 additions & 1 deletion tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ async function setupPostgres() {
process.env['NANGO_DB_USER'] = user;
process.env['NANGO_DB_PORT'] = port.toString();
process.env['NANGO_DB_NAME'] = dbName;
process.env['NANGO_DB_MIGRATION_FOLDER'] = './packages/database/lib/migrations';
process.env['TELEMETRY'] = 'false';
process.env['RECORDS_DATABASE_URL'] = `postgres://${user}:${password}@localhost:${port}/${dbName}`;
}
Expand Down

0 comments on commit 4c14316

Please sign in to comment.