Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerpogo committed Feb 25, 2022
1 parent 441d51e commit af37844
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions api/src/migrations/1642980631163-initial.ts
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"`);
}
}

0 comments on commit af37844

Please sign in to comment.