From af378449421eed6876bcd527d813b22c754db014 Mon Sep 17 00:00:00 2001 From: Scoder12 <34356756+Scoder12@users.noreply.github.com> Date: Thu, 24 Feb 2022 19:43:37 -0800 Subject: [PATCH] Format --- api/src/migrations/1642980631163-initial.ts | 49 +++++++++++++-------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/api/src/migrations/1642980631163-initial.ts b/api/src/migrations/1642980631163-initial.ts index a3982fc..bc1d702 100644 --- a/api/src/migrations/1642980631163-initial.ts +++ b/api/src/migrations/1642980631163-initial.ts @@ -1,24 +1,35 @@ -import {MigrationInterface, QueryRunner} from "typeorm"; +import { MigrationInterface, QueryRunner } from "typeorm"; export class initial1642980631163 implements MigrationInterface { - name = 'initial1642980631163' + name = "initial1642980631163"; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE "user" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "githubId" integer NOT NULL, "name" varchar NOT NULL, CONSTRAINT "UQ_0d84cc6a830f0e4ebbfcd6381dd" UNIQUE ("githubId"), CONSTRAINT "UQ_065d4d8f3b5adb4a08841eae3c8" UNIQUE ("name"))`); - await queryRunner.query(`CREATE TABLE "event" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "start" numeric NOT NULL, "userId" integer)`); - await queryRunner.query(`CREATE TABLE "temporary_event" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "start" numeric NOT NULL, "userId" integer, CONSTRAINT "FK_01cd2b829e0263917bf570cb672" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`); - await queryRunner.query(`INSERT INTO "temporary_event"("id", "name", "start", "userId") SELECT "id", "name", "start", "userId" FROM "event"`); - await queryRunner.query(`DROP TABLE "event"`); - await queryRunner.query(`ALTER TABLE "temporary_event" RENAME TO "event"`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "event" RENAME TO "temporary_event"`); - await queryRunner.query(`CREATE TABLE "event" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "start" numeric NOT NULL, "userId" integer)`); - await queryRunner.query(`INSERT INTO "event"("id", "name", "start", "userId") SELECT "id", "name", "start", "userId" FROM "temporary_event"`); - await queryRunner.query(`DROP TABLE "temporary_event"`); - await queryRunner.query(`DROP TABLE "event"`); - await queryRunner.query(`DROP TABLE "user"`); - } + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE "user" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "githubId" integer NOT NULL, "name" varchar NOT NULL, CONSTRAINT "UQ_0d84cc6a830f0e4ebbfcd6381dd" UNIQUE ("githubId"), CONSTRAINT "UQ_065d4d8f3b5adb4a08841eae3c8" UNIQUE ("name"))` + ); + await queryRunner.query( + `CREATE TABLE "event" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "start" numeric NOT NULL, "userId" integer)` + ); + await queryRunner.query( + `CREATE TABLE "temporary_event" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "start" numeric NOT NULL, "userId" integer, CONSTRAINT "FK_01cd2b829e0263917bf570cb672" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)` + ); + await queryRunner.query( + `INSERT INTO "temporary_event"("id", "name", "start", "userId") SELECT "id", "name", "start", "userId" FROM "event"` + ); + await queryRunner.query(`DROP TABLE "event"`); + await queryRunner.query(`ALTER TABLE "temporary_event" RENAME TO "event"`); + } + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "event" RENAME TO "temporary_event"`); + await queryRunner.query( + `CREATE TABLE "event" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "start" numeric NOT NULL, "userId" integer)` + ); + await queryRunner.query( + `INSERT INTO "event"("id", "name", "start", "userId") SELECT "id", "name", "start", "userId" FROM "temporary_event"` + ); + await queryRunner.query(`DROP TABLE "temporary_event"`); + await queryRunner.query(`DROP TABLE "event"`); + await queryRunner.query(`DROP TABLE "user"`); + } }