add news migrations
This commit is contained in:
File diff suppressed because it is too large
Load Diff
59
src/database/migrations/Migration20251201115952.ts
Normal file
59
src/database/migrations/Migration20251201115952.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Migration } from "@mikro-orm/migrations";
|
||||
|
||||
export class Migration20251201115952 extends Migration {
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(
|
||||
`create table "article" ("id" varchar(30) not null, "thumbnail" varchar(100) not null, "slug" varchar(100) not null, "title" varchar(100) not null, "content" text not null, "views" int not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "article_pkey" primary key ("id"));`,
|
||||
);
|
||||
this.addSql(
|
||||
`alter table "article" add constraint "article_slug_unique" unique ("slug");`,
|
||||
);
|
||||
|
||||
this.addSql(
|
||||
`create table "tag" ("id" varchar(30) not null, "slug" varchar(100) not null, "name" varchar(100) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "tag_pkey" primary key ("id"));`,
|
||||
);
|
||||
this.addSql(
|
||||
`alter table "tag" add constraint "tag_slug_unique" unique ("slug");`,
|
||||
);
|
||||
|
||||
this.addSql(
|
||||
`create table "article_tags" ("article_id" varchar(30) not null, "tag_id" varchar(30) not null, constraint "article_tags_pkey" primary key ("article_id", "tag_id"));`,
|
||||
);
|
||||
|
||||
this.addSql(
|
||||
`create table "package_consult_session" ("id" varchar(30) not null, "code" varchar(6) not null, "package_id" varchar(30) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "package_consult_session_pkey" primary key ("id"));`,
|
||||
);
|
||||
this.addSql(
|
||||
`alter table "package_consult_session" add constraint "package_consult_session_code_unique" unique ("code");`,
|
||||
);
|
||||
|
||||
this.addSql(
|
||||
`alter table "article_tags" add constraint "article_tags_article_id_foreign" foreign key ("article_id") references "article" ("id") on update cascade on delete cascade;`,
|
||||
);
|
||||
this.addSql(
|
||||
`alter table "article_tags" add constraint "article_tags_tag_id_foreign" foreign key ("tag_id") references "tag" ("id") on update cascade on delete cascade;`,
|
||||
);
|
||||
|
||||
this.addSql(
|
||||
`alter table "package_consult_session" add constraint "package_consult_session_package_id_foreign" foreign key ("package_id") references "package" ("id") on update cascade;`,
|
||||
);
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(
|
||||
`alter table "article_tags" drop constraint "article_tags_article_id_foreign";`,
|
||||
);
|
||||
|
||||
this.addSql(
|
||||
`alter table "article_tags" drop constraint "article_tags_tag_id_foreign";`,
|
||||
);
|
||||
|
||||
this.addSql(`drop table if exists "article" cascade;`);
|
||||
|
||||
this.addSql(`drop table if exists "tag" cascade;`);
|
||||
|
||||
this.addSql(`drop table if exists "article_tags" cascade;`);
|
||||
|
||||
this.addSql(`drop table if exists "package_consult_session" cascade;`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user