dating/migrations/1695130227420-init-schema.ts

52 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-09-19 13:37:42 +00:00
import { MigrationInterface, QueryRunner } from 'typeorm';
export class InitSchema1695130227420 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE users (
id serial4 NOT NULL,
"name" varchar NOT NULL,
"password" varchar NOT NULL,
email varchar NOT NULL,
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 "PK_bb38af5831e2c084a78e3622ff6" 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,
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<void> {
await queryRunner.query(`
DROP TABLE users;
DROP TABLE swipes;
DROP TABLE pairs;
DROP TABLE "pair-members";
`);
}
}