mam-kupi-api/migrations/1693809572293-init-schema.ts

48 lines
1.4 KiB
TypeScript

import { MigrationInterface, QueryRunner } from 'typeorm';
export class InitSchema1693809572293 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TYPE public."Users_roles_enum" AS ENUM ('admin','standard');
CREATE TABLE public."Users" (
id serial4 primary key,
"name" varchar NOT NULL,
"password" varchar NOT NULL,
email varchar NOT NULL UNIQUE,
"role" public."Users_roles_enum" NOT NULL DEFAULT 'standard'::"Users_roles_enum"
);
CREATE TABLE public."Links" (
id serial4 PRIMARY KEY,
url varchar NOT NULL,
"lastCheckDate" timestamp NULL,
"userId" int4 NOT NULL
);
ALTER TABLE public."Links" ADD CONSTRAINT "links_user" FOREIGN KEY ("userId") REFERENCES public."Users"(id);
CREATE TABLE public."Prices" (
id serial4 PRIMARY KEY,
value int4 NOT NULL,
"createdDate" timestamp NOT NULL DEFAULT now(),
"linkId" int4 NOT NULL
);
ALTER TABLE public."Prices" ADD CONSTRAINT "prices_link" FOREIGN KEY ("linkId") REFERENCES public."Links"(id);
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP TYPE public."Users_roles_enum";
DROP TABLE public."Users";
DROP TABLE public."Links";
DROP TABLE public."Prices";
`);
}
}