diff --git a/packages/cli/src/Db.ts b/packages/cli/src/Db.ts index 07feb7422f..2cdead7651 100644 --- a/packages/cli/src/Db.ts +++ b/packages/cli/src/Db.ts @@ -164,7 +164,7 @@ export async function init(): Promise { CreateIndexStoppedAt1594825041918, MakeStoppedAtNullable1607431743769, ], - migrationsRun: true, + migrationsRun: false, // migrations for sqlite will be ran manually for now; see below migrationsTableName: `${entityPrefix}migrations`, }; break; @@ -181,27 +181,26 @@ export async function init(): Promise { let connection = await createConnection(connectionOptions); - let mustReconnect = false; if (dbType === 'sqlite') { // This specific migration changes database metadata. // A field is now nullable. We need to reconnect so that // n8n knows it has changed. Happens only on sqlite. - const migrations = await connection.query('SELECT id FROM migrations where name = "MakeStoppedAtNullable1607431743769"'); + const migrations = await connection.query(`SELECT id FROM ${entityPrefix}migrations where name = "MakeStoppedAtNullable1607431743769"`); + + // If you remove this call, remember to turn back on the + // setting to run migrations automatically above. + await connection.runMigrations({ + transaction: 'none', + }); + if (migrations.length === 0) { - mustReconnect = true; + await connection.close(); + connection = await createConnection(connectionOptions); } } - await connection.runMigrations({ - transaction: 'none', - }); - if (mustReconnect) { - console.log('is reconnecting'); - await connection.close(); - connection = await createConnection(connectionOptions); - } collections.Credentials = getRepository(entities.CredentialsEntity); diff --git a/packages/cli/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.ts b/packages/cli/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.ts index bed94ea48c..5f0a05c02c 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.ts @@ -3,10 +3,15 @@ import {MigrationInterface, QueryRunner} from "typeorm"; import * as config from '../../../../config'; export class MakeStoppedAtNullable1607431743768 implements MigrationInterface { + name = 'MakeStoppedAtNullable1607431743768'; async up(queryRunner: QueryRunner): Promise { - const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.query('ALTER TABLE `' + tablePrefix + 'execution_entity` ALTER COLUMN `stoppedAt` DROP NOT NULL', undefined); + let tablePrefix = config.get('database.tablePrefix'); + const schema = config.get('database.postgresdb.schema'); + if (schema) { + tablePrefix = schema + '.' + tablePrefix; + } + await queryRunner.query('ALTER TABLE ' + tablePrefix + 'execution_entity ALTER COLUMN "stoppedAt" DROP NOT NULL', undefined); } async down(queryRunner: QueryRunner): Promise {