-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create migrations for other db systems
- Loading branch information
Showing
6 changed files
with
104 additions
and
6 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/cli/src/databases/mysqldb/migrations/1652254514003-CommunityNodes.ts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/cli/src/databases/postgresdb/migrations/1652254514002-CommunityNodes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
...igrations/1648135167001-CommunityNodes.ts → ...igrations/1652254514001-CommunityNodes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters