-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
441d51e
commit af37844
Showing
1 changed file
with
30 additions
and
19 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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<void> { | ||
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<void> { | ||
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<void> { | ||
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<void> { | ||
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"`); | ||
} | ||
} |