diff --git a/packages/cli/src/Db.ts b/packages/cli/src/Db.ts index b8f43e6704..089119e737 100644 --- a/packages/cli/src/Db.ts +++ b/packages/cli/src/Db.ts @@ -1,7 +1,7 @@ import { + DatabaseType, GenericHelpers, IDatabaseCollections, - DatabaseType, } from './'; import { @@ -12,14 +12,13 @@ import { ConnectionOptions, createConnection, getRepository, - Connection, } from 'typeorm'; import { MongoDb, + MySQLDb, PostgresDb, SQLite, - MySQLDb, } from './databases'; export let collections: IDatabaseCollections = { @@ -48,9 +47,7 @@ export async function init(): Promise { let entities; let connectionOptions: ConnectionOptions; - let connection; - let dbNotExistError: string | undefined; switch (dbType) { case 'mongodb': entities = MongoDb; @@ -63,7 +60,6 @@ export async function init(): Promise { break; case 'postgresdb': - dbNotExistError = 'does not exist'; entities = PostgresDb; connectionOptions = { type: 'postgres', @@ -81,7 +77,6 @@ export async function init(): Promise { case 'mariadb': case 'mysqldb': - dbNotExistError = 'does not exist'; entities = MySQLDb; connectionOptions = { type: dbType === 'mysqldb' ? 'mysql' : 'mariadb', @@ -97,14 +92,13 @@ export async function init(): Promise { break; case 'sqlite': - dbNotExistError = 'no such table:'; entities = SQLite; connectionOptions = { type: 'sqlite', database: path.join(n8nFolder, 'database.sqlite'), entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string, - migrations: [InitialMigration1588102412422], - migrationsRun: true + migrations: [InitialMigration1588102412422], + migrationsRun: true, }; break; @@ -115,29 +109,18 @@ export async function init(): Promise { Object.assign(connectionOptions, { entities: Object.values(entities), synchronize: false, - logging: true + logging: false, }); - try { - connection = await createConnection(connectionOptions); + const connection = await createConnection(connectionOptions); - await connection.runMigrations({ - transaction: 'none' - }); + await connection.runMigrations({ + transaction: 'none', + }); - - if(connection.isConnected){ - collections.Credentials = getRepository(entities.CredentialsEntity); - collections.Execution = getRepository(entities.ExecutionEntity); - collections.Workflow = getRepository(entities.WorkflowEntity); - } else { - init(); - } - - } catch (e){ - console.log(e); - } + collections.Credentials = getRepository(entities.CredentialsEntity); + collections.Execution = getRepository(entities.ExecutionEntity); + collections.Workflow = getRepository(entities.WorkflowEntity); return collections; - -}; +} diff --git a/packages/cli/src/databases/mongodb/Migrations/1587563438936-InitialMigration.ts b/packages/cli/src/databases/mongodb/Migrations/1587563438936-InitialMigration.ts index f26191c69a..df2785c350 100644 --- a/packages/cli/src/databases/mongodb/Migrations/1587563438936-InitialMigration.ts +++ b/packages/cli/src/databases/mongodb/Migrations/1587563438936-InitialMigration.ts @@ -1,11 +1,11 @@ -import {MigrationInterface, QueryRunner} from "typeorm"; +import { MigrationInterface, QueryRunner } from 'typeorm'; export class InitialMigration1587563438936 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - } + async up(queryRunner: QueryRunner): Promise { + } - public async down(queryRunner: QueryRunner): Promise { - } + async down(queryRunner: QueryRunner): Promise { + } } diff --git a/packages/cli/src/databases/mongodb/Migrations/index.ts b/packages/cli/src/databases/mongodb/Migrations/index.ts new file mode 100644 index 0000000000..a60bdc7cf8 --- /dev/null +++ b/packages/cli/src/databases/mongodb/Migrations/index.ts @@ -0,0 +1 @@ +export * from './1587563438936-InitialMigration'; diff --git a/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts b/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts index f6aba32791..a156dd949e 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts @@ -1,20 +1,20 @@ -import {MigrationInterface, QueryRunner} from "typeorm"; +import { MigrationInterface, QueryRunner } from 'typeorm'; export class InitialMigration1588157391238 implements MigrationInterface { - name = 'InitialMigration1588157391238' + name = 'InitialMigration1588157391238'; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query("CREATE TABLE IF NOT EXISTS `credentials_entity` (`id` int NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL, `data` text NOT NULL, `type` varchar(32) NOT NULL, `nodesAccess` json NOT NULL, `createdAt` datetime NOT NULL, `updatedAt` datetime NOT NULL, INDEX `IDX_07fde106c0b471d8cc80a64fc8` (`type`), PRIMARY KEY (`id`)) ENGINE=InnoDB", undefined); - await queryRunner.query("CREATE TABLE IF NOT EXISTS `execution_entity` (`id` int NOT NULL AUTO_INCREMENT, `data` text NOT NULL, `finished` tinyint NOT NULL, `mode` varchar(255) NOT NULL, `retryOf` varchar(255) NULL, `retrySuccessId` varchar(255) NULL, `startedAt` datetime NOT NULL, `stoppedAt` datetime NOT NULL, `workflowData` json NOT NULL, `workflowId` varchar(255) NULL, INDEX `IDX_c4d999a5e90784e8caccf5589d` (`workflowId`), PRIMARY KEY (`id`)) ENGINE=InnoDB", undefined); - await queryRunner.query("CREATE TABLE IF NOT EXISTS`workflow_entity` (`id` int NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL, `active` tinyint NOT NULL, `nodes` json NOT NULL, `connections` json NOT NULL, `createdAt` datetime NOT NULL, `updatedAt` datetime NOT NULL, `settings` json NULL, `staticData` json NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB", undefined); - } + async up(queryRunner: QueryRunner): Promise { + await queryRunner.query('CREATE TABLE IF NOT EXISTS `credentials_entity` (`id` int NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL, `data` text NOT NULL, `type` varchar(32) NOT NULL, `nodesAccess` json NOT NULL, `createdAt` datetime NOT NULL, `updatedAt` datetime NOT NULL, INDEX `IDX_07fde106c0b471d8cc80a64fc8` (`type`), PRIMARY KEY (`id`)) ENGINE=InnoDB', undefined); + await queryRunner.query('CREATE TABLE IF NOT EXISTS `execution_entity` (`id` int NOT NULL AUTO_INCREMENT, `data` text NOT NULL, `finished` tinyint NOT NULL, `mode` varchar(255) NOT NULL, `retryOf` varchar(255) NULL, `retrySuccessId` varchar(255) NULL, `startedAt` datetime NOT NULL, `stoppedAt` datetime NOT NULL, `workflowData` json NOT NULL, `workflowId` varchar(255) NULL, INDEX `IDX_c4d999a5e90784e8caccf5589d` (`workflowId`), PRIMARY KEY (`id`)) ENGINE=InnoDB', undefined); + await queryRunner.query('CREATE TABLE IF NOT EXISTS`workflow_entity` (`id` int NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL, `active` tinyint NOT NULL, `nodes` json NOT NULL, `connections` json NOT NULL, `createdAt` datetime NOT NULL, `updatedAt` datetime NOT NULL, `settings` json NULL, `staticData` json NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB', undefined); + } - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query("DROP TABLE `workflow_entity`", undefined); - await queryRunner.query("DROP INDEX `IDX_c4d999a5e90784e8caccf5589d` ON `execution_entity`", undefined); - await queryRunner.query("DROP TABLE `execution_entity`", undefined); - await queryRunner.query("DROP INDEX `IDX_07fde106c0b471d8cc80a64fc8` ON `credentials_entity`", undefined); - await queryRunner.query("DROP TABLE `credentials_entity`", undefined); - } + async down(queryRunner: QueryRunner): Promise { + await queryRunner.query('DROP TABLE `workflow_entity`', undefined); + await queryRunner.query('DROP INDEX `IDX_c4d999a5e90784e8caccf5589d` ON `execution_entity`', undefined); + await queryRunner.query('DROP TABLE `execution_entity`', undefined); + await queryRunner.query('DROP INDEX `IDX_07fde106c0b471d8cc80a64fc8` ON `credentials_entity`', undefined); + await queryRunner.query('DROP TABLE `credentials_entity`', undefined); + } } diff --git a/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts b/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts index b26470c797..fe050c9c3d 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts @@ -1,22 +1,22 @@ -import {MigrationInterface, QueryRunner} from "typeorm"; +import { MigrationInterface, QueryRunner } from "typeorm"; export class InitialMigration1587669153312 implements MigrationInterface { - name = 'InitialMigration1587669153312' + name = 'InitialMigration1587669153312'; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS IDX_07fde106c0b471d8cc80a64fc8 ON credentials_entity (type) `, undefined); - await queryRunner.query(`CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS IDX_c4d999a5e90784e8caccf5589d ON execution_entity ("workflowId") `, undefined); - await queryRunner.query(`CREATE TABLE IF NOT EXISTS 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); - } + async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS IDX_07fde106c0b471d8cc80a64fc8 ON credentials_entity (type) `, undefined); + await queryRunner.query(`CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS IDX_c4d999a5e90784e8caccf5589d ON execution_entity ("workflowId") `, undefined); + await queryRunner.query(`CREATE TABLE IF NOT EXISTS 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 { - await queryRunner.query(`DROP TABLE workflow_entity`, undefined); - await queryRunner.query(`DROP INDEX IDX_c4d999a5e90784e8caccf5589d`, undefined); - await queryRunner.query(`DROP TABLE execution_entity`, undefined); - await queryRunner.query(`DROP INDEX IDX_07fde106c0b471d8cc80a64fc8`, undefined); - await queryRunner.query(`DROP TABLE credentials_entity`, undefined); - } + async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE workflow_entity`, undefined); + await queryRunner.query(`DROP INDEX IDX_c4d999a5e90784e8caccf5589d`, undefined); + await queryRunner.query(`DROP TABLE execution_entity`, undefined); + await queryRunner.query(`DROP INDEX IDX_07fde106c0b471d8cc80a64fc8`, undefined); + await queryRunner.query(`DROP TABLE credentials_entity`, undefined); + } } diff --git a/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts b/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts index a68c3f5744..038c24edaa 100644 --- a/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts +++ b/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts @@ -1,22 +1,22 @@ -import {MigrationInterface, QueryRunner} from "typeorm"; +import { MigrationInterface, QueryRunner } from "typeorm"; export class InitialMigration1588102412422 implements MigrationInterface { - name = 'InitialMigration1588102412422' + name = 'InitialMigration1588102412422'; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE IF NOT EXISTS "credentials_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(128) NOT NULL, "data" text NOT NULL, "type" varchar(32) NOT NULL, "nodesAccess" text NOT NULL, "createdAt" datetime NOT NULL, "updatedAt" datetime NOT NULL)`, undefined); - await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_07fde106c0b471d8cc80a64fc8" ON "credentials_entity" ("type") `, undefined); - await queryRunner.query(`CREATE TABLE IF NOT EXISTS "execution_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "data" text NOT NULL, "finished" boolean NOT NULL, "mode" varchar NOT NULL, "retryOf" varchar, "retrySuccessId" varchar, "startedAt" datetime NOT NULL, "stoppedAt" datetime NOT NULL, "workflowData" text NOT NULL, "workflowId" varchar)`, undefined); - await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_c4d999a5e90784e8caccf5589d" ON "execution_entity" ("workflowId") `, undefined); - await queryRunner.query(`CREATE TABLE IF NOT EXISTS "workflow_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(128) NOT NULL, "active" boolean NOT NULL, "nodes" text NOT NULL, "connections" text NOT NULL, "createdAt" datetime NOT NULL, "updatedAt" datetime NOT NULL, "settings" text, "staticData" text)`, undefined); - } + async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE IF NOT EXISTS "credentials_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(128) NOT NULL, "data" text NOT NULL, "type" varchar(32) NOT NULL, "nodesAccess" text NOT NULL, "createdAt" datetime NOT NULL, "updatedAt" datetime NOT NULL)`, undefined); + await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_07fde106c0b471d8cc80a64fc8" ON "credentials_entity" ("type") `, undefined); + await queryRunner.query(`CREATE TABLE IF NOT EXISTS "execution_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "data" text NOT NULL, "finished" boolean NOT NULL, "mode" varchar NOT NULL, "retryOf" varchar, "retrySuccessId" varchar, "startedAt" datetime NOT NULL, "stoppedAt" datetime NOT NULL, "workflowData" text NOT NULL, "workflowId" varchar)`, undefined); + await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_c4d999a5e90784e8caccf5589d" ON "execution_entity" ("workflowId") `, undefined); + await queryRunner.query(`CREATE TABLE IF NOT EXISTS "workflow_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(128) NOT NULL, "active" boolean NOT NULL, "nodes" text NOT NULL, "connections" text NOT NULL, "createdAt" datetime NOT NULL, "updatedAt" datetime NOT NULL, "settings" text, "staticData" text)`, undefined); + } - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE "workflow_entity"`, undefined); - await queryRunner.query(`DROP INDEX "IDX_c4d999a5e90784e8caccf5589d"`, undefined); - await queryRunner.query(`DROP TABLE "execution_entity"`, undefined); - await queryRunner.query(`DROP INDEX "IDX_07fde106c0b471d8cc80a64fc8"`, undefined); - await queryRunner.query(`DROP TABLE "credentials_entity"`, undefined); - } + async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "workflow_entity"`, undefined); + await queryRunner.query(`DROP INDEX "IDX_c4d999a5e90784e8caccf5589d"`, undefined); + await queryRunner.query(`DROP TABLE "execution_entity"`, undefined); + await queryRunner.query(`DROP INDEX "IDX_07fde106c0b471d8cc80a64fc8"`, undefined); + await queryRunner.query(`DROP TABLE "credentials_entity"`, undefined); + } }