import { MigrationInterface, QueryRunner } from 'typeorm'; export class InitSchema1695130227420 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(` CREATE TABLE users ( id serial4 NOT NULL, "name" varchar NOT NULL, "password" varchar NOT NULL, email varchar NOT NULL, "createdAt" timestamp NOT NULL DEFAULT now(), CONSTRAINT "users_pk" PRIMARY KEY (id), CONSTRAINT "users_email_unique" UNIQUE (email) ); CREATE TABLE swipes ( id serial4 NOT NULL, liked bool NOT NULL, "createdAt" timestamp NOT NULL DEFAULT now(), "sourceUserId" int4 NULL, "targetUserId" int4 NULL, CONSTRAINT "swipes_pk" PRIMARY KEY (id) ); ALTER TABLE swipes ADD CONSTRAINT "swipes_target_user_fk" FOREIGN KEY ("targetUserId") REFERENCES users(id); ALTER TABLE swipes ADD CONSTRAINT "swipes_source_user_fk" FOREIGN KEY ("sourceUserId") REFERENCES users(id); CREATE TABLE pairs ( id serial4 NOT NULL, "createdAt" timestamp NOT NULL DEFAULT now(), CONSTRAINT "pairs_pk" PRIMARY KEY (id) ); CREATE TABLE "pair-members" ( "pairId" int4 NOT NULL, "userId" int4 NOT NULL, CONSTRAINT "pair_members_pk" PRIMARY KEY ("pairId", "userId") ); ALTER TABLE "pair-members" ADD CONSTRAINT "pair_members_user_fk" FOREIGN KEY ("userId") REFERENCES users(id); ALTER TABLE "pair-members" ADD CONSTRAINT "pair_members_pair_fk" FOREIGN KEY ("pairId") REFERENCES pairs(id); `); } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(` DROP TABLE users; DROP TABLE swipes; DROP TABLE pairs; DROP TABLE "pair-members"; `); } }