mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
postgresql initial migration
This commit is contained in:
parent
daeafe68f3
commit
032f4075e4
|
@ -115,11 +115,7 @@ export class Start extends Command {
|
||||||
await credentialTypes.init(loadNodesAndCredentials.credentialTypes);
|
await credentialTypes.init(loadNodesAndCredentials.credentialTypes);
|
||||||
|
|
||||||
// Wait till the database is ready
|
// Wait till the database is ready
|
||||||
let dbReady = await startDbInitPromise;
|
await startDbInitPromise;
|
||||||
|
|
||||||
if(!dbReady){
|
|
||||||
throw new Error("DB did not initialize.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags.tunnel === true) {
|
if (flags.tunnel === true) {
|
||||||
this.log('\nWaiting for tunnel ...');
|
this.log('\nWaiting for tunnel ...');
|
||||||
|
|
|
@ -28,9 +28,11 @@ export let collections: IDatabaseCollections = {
|
||||||
Workflow: null,
|
Workflow: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
import InitialMigration1587669153312 from './databases/postgresdb/migrations/1587669153312-InitialMigration'
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export async function init(synchronize?: boolean): Promise<boolean> {
|
export async function init(synchronize?: boolean): Promise<IDatabaseCollections> {
|
||||||
const dbType = await GenericHelpers.getConfigValue('database.type') as DatabaseType;
|
const dbType = await GenericHelpers.getConfigValue('database.type') as DatabaseType;
|
||||||
const n8nFolder = UserSettings.getUserN8nFolderPath();
|
const n8nFolder = UserSettings.getUserN8nFolderPath();
|
||||||
|
|
||||||
|
@ -63,7 +65,7 @@ export async function init(synchronize?: boolean): Promise<boolean> {
|
||||||
port: await GenericHelpers.getConfigValue('database.postgresdb.port') as number,
|
port: await GenericHelpers.getConfigValue('database.postgresdb.port') as number,
|
||||||
username: await GenericHelpers.getConfigValue('database.postgresdb.user') as string,
|
username: await GenericHelpers.getConfigValue('database.postgresdb.user') as string,
|
||||||
schema: await GenericHelpers.getConfigValue('database.postgresdb.schema') as string,
|
schema: await GenericHelpers.getConfigValue('database.postgresdb.schema') as string,
|
||||||
migrations: ['./databases/postgresdb/migrations/*.js']
|
migrations: [InitialMigration1587669153312]
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -105,21 +107,45 @@ export async function init(synchronize?: boolean): Promise<boolean> {
|
||||||
migrationsRun: true
|
migrationsRun: true
|
||||||
});
|
});
|
||||||
|
|
||||||
for(let i = 0; i < 1000; i++){
|
|
||||||
console.log(connectionOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
connection = await createConnection(connectionOptions);
|
connection = await createConnection(connectionOptions);
|
||||||
|
|
||||||
await connection.runMigrations({
|
let migrations = await connection.runMigrations({
|
||||||
transaction: "none"
|
transaction: 'none'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(migrations);
|
||||||
|
|
||||||
}catch(e){
|
}catch(e){
|
||||||
throw new Error("Couldn't connect to db / migrate stuff.")
|
console.log(`Error: ${e}`);
|
||||||
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Fix that properly
|
||||||
|
// @ts-ignore
|
||||||
|
collections.Credentials = getRepository(entities.CredentialsEntity);
|
||||||
|
// @ts-ignore
|
||||||
|
collections.Execution = getRepository(entities.ExecutionEntity);
|
||||||
|
// @ts-ignore
|
||||||
|
collections.Workflow = getRepository(entities.WorkflowEntity);
|
||||||
|
|
||||||
|
// Make sure that database did already get initialized
|
||||||
|
try {
|
||||||
|
// Try a simple query, if it fails it is normally a sign that
|
||||||
|
// database did not get initialized
|
||||||
|
await collections.Execution!.findOne({ id: 1 });
|
||||||
|
} catch (error) {
|
||||||
|
// If query errors and the problem is that the database does not exist
|
||||||
|
// run the init again with "synchronize: true"
|
||||||
|
if (dbNotExistError !== undefined && error.message.includes(dbNotExistError)) {
|
||||||
|
// Disconnect before we try to connect again
|
||||||
|
if (connection.isConnected) {
|
||||||
|
await connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
return connection.isConnected;
|
return init(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return collections;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
import {MigrationInterface, QueryRunner} from "typeorm";
|
|
||||||
|
|
||||||
export class InitialMigration1587563465704 implements MigrationInterface {
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +1,14 @@
|
||||||
import {MigrationInterface, QueryRunner} from "typeorm";
|
import {MigrationInterface, QueryRunner} from "typeorm";
|
||||||
|
|
||||||
export class InitialMigration1587669153312 implements MigrationInterface {
|
export default class InitialMigration1587669153312 implements MigrationInterface {
|
||||||
name = 'InitialMigration1587669153312'
|
name = 'InitialMigration1587669153312'
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
await queryRunner.query(`CREATE TABLE credentials_entity (id SERIAL NOT NULL, name character varying(128) NOT NULL, data text NOT NULL, type character varying(32) NOT NULL, nodesAccess json NOT NULL, createdAt TIMESTAMP NOT NULL, updatedAt TIMESTAMP NOT NULL, CONSTRAINT PK_814c3d3c36e8a27fa8edb761b0e PRIMARY KEY (id))`, undefined);
|
await queryRunner.query(`CREATE TABLE credentials_entity (id SERIAL NOT NULL, "name" character varying(128) NOT NULL, "data" text NOT NULL, "type" character varying(32) NOT NULL, "nodesAccess" json NOT NULL, "createdAt" TIMESTAMP NOT NULL, "updatedAt" TIMESTAMP NOT NULL, CONSTRAINT PK_814c3d3c36e8a27fa8edb761b0e PRIMARY KEY (id))`, undefined);
|
||||||
await queryRunner.query(`CREATE INDEX IDX_07fde106c0b471d8cc80a64fc8 ON credentials_entity (type) `, undefined);
|
await queryRunner.query(`CREATE INDEX IDX_07fde106c0b471d8cc80a64fc8 ON credentials_entity (type) `, undefined);
|
||||||
await queryRunner.query(`CREATE TABLE execution_entity (id SERIAL NOT NULL, data text NOT NULL, finished boolean NOT NULL, mode character varying NOT NULL, retryOf character varying, retrySuccessId character varying, startedAt TIMESTAMP NOT NULL, stoppedAt TIMESTAMP NOT NULL, workflowData json NOT NULL, workflowId character varying, CONSTRAINT PK_e3e63bbf986767844bbe1166d4e PRIMARY KEY (id))`, undefined);
|
await queryRunner.query(`CREATE TABLE execution_entity (id SERIAL NOT NULL, "data" text NOT NULL, "finished" boolean NOT NULL, "mode" character varying NOT NULL, "retryOf" character varying, "retrySuccessId" character varying, "startedAt" TIMESTAMP NOT NULL, "stoppedAt" TIMESTAMP NOT NULL, "workflowData" json NOT NULL, "workflowId" character varying, CONSTRAINT PK_e3e63bbf986767844bbe1166d4e PRIMARY KEY (id))`, undefined);
|
||||||
await queryRunner.query(`CREATE INDEX IDX_c4d999a5e90784e8caccf5589d ON execution_entity (workflowId) `, undefined);
|
await queryRunner.query(`CREATE INDEX IDX_c4d999a5e90784e8caccf5589d ON execution_entity ("workflowId") `, undefined);
|
||||||
await queryRunner.query(`CREATE TABLE workflow_entity (id SERIAL NOT NULL, name character varying(128) NOT NULL, active boolean NOT NULL, nodes json NOT NULL, connections json NOT NULL, createdAt TIMESTAMP NOT NULL, updatedAt TIMESTAMP NOT NULL, settings json, staticData json, CONSTRAINT PK_eded7d72664448da7745d551207 PRIMARY KEY (id))`, undefined);
|
await queryRunner.query(`CREATE TABLE workflow_entity (id SERIAL NOT NULL, "name" character varying(128) NOT NULL, "active" boolean NOT NULL, "nodes" json NOT NULL, "connections" json NOT NULL, "createdAt" TIMESTAMP NOT NULL, "updatedAt" TIMESTAMP NOT NULL, "settings" json, "staticData" json, CONSTRAINT PK_eded7d72664448da7745d551207 PRIMARY KEY (id))`, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
|
Loading…
Reference in a new issue