44 lines
4.1 KiB
TypeScript
44 lines
4.1 KiB
TypeScript
import { Migration } from '@mikro-orm/migrations';
|
|
|
|
export class Migration20260222084735 extends Migration {
|
|
|
|
override async up(): Promise<void> {
|
|
this.addSql(`create table "learning_categories" ("id" char(26) not null, "created_at" timestamptz not null default now(), "deleted_at" timestamptz null, "name" varchar(100) not null, constraint "learning_categories_pkey" primary key ("id"));`);
|
|
this.addSql(`alter table "learning_categories" add constraint "learning_categories_name_unique" unique ("name");`);
|
|
|
|
this.addSql(`create table "learnings" ("id" char(26) not null, "created_at" timestamptz not null default now(), "deleted_at" timestamptz null, "title" varchar(200) not null, "description" text not null, "cover_url" text not null, "video_url" text null, "video_duration" varchar(200) null, "category_id" char(26) not null, constraint "learnings_pkey" primary key ("id"));`);
|
|
|
|
this.addSql(`create table "prints" ("id" char(26) not null, "created_at" timestamptz not null default now(), "deleted_at" timestamptz null, "fileds" jsonb null, constraint "prints_pkey" primary key ("id"));`);
|
|
|
|
this.addSql(`create table "learning_progress" ("id" char(26) not null, "created_at" timestamptz not null default now(), "deleted_at" timestamptz null, "user_id" char(26) not null, "learning_id" char(26) not null, "watched_at" timestamptz not null default CURRENT_TIMESTAMP, constraint "learning_progress_pkey" primary key ("id"));`);
|
|
|
|
this.addSql(`alter table "learnings" add constraint "learnings_category_id_foreign" foreign key ("category_id") references "learning_categories" ("id") on update cascade;`);
|
|
|
|
this.addSql(`alter table "learning_progress" add constraint "learning_progress_user_id_foreign" foreign key ("user_id") references "users" ("id") on update cascade;`);
|
|
this.addSql(`alter table "learning_progress" add constraint "learning_progress_learning_id_foreign" foreign key ("learning_id") references "learnings" ("id") on update cascade;`);
|
|
|
|
this.addSql(`alter table "permissions" drop constraint if exists "permissions_name_check";`);
|
|
|
|
this.addSql(`alter table "permissions" add constraint "permissions_name_check" check("name" in ('manage_products', 'manage_categories', 'view_requests', 'delete_request', 'update_request', 'view_invoices', 'create_invoice', 'update_invoice', 'delete_invoice', 'view_all_invoiced_orders', 'view_my_assigned_invoiced_requests', 'view_orders', 'view_assigned_orders', 'create_order', 'update_order', 'assign_designer', 'delete_order', 'manage_admins', 'manage_roles', 'manage_users', 'manage_payments', 'manage_settings', 'manage_form_builder', 'create_print', 'view_print', 'manage_learnings'));`);
|
|
|
|
this.addSql(`alter table "orders" add column "print_id" char(26) null;`);
|
|
this.addSql(`alter table "orders" add constraint "orders_print_id_foreign" foreign key ("print_id") references "prints" ("id") on update cascade on delete set null;`);
|
|
this.addSql(`alter table "orders" add constraint "orders_print_id_unique" unique ("print_id");`);
|
|
|
|
this.addSql(`alter table "credit_transactions" rename column "order_id" to "invoice_id";`);
|
|
}
|
|
|
|
override async down(): Promise<void> {
|
|
this.addSql(`alter table "permissions" drop constraint if exists "permissions_name_check";`);
|
|
|
|
this.addSql(`alter table "permissions" add constraint "permissions_name_check" check("name" in ('manage_products', 'manage_categories', 'view_requests', 'delete_request', 'update_request', 'view_invoices', 'create_invoice', 'update_invoice', 'delete_invoice', 'view_all_invoiced_orders', 'view_my_assigned_invoiced_requests', 'view_orders', 'view_assigned_orders', 'create_order', 'update_order', 'assign_designer', 'delete_order', 'manage_admins', 'manage_roles', 'manage_users', 'manage_payments', 'manage_settings', 'manage_form_builder', 'manage_print'));`);
|
|
|
|
this.addSql(`alter table "orders" drop constraint "orders_print_id_unique";`);
|
|
|
|
this.addSql(`alter table "orders" add column "attributes" jsonb null, add column "printery" varchar(255) null, add column "lithography" varchar(255) null;`);
|
|
|
|
this.addSql(`alter table "credit_transactions" rename column "invoice_id" to "order_id";`);
|
|
}
|
|
|
|
}
|