import { MigrationInterface , QueryRunner } from "typeorm" ; export class createVotesTable1608048371519 implements MigrationInterface { name = 'createVotesTable1608048371519' ; public async up ( queryRunner ) { await queryRunner . query ( `CREATE TABLE "votes" ("id" SERIAL NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "value" integer NOT NULL, "username" character varying NOT NULL, "postId" integer, "commentId" integer, CONSTRAINT "PK_f3d9fd4a0af865152c3f59db8ff" PRIMARY KEY ("id"))` ) ; await queryRunner . query ( `ALTER TABLE "posts" DROP CONSTRAINT "FK_42377e3f89a203ca74d117e5961"` ) ; await queryRunner . query ( `ALTER TABLE "posts" ALTER COLUMN "username" SET NOT NULL` ) ; await queryRunner . query ( `COMMENT ON COLUMN "posts"."username" IS NULL` ) ; await queryRunner . query ( `ALTER TABLE "votes" ADD CONSTRAINT "FK_79326ff26ef790424d820d54a72" FOREIGN KEY ("username") REFERENCES "users"("username") ON DELETE NO ACTION ON UPDATE NO ACTION` ) ; await queryRunner . query ( `ALTER TABLE "votes" ADD CONSTRAINT "FK_b5b05adc89dda0614276a13a599" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE NO ACTION ON UPDATE NO ACTION` ) ; await queryRunner . query ( `ALTER TABLE "votes" ADD CONSTRAINT "FK_554879cbc33538bf15d6991f400" FOREIGN KEY ("commentId") REFERENCES "comments"("id") ON DELETE NO ACTION ON UPDATE NO ACTION` ) ; await queryRunner . query ( `ALTER TABLE "posts" ADD CONSTRAINT "FK_42377e3f89a203ca74d117e5961" FOREIGN KEY ("username") REFERENCES "users"("username") ON DELETE NO ACTION ON UPDATE NO ACTION` ) ; } public async down ( queryRunner ) { await queryRunner . query ( `ALTER TABLE "posts" DROP CONSTRAINT "FK_42377e3f89a203ca74d117e5961"` ) ; await queryRunner . query ( `ALTER TABLE "votes" DROP CONSTRAINT "FK_554879cbc33538bf15d6991f400"` ) ; await queryRunner . query ( `ALTER TABLE "votes" DROP CONSTRAINT "FK_b5b05adc89dda0614276a13a599"` ) ; await queryRunner . query ( `ALTER TABLE "votes" DROP CONSTRAINT "FK_79326ff26ef790424d820d54a72"` ) ; await queryRunner . query ( `COMMENT ON COLUMN "posts"."username" IS NULL` ) ; await queryRunner . query ( `ALTER TABLE "posts" ALTER COLUMN "username" DROP NOT NULL` ) ; await queryRunner . query ( `ALTER TABLE "posts" ADD CONSTRAINT "FK_42377e3f89a203ca74d117e5961" FOREIGN KEY ("username") REFERENCES "users"("username") ON DELETE NO ACTION ON UPDATE NO ACTION` ) ; await queryRunner . query ( `DROP TABLE "votes"` ) ; } }