mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-20 18:49:27 -08:00
Reload database on migration run
This commit is contained in:
parent
ca6ac51d8d
commit
e18ecbed6a
|
@ -179,12 +179,31 @@ export async function init(): Promise<IDatabaseCollections> {
|
||||||
logging: false,
|
logging: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const connection = await createConnection(connectionOptions);
|
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"');
|
||||||
|
if (migrations.length === 0) {
|
||||||
|
mustReconnect = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await connection.runMigrations({
|
await connection.runMigrations({
|
||||||
transaction: 'none',
|
transaction: 'none',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (mustReconnect) {
|
||||||
|
console.log('is reconnecting');
|
||||||
|
await connection.close();
|
||||||
|
connection = await createConnection(connectionOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
collections.Credentials = getRepository(entities.CredentialsEntity);
|
collections.Credentials = getRepository(entities.CredentialsEntity);
|
||||||
collections.Execution = getRepository(entities.ExecutionEntity);
|
collections.Execution = getRepository(entities.ExecutionEntity);
|
||||||
collections.Workflow = getRepository(entities.WorkflowEntity);
|
collections.Workflow = getRepository(entities.WorkflowEntity);
|
||||||
|
|
Loading…
Reference in a new issue