dating/migrations/1695130227420-init-schema.ts

54 lines
1.8 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,
2023-09-19 16:38:07 +00:00
"createdAt" timestamp NOT NULL DEFAULT now(),
2023-09-19 13:37:42 +00:00
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,
2023-09-19 16:38:07 +00:00
CONSTRAINT "swipes_pk" PRIMARY KEY (id)
2023-09-19 13:37:42 +00:00
);
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,
2023-09-19 16:38:07 +00:00
"createdAt" timestamp NOT NULL DEFAULT now(),
2023-09-19 13:37:42 +00:00
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";
`);
}
}