From 864758f296a6ca35620e883027d7fd4339ffa930 Mon Sep 17 00:00:00 2001 From: rubikscraft Date: Sun, 4 Sep 2022 20:04:20 +0200 Subject: [PATCH] create db migration --- backend/package.json | 2 +- .../migrations/1662314197741-V_0_4_0_a.ts | 20 +++++++++++++++++++ backend/src/database/migrations/index.ts | 2 ++ backend/src/main.ts | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 backend/src/database/migrations/1662314197741-V_0_4_0_a.ts diff --git a/backend/package.json b/backend/package.json index ca2f3a4..b0a8159 100644 --- a/backend/package.json +++ b/backend/package.json @@ -15,7 +15,7 @@ "start:debug": "nest start --debug --watch --exec \"node --es-module-specifier-resolution=node\"", "start:prod": "node --es-module-specifier-resolution=node dist/main", "typeorm": "typeorm-ts-node-esm", - "migrate": "yarn typeorm migration:generate -d ./src/datasource.ts", + "migrate": "PICSUR_PRODUCTION=\"true\" yarn typeorm migration:generate -d ./src/datasource.ts", "format": "prettier --write \"src/**/*.ts\"", "clean": "rimraf dist", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", diff --git a/backend/src/database/migrations/1662314197741-V_0_4_0_a.ts b/backend/src/database/migrations/1662314197741-V_0_4_0_a.ts new file mode 100644 index 0000000..58c0a86 --- /dev/null +++ b/backend/src/database/migrations/1662314197741-V_0_4_0_a.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class V040A1662314197741 implements MigrationInterface { + name = 'V040A1662314197741' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "e_api_key_backend" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "key" character varying NOT NULL, "name" character varying NOT NULL, "created" TIMESTAMP NOT NULL, "last_used" TIMESTAMP, "userId" uuid NOT NULL, CONSTRAINT "UQ_a244964afdff398bab8a45017c8" UNIQUE ("key"), CONSTRAINT "PK_e31f7dfe2db917a6ed1024f4e8b" PRIMARY KEY ("id"))`); + await queryRunner.query(`CREATE INDEX "IDX_a244964afdff398bab8a45017c" ON "e_api_key_backend" ("key") `); + await queryRunner.query(`ALTER TABLE "e_image_backend" ADD "delete_key" character varying`); + await queryRunner.query(`ALTER TABLE "e_api_key_backend" ADD CONSTRAINT "FK_3a32374df29b25152a84f0d1025" FOREIGN KEY ("userId") REFERENCES "e_user_backend"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "e_api_key_backend" DROP CONSTRAINT "FK_3a32374df29b25152a84f0d1025"`); + await queryRunner.query(`ALTER TABLE "e_image_backend" DROP COLUMN "delete_key"`); + await queryRunner.query(`DROP INDEX "public"."IDX_a244964afdff398bab8a45017c"`); + await queryRunner.query(`DROP TABLE "e_api_key_backend"`); + } + +} diff --git a/backend/src/database/migrations/index.ts b/backend/src/database/migrations/index.ts index e36e71d..53dd346 100644 --- a/backend/src/database/migrations/index.ts +++ b/backend/src/database/migrations/index.ts @@ -1,7 +1,9 @@ import { V030A1661692206479 } from './1661692206479-V_0_3_0_a'; import { V032A1662029904716 } from './1662029904716-V_0_3_2_a'; +import { V040A1662314197741 } from './1662314197741-V_0_4_0_a'; export const MigrationList: Function[] = [ V030A1661692206479, V032A1662029904716, + V040A1662314197741, ]; diff --git a/backend/src/main.ts b/backend/src/main.ts index bd5f33c..e51bc24 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -27,7 +27,7 @@ async function bootstrap() { AppModule, fastifyAdapter, { - bufferLogs: false, + bufferLogs: true, }, );