Skip to content

Commit

Permalink
Create migrations for other db systems
Browse files Browse the repository at this point in the history
  • Loading branch information
krynble committed May 11, 2022
1 parent 8a60879 commit 8867489
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import * as config from '../../../../config';

export class CommunityNodes1652254514003 implements MigrationInterface {
name = 'CommunityNodes1652254514003';

public async up(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.getEnv('database.tablePrefix');

await queryRunner.query(
`CREATE TABLE \`${tablePrefix}installed_packages\` (` +
'`packageName` char(214) NOT NULL,' +
'`installedVersion` char(50) NOT NULL,' +
'`createdAt` datetime NULL DEFAULT CURRENT_TIMESTAMP,' +
'`updatedAt` datetime NULL DEFAULT CURRENT_TIMESTAMP,' +
'PRIMARY KEY (\`packageName\`)' +
') ENGINE=InnoDB;'
);

await queryRunner.query(

`CREATE TABLE \`${tablePrefix}installed_nodes\` (` +
'`name` char(200) NOT NULL,' +
'`type` char(200) NOT NULL,' +
"`latestVersion` int NOT NULL DEFAULT '1'," +
'`package` char(214) NOT NULL,' +
'PRIMARY KEY (`name`),' +
`INDEX \`FK_${tablePrefix}73f857fc5dce682cef8a99c11dbddbc969618951\` (\`package\` ASC)` +
") ENGINE='InnoDB';"
);

await queryRunner.query(
`ALTER TABLE \`${tablePrefix}installed_nodes\` ADD CONSTRAINT \`FK_${tablePrefix}73f857fc5dce682cef8a99c11dbddbc969618951\` FOREIGN KEY (\`package\`) REFERENCES \`${tablePrefix}installed_packages\`(\`packageName\`) ON DELETE CASCADE ON UPDATE CASCADE`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.getEnv('database.tablePrefix');

await queryRunner.query(
`ALTER TABLE ${tablePrefix}workflow_entity ADD UNIQUE INDEX \`IDX_${tablePrefix}943d8f922be094eb507cb9a7f9\` (\`name\`)`,
);

await queryRunner.query(`DROP TABLE "${tablePrefix}installed_nodes"`);
await queryRunner.query(`DROP TABLE "${tablePrefix}installed_packages"`);
}
}
2 changes: 2 additions & 0 deletions packages/cli/src/databases/mysqldb/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { UpdateWorkflowCredentials1630451444017 } from './1630451444017-UpdateWo
import { AddExecutionEntityIndexes1644424784709 } from './1644424784709-AddExecutionEntityIndexes';
import { CreateUserManagement1646992772331 } from './1646992772331-CreateUserManagement';
import { LowerCaseUserEmail1648740597343 } from './1648740597343-LowerCaseUserEmail';
import { CommunityNodes1652254514003 } from './1652254514003-CommunityNodes.ts';

export const mysqlMigrations = [
InitialMigration1588157391238,
Expand All @@ -30,4 +31,5 @@ export const mysqlMigrations = [
AddExecutionEntityIndexes1644424784709,
CreateUserManagement1646992772331,
LowerCaseUserEmail1648740597343,
CommunityNodes1652254514003,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import config = require('../../../../config');
import {
logMigrationEnd,
logMigrationStart,
} from '../../utils/migrationHelpers';

export class CommunityNodes1652254514002 implements MigrationInterface {
name = 'CommunityNodes1652254514002';

public async up(queryRunner: QueryRunner): Promise<void> {
logMigrationStart(this.name);

let tablePrefix = config.getEnv('database.tablePrefix');
const schema = config.getEnv('database.postgresdb.schema');
if (schema) {
tablePrefix = schema + '.' + tablePrefix;
}

await queryRunner.query(
`CREATE TABLE ${tablePrefix}installed_packages (` +
'"packageName" character(214) NOT NULL,' +
'"installedVersion" character(50) NOT NULL,' +
'"createdAt" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,' +
'"updatedAt" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,' +
`CONSTRAINT "PK_${tablePrefix}08cc9197c39b028c1e9beca225940576fd1a5804" PRIMARY KEY ("packageName")` +
');',
);

await queryRunner.query(

`CREATE TABLE ${tablePrefix}installed_nodes (` +
'"name" character(200) NOT NULL, ' +
'"type" character(200) NOT NULL, ' +
'"latestVersion" integer NOT NULL DEFAULT 1, ' +
'"package" character(241) NOT NULL, ' +
`CONSTRAINT "PK_${tablePrefix}8ebd28194e4f792f96b5933423fc439df97d9689" PRIMARY KEY ("name"), ` +
`CONSTRAINT "FK_${tablePrefix}73f857fc5dce682cef8a99c11dbddbc969618951" FOREIGN KEY ("package") REFERENCES ${tablePrefix}installed_packages ("packageName")` +
');'
);
logMigrationEnd(this.name);
}

public async down(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.get('database.tablePrefix');
await queryRunner.query(`DROP TABLE "${tablePrefix}installed_nodes"`);
await queryRunner.query(`DROP TABLE "${tablePrefix}installed_packages"`);
}
}
2 changes: 2 additions & 0 deletions packages/cli/src/databases/postgresdb/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AddExecutionEntityIndexes1644422880309 } from './1644422880309-AddExecu
import { IncreaseTypeVarcharLimit1646834195327 } from './1646834195327-IncreaseTypeVarcharLimit';
import { CreateUserManagement1646992772331 } from './1646992772331-CreateUserManagement';
import { LowerCaseUserEmail1648740597343 } from './1648740597343-LowerCaseUserEmail';
import { CommunityNodes1652254514002 } from './1652254514002-CommunityNodes';

export const postgresMigrations = [
InitialMigration1587669153312,
Expand All @@ -26,4 +27,5 @@ export const postgresMigrations = [
IncreaseTypeVarcharLimit1646834195327,
CreateUserManagement1646992772331,
LowerCaseUserEmail1648740597343,
CommunityNodes1652254514002,
];
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { v4 as uuid } from 'uuid';
import config = require('../../../../config');
import {
loadSurveyFromDisk,
logMigrationEnd,
logMigrationStart,
} from '../../utils/migrationHelpers';

export class CommunityNodes1648135167001 implements MigrationInterface {
name = 'CommunityNodes1648135167001';
export class CommunityNodes1652254514001 implements MigrationInterface {
name = 'CommunityNodes1652254514001';

public async up(queryRunner: QueryRunner): Promise<void> {
logMigrationStart(this.name);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/databases/sqlite/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { UpdateWorkflowCredentials1630330987096 } from './1630330987096-UpdateWo
import { AddExecutionEntityIndexes1644421939510 } from './1644421939510-AddExecutionEntityIndexes';
import { CreateUserManagement1646992772331 } from './1646992772331-CreateUserManagement';
import { LowerCaseUserEmail1648740597343 } from './1648740597343-LowerCaseUserEmail';
import { CommunityNodes1648135167001 } from './1648135167001-CommunityNodes'
import { CommunityNodes1652254514001 } from './1652254514001-CommunityNodes'

const sqliteMigrations = [
InitialMigration1588102412422,
Expand All @@ -27,7 +27,7 @@ const sqliteMigrations = [
AddExecutionEntityIndexes1644421939510,
CreateUserManagement1646992772331,
LowerCaseUserEmail1648740597343,
CommunityNodes1648135167001,
CommunityNodes1652254514001,
];

export { sqliteMigrations };

0 comments on commit 8867489

Please sign in to comment.