From 95670f6699f6fcca39465b2ebf8cb005d985af43 Mon Sep 17 00:00:00 2001 From: ItsMalma Date: Mon, 1 Dec 2025 20:35:24 +0700 Subject: [PATCH] restart migrations --- .../migrations/Migration20251201133232.ts | 121 ---- .../migrations/Migration20251201133512.ts | 530 ++++++++++++++++++ 2 files changed, 530 insertions(+), 121 deletions(-) delete mode 100644 src/database/migrations/Migration20251201133232.ts create mode 100644 src/database/migrations/Migration20251201133512.ts diff --git a/src/database/migrations/Migration20251201133232.ts b/src/database/migrations/Migration20251201133232.ts deleted file mode 100644 index 16499f7..0000000 --- a/src/database/migrations/Migration20251201133232.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { Migration } from "@mikro-orm/migrations"; - -export class Migration20251201133232 extends Migration { - override async up(): Promise { - this.addSql( - `alter table "airline" alter column "skytrax_type" type text using ("skytrax_type"::text);`, - ); - this.addSql( - `alter table "airline" add constraint "airline_skytrax_type_check" check("skytrax_type" in ('full_service', 'low_cost'));`, - ); - - this.addSql( - `alter table "package_itinerary_widget" alter column "type" type text using ("type"::text);`, - ); - this.addSql( - `alter table "package_itinerary_widget" add constraint "package_itinerary_widget_type_check" check("type" in ('hotel', 'information', 'transport'));`, - ); - - this.addSql( - `alter table "verification" alter column "type" type text using ("type"::text);`, - ); - this.addSql( - `alter table "verification" add constraint "verification_type_check" check("type" in ('admin:create', 'admin:changeEmail', 'admin:changePassword', 'admin:update', 'partner:create', 'partner:changeEmail', 'partner:changePassword', 'partner:update', 'order:create'));`, - ); - - this.addSql( - `alter table "package" alter column "type" type text using ("type"::text);`, - ); - this.addSql( - `alter table "package" alter column "class" type text using ("class"::text);`, - ); - this.addSql( - `alter table "package" add constraint "package_type_check" check("type" in ('reguler', 'plus'));`, - ); - this.addSql( - `alter table "package" add constraint "package_class_check" check("class" in ('silver', 'gold', 'platinum'));`, - ); - - this.addSql( - `alter table "order_detail" alter column "room_type" type text using ("room_type"::text);`, - ); - this.addSql( - `alter table "order_detail" add constraint "order_detail_room_type_check" check("room_type" in ('double', 'triple', 'quad', 'infant'));`, - ); - - this.addSql(`drop type "admin_permission";`); - this.addSql(`drop type "package_class";`); - this.addSql(`drop type "package_itinerary_widget_type";`); - this.addSql(`drop type "package_type";`); - this.addSql(`drop type "room_type";`); - this.addSql(`drop type "skytrax_type";`); - this.addSql(`drop type "verification_type";`); - } - - override async down(): Promise { - this.addSql( - `create type "admin_permission" as enum ('country:create', 'country:update', 'country:delete', 'city:create', 'city:update', 'city:delete', 'airline:create', 'airline:update', 'airline:delete', 'airport:create', 'airport:update', 'airport:delete', 'flight:create', 'flight:update', 'flight:delete', 'flight-class:create', 'flight-class:update', 'flight-class:delete', 'hotel-facility:create', 'hotel-facility:update', 'hotel-facility:delete', 'hotel:create', 'hotel:update', 'hotel:delete', 'transportation:create', 'transportation:update', 'transportation:delete', 'transportation-class:create', 'transportation-class:update', 'transportation-class:delete', 'package:create', 'package:update', 'package:delete', 'package-detail:create', 'package-detail:update', 'package-detail:delete', 'admin:create', 'admin:update', 'admin:delete', 'partner:create', 'partner:update', 'partner:delete');`, - ); - this.addSql( - `create type "package_class" as enum ('silver', 'gold', 'platinum');`, - ); - this.addSql( - `create type "package_itinerary_widget_type" as enum ('hotel', 'information', 'transport');`, - ); - this.addSql(`create type "package_type" as enum ('reguler', 'plus');`); - this.addSql( - `create type "room_type" as enum ('double', 'triple', 'quad', 'infant');`, - ); - this.addSql( - `create type "skytrax_type" as enum ('full_service', 'low_cost');`, - ); - this.addSql( - `create type "verification_type" as enum ('admin:create', 'admin:changeEmail', 'admin:changePassword', 'admin:update', 'partner:create', 'partner:changeEmail', 'partner:changePassword', 'partner:update', 'order:create');`, - ); - this.addSql( - `alter table "airline" drop constraint if exists "airline_skytrax_type_check";`, - ); - - this.addSql( - `alter table "order_detail" drop constraint if exists "order_detail_room_type_check";`, - ); - - this.addSql( - `alter table "package" drop constraint if exists "package_type_check";`, - ); - this.addSql( - `alter table "package" drop constraint if exists "package_class_check";`, - ); - - this.addSql( - `alter table "package_itinerary_widget" drop constraint if exists "package_itinerary_widget_type_check";`, - ); - - this.addSql( - `alter table "verification" drop constraint if exists "verification_type_check";`, - ); - - this.addSql( - `alter table "airline" alter column "skytrax_type" type "skytrax_type" using ("skytrax_type"::"skytrax_type");`, - ); - - this.addSql( - `alter table "order_detail" alter column "room_type" type "room_type" using ("room_type"::"room_type");`, - ); - - this.addSql( - `alter table "package" alter column "type" type "package_type" using ("type"::"package_type");`, - ); - this.addSql( - `alter table "package" alter column "class" type "package_class" using ("class"::"package_class");`, - ); - - this.addSql( - `alter table "package_itinerary_widget" alter column "type" type "package_itinerary_widget_type" using ("type"::"package_itinerary_widget_type");`, - ); - - this.addSql( - `alter table "verification" alter column "type" type "verification_type" using ("type"::"verification_type");`, - ); - } -} diff --git a/src/database/migrations/Migration20251201133512.ts b/src/database/migrations/Migration20251201133512.ts new file mode 100644 index 0000000..14aa832 --- /dev/null +++ b/src/database/migrations/Migration20251201133512.ts @@ -0,0 +1,530 @@ +import { Migration } from "@mikro-orm/migrations"; + +export class Migration20251201133512 extends Migration { + override async up(): Promise { + this.addSql( + `create table "airline" ("id" varchar(30) not null, "name" varchar(100) not null, "code" varchar(10) not null, "logo" varchar(100) not null, "skytrax_rating" int not null, "skytrax_type" text check ("skytrax_type" in ('full_service', 'low_cost')) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "airline_pkey" primary key ("id"));`, + ); + this.addSql( + `alter table "airline" add constraint "airline_code_unique" unique ("code");`, + ); + + 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 "country" ("id" varchar(30) not null, "name" varchar(100) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "country_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "city" ("id" varchar(30) not null, "name" varchar(100) not null, "country_id" varchar(30) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "city_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "airport" ("id" varchar(30) not null, "name" varchar(100) not null, "code" varchar(10) not null, "city_id" varchar(30) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "airport_pkey" primary key ("id"));`, + ); + this.addSql( + `alter table "airport" add constraint "airport_code_unique" unique ("code");`, + ); + + this.addSql( + `create table "flight" ("id" varchar(30) not null, "airline_id" varchar(30) not null, "number" int not null, "departure_airport_id" varchar(30) not null, "departure_terminal" varchar(100) null, "departure_gate" varchar(100) null, "departure_time" time(0) not null, "arrival_airport_id" varchar(30) not null, "arrival_terminal" varchar(100) null, "arrival_gate" varchar(100) null, "duration" int not null, "aircraft" varchar(100) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "flight_pkey" primary key ("id"));`, + ); + this.addSql( + `alter table "flight" add constraint "flight_airline_id_number_unique" unique ("airline_id", "number");`, + ); + + this.addSql( + `create table "flight_class" ("id" varchar(30) not null, "flight_id" varchar(30) not null, "class" varchar(100) not null, "seat_layout" varchar(10) not null, "baggage" int not null, "cabin_baggage" int not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "flight_class_pkey" primary key ("id"));`, + ); + this.addSql( + `alter table "flight_class" add constraint "flight_class_flight_id_class_unique" unique ("flight_id", "class");`, + ); + + this.addSql( + `create table "flight_schedule" ("id" varchar(30) not null, "flight_id" varchar(30) not null, "next_id" varchar(30) null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "flight_schedule_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "hotel" ("id" varchar(30) not null, "name" varchar(100) not null, "city_id" varchar(30) not null, "star" int not null, "google_maps_link" varchar(1000) not null, "google_maps_embed" varchar(1000) not null, "google_reviews_link" varchar(1000) not null, "description" varchar(1000) not null, "address" varchar(100) not null, "landmark" varchar(100) not null, "distance_to_landmark" numeric(10,0) not null, "food_type" varchar(100) not null, "food_amount" int not null, "food_menu" varchar(100) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "hotel_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "hotel_facility" ("id" varchar(30) not null, "name" varchar(100) not null, "icon" varchar(100) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "hotel_facility_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "hotel_facilities" ("hotel_id" varchar(30) not null, "hotel_facility_id" varchar(30) not null, constraint "hotel_facilities_pkey" primary key ("hotel_id", "hotel_facility_id"));`, + ); + + this.addSql( + `create table "hotel_image" ("id" varchar(30) not null, "hotel_id" varchar(30) not null, "src" varchar(100) not null, "created_at" varchar(100) not null, "updated_at" timestamptz not null, constraint "hotel_image_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "package_itinerary_day" ("id" varchar(30) not null, "title" varchar(100) not null, "description" varchar(1000) not null, "next_id" varchar(30) null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "package_itinerary_day_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "package_itinerary" ("id" varchar(30) not null, "location" varchar(100) not null, "day_id" varchar(30) null, "next_id" varchar(30) null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "package_itinerary_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "package_itinerary_image" ("id" varchar(30) not null, "package_itinerary_id" varchar(30) not null, "src" varchar(100) not null, "created_at" varchar(100) not null, "updated_at" timestamptz not null, constraint "package_itinerary_image_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "package_itinerary_widget" ("id" varchar(30) not null, "package_itinerary_day_id" varchar(30) not null, "type" text check ("type" in ('hotel', 'information', 'transport')) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, "hotel_id" varchar(30) null, "description" varchar(1000) null, "transportation" varchar(100) null, "from" varchar(100) null, "to" varchar(100) null, constraint "package_itinerary_widget_pkey" primary key ("id"));`, + ); + this.addSql( + `create index "package_itinerary_widget_type_index" on "package_itinerary_widget" ("type");`, + ); + + 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 "transportation" ("id" varchar(30) not null, "name" varchar(100) not null, "type" varchar(100) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "transportation_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "transportation_class" ("id" varchar(30) not null, "transportation_id" varchar(30) not null, "class" varchar(100) not null, "total_seats" int not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "transportation_class_pkey" primary key ("id"));`, + ); + this.addSql( + `alter table "transportation_class" add constraint "transportation_class_transportation_id_class_unique" unique ("transportation_id", "class");`, + ); + + this.addSql( + `create table "transportation_image" ("id" varchar(30) not null, "transportation_id" varchar(30) not null, "src" varchar(100) not null, "created_at" varchar(100) not null, "updated_at" timestamptz not null, constraint "transportation_image_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "verification" ("id" varchar(30) not null, "code" char(6) not null, "type" text check ("type" in ('admin:create', 'admin:changeEmail', 'admin:changePassword', 'admin:update', 'partner:create', 'partner:changeEmail', 'partner:changePassword', 'partner:update', 'order:create')) not null, "expired_at" timestamptz not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "verification_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "partner" ("id" varchar(30) not null, "name" varchar(100) not null, "email" varchar(254) not null, "whatsapp" varchar(20) not null, "password" text not null, "avatar" varchar(100) null, "verification_id" varchar(30) null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "partner_pkey" primary key ("id"));`, + ); + this.addSql( + `alter table "partner" add constraint "partner_email_unique" unique ("email");`, + ); + this.addSql( + `alter table "partner" add constraint "partner_whatsapp_unique" unique ("whatsapp");`, + ); + + this.addSql( + `create table "package" ("id" varchar(30) not null, "slug" varchar(100) not null, "name" varchar(100) not null, "type" text check ("type" in ('reguler', 'plus')) not null, "class" text check ("class" in ('silver', 'gold', 'platinum')) not null, "thumbnail" varchar(100) not null, "use_fast_train" boolean not null, "partner_id" varchar(30) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "package_pkey" primary key ("id"));`, + ); + this.addSql( + `alter table "package" add constraint "package_slug_unique" unique ("slug");`, + ); + + this.addSql( + `create table "package_detail" ("id" varchar(30) not null, "package_id" varchar(30) not null, "departure_date" date not null, "tour_flight_id" varchar(30) null, "outbound_flight_id" varchar(30) null, "inbound_flight_id" varchar(30) null, "makkah_hotel_id" varchar(30) null, "madinah_hotel_id" varchar(30) null, "transportation_id" varchar(30) not null, "quad_price" numeric(10,0) not null, "triple_price" numeric(10,0) not null, "double_price" numeric(10,0) not null, "infant_price" numeric(10,0) null, "itinerary_id" varchar(30) null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "package_detail_pkey" primary key ("id"));`, + ); + this.addSql( + `alter table "package_detail" add constraint "package_detail_package_id_departure_date_unique" unique ("package_id", "departure_date");`, + ); + + this.addSql( + `create table "package_detail_tour_hotels" ("package_detail_id" varchar(30) not null, "hotel_id" varchar(30) not null, constraint "package_detail_tour_hotels_pkey" primary key ("package_detail_id", "hotel_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( + `create table "order" ("id" varchar(30) not null, "package_id" varchar(30) not null, "name" varchar(100) not null, "whatsapp" varchar(20) not null, "verification_id" varchar(30) null, "partner_id" varchar(30) null, "expired_at" timestamptz null, "purchased_at" timestamptz null, "finished_at" timestamptz null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "order_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "order_detail" ("id" varchar(30) not null, "order_id" varchar(30) not null, "room_type" text check ("room_type" in ('double', 'triple', 'quad', 'infant')) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "order_detail_pkey" primary key ("id"));`, + ); + + this.addSql( + `create table "admin" ("id" varchar(30) not null, "name" varchar(100) not null, "email" varchar(254) not null, "password" text not null, "avatar" varchar(100) null, "permissions" text[] not null, "verification_id" varchar(30) null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "admin_pkey" primary key ("id"));`, + ); + this.addSql( + `alter table "admin" add constraint "admin_email_unique" unique ("email");`, + ); + + this.addSql( + `alter table "city" add constraint "city_country_id_foreign" foreign key ("country_id") references "country" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "airport" add constraint "airport_city_id_foreign" foreign key ("city_id") references "city" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "flight" add constraint "flight_airline_id_foreign" foreign key ("airline_id") references "airline" ("id") on update cascade;`, + ); + this.addSql( + `alter table "flight" add constraint "flight_departure_airport_id_foreign" foreign key ("departure_airport_id") references "airport" ("id") on update cascade;`, + ); + this.addSql( + `alter table "flight" add constraint "flight_arrival_airport_id_foreign" foreign key ("arrival_airport_id") references "airport" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "flight_class" add constraint "flight_class_flight_id_foreign" foreign key ("flight_id") references "flight" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "flight_schedule" add constraint "flight_schedule_flight_id_foreign" foreign key ("flight_id") references "flight_class" ("id") on update cascade;`, + ); + this.addSql( + `alter table "flight_schedule" add constraint "flight_schedule_next_id_foreign" foreign key ("next_id") references "flight_schedule" ("id") on delete cascade;`, + ); + + this.addSql( + `alter table "hotel" add constraint "hotel_city_id_foreign" foreign key ("city_id") references "city" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "hotel_facilities" add constraint "hotel_facilities_hotel_id_foreign" foreign key ("hotel_id") references "hotel" ("id") on update cascade on delete cascade;`, + ); + this.addSql( + `alter table "hotel_facilities" add constraint "hotel_facilities_hotel_facility_id_foreign" foreign key ("hotel_facility_id") references "hotel_facility" ("id") on update cascade on delete cascade;`, + ); + + this.addSql( + `alter table "hotel_image" add constraint "hotel_image_hotel_id_foreign" foreign key ("hotel_id") references "hotel" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "package_itinerary_day" add constraint "package_itinerary_day_next_id_foreign" foreign key ("next_id") references "package_itinerary_day" ("id") on delete cascade;`, + ); + + this.addSql( + `alter table "package_itinerary" add constraint "package_itinerary_day_id_foreign" foreign key ("day_id") references "package_itinerary_day" ("id") on delete cascade;`, + ); + this.addSql( + `alter table "package_itinerary" add constraint "package_itinerary_next_id_foreign" foreign key ("next_id") references "package_itinerary" ("id") on delete cascade;`, + ); + + this.addSql( + `alter table "package_itinerary_image" add constraint "package_itinerary_image_package_itinerary_id_foreign" foreign key ("package_itinerary_id") references "package_itinerary" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "package_itinerary_widget" add constraint "package_itinerary_widget_package_itinerary_day_id_foreign" foreign key ("package_itinerary_day_id") references "package_itinerary_day" ("id") on update cascade;`, + ); + this.addSql( + `alter table "package_itinerary_widget" add constraint "package_itinerary_widget_hotel_id_foreign" foreign key ("hotel_id") references "hotel" ("id") on update cascade on delete set null;`, + ); + + 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 "transportation_class" add constraint "transportation_class_transportation_id_foreign" foreign key ("transportation_id") references "transportation" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "transportation_image" add constraint "transportation_image_transportation_id_foreign" foreign key ("transportation_id") references "transportation_class" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "partner" add constraint "partner_verification_id_foreign" foreign key ("verification_id") references "verification" ("id") on update cascade on delete set null;`, + ); + + this.addSql( + `alter table "package" add constraint "package_partner_id_foreign" foreign key ("partner_id") references "partner" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "package_detail" add constraint "package_detail_package_id_foreign" foreign key ("package_id") references "package" ("id") on update cascade;`, + ); + this.addSql( + `alter table "package_detail" add constraint "package_detail_tour_flight_id_foreign" foreign key ("tour_flight_id") references "flight_schedule" ("id") on delete cascade;`, + ); + this.addSql( + `alter table "package_detail" add constraint "package_detail_outbound_flight_id_foreign" foreign key ("outbound_flight_id") references "flight_schedule" ("id") on delete cascade;`, + ); + this.addSql( + `alter table "package_detail" add constraint "package_detail_inbound_flight_id_foreign" foreign key ("inbound_flight_id") references "flight_schedule" ("id") on delete cascade;`, + ); + this.addSql( + `alter table "package_detail" add constraint "package_detail_makkah_hotel_id_foreign" foreign key ("makkah_hotel_id") references "hotel" ("id") on delete cascade;`, + ); + this.addSql( + `alter table "package_detail" add constraint "package_detail_madinah_hotel_id_foreign" foreign key ("madinah_hotel_id") references "hotel" ("id") on delete cascade;`, + ); + this.addSql( + `alter table "package_detail" add constraint "package_detail_transportation_id_foreign" foreign key ("transportation_id") references "transportation_class" ("id") on update cascade;`, + ); + this.addSql( + `alter table "package_detail" add constraint "package_detail_itinerary_id_foreign" foreign key ("itinerary_id") references "package_itinerary" ("id") on delete cascade;`, + ); + + this.addSql( + `alter table "package_detail_tour_hotels" add constraint "package_detail_tour_hotels_package_detail_id_foreign" foreign key ("package_detail_id") references "package_detail" ("id") on update cascade on delete cascade;`, + ); + this.addSql( + `alter table "package_detail_tour_hotels" add constraint "package_detail_tour_hotels_hotel_id_foreign" foreign key ("hotel_id") references "hotel" ("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;`, + ); + + this.addSql( + `alter table "order" add constraint "order_package_id_foreign" foreign key ("package_id") references "package_detail" ("id") on update cascade;`, + ); + this.addSql( + `alter table "order" add constraint "order_verification_id_foreign" foreign key ("verification_id") references "verification" ("id") on update cascade on delete set null;`, + ); + this.addSql( + `alter table "order" add constraint "order_partner_id_foreign" foreign key ("partner_id") references "partner" ("id") on update cascade on delete set null;`, + ); + + this.addSql( + `alter table "order_detail" add constraint "order_detail_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;`, + ); + + this.addSql( + `alter table "admin" add constraint "admin_verification_id_foreign" foreign key ("verification_id") references "verification" ("id") on update cascade on delete set null;`, + ); + } + + override async down(): Promise { + this.addSql( + `alter table "flight" drop constraint "flight_airline_id_foreign";`, + ); + + this.addSql( + `alter table "article_tags" drop constraint "article_tags_article_id_foreign";`, + ); + + this.addSql( + `alter table "city" drop constraint "city_country_id_foreign";`, + ); + + this.addSql( + `alter table "airport" drop constraint "airport_city_id_foreign";`, + ); + + this.addSql(`alter table "hotel" drop constraint "hotel_city_id_foreign";`); + + this.addSql( + `alter table "flight" drop constraint "flight_departure_airport_id_foreign";`, + ); + + this.addSql( + `alter table "flight" drop constraint "flight_arrival_airport_id_foreign";`, + ); + + this.addSql( + `alter table "flight_class" drop constraint "flight_class_flight_id_foreign";`, + ); + + this.addSql( + `alter table "flight_schedule" drop constraint "flight_schedule_flight_id_foreign";`, + ); + + this.addSql( + `alter table "flight_schedule" drop constraint "flight_schedule_next_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail" drop constraint "package_detail_tour_flight_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail" drop constraint "package_detail_outbound_flight_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail" drop constraint "package_detail_inbound_flight_id_foreign";`, + ); + + this.addSql( + `alter table "hotel_facilities" drop constraint "hotel_facilities_hotel_id_foreign";`, + ); + + this.addSql( + `alter table "hotel_image" drop constraint "hotel_image_hotel_id_foreign";`, + ); + + this.addSql( + `alter table "package_itinerary_widget" drop constraint "package_itinerary_widget_hotel_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail" drop constraint "package_detail_makkah_hotel_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail" drop constraint "package_detail_madinah_hotel_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail_tour_hotels" drop constraint "package_detail_tour_hotels_hotel_id_foreign";`, + ); + + this.addSql( + `alter table "hotel_facilities" drop constraint "hotel_facilities_hotel_facility_id_foreign";`, + ); + + this.addSql( + `alter table "package_itinerary_day" drop constraint "package_itinerary_day_next_id_foreign";`, + ); + + this.addSql( + `alter table "package_itinerary" drop constraint "package_itinerary_day_id_foreign";`, + ); + + this.addSql( + `alter table "package_itinerary_widget" drop constraint "package_itinerary_widget_package_itinerary_day_id_foreign";`, + ); + + this.addSql( + `alter table "package_itinerary" drop constraint "package_itinerary_next_id_foreign";`, + ); + + this.addSql( + `alter table "package_itinerary_image" drop constraint "package_itinerary_image_package_itinerary_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail" drop constraint "package_detail_itinerary_id_foreign";`, + ); + + this.addSql( + `alter table "article_tags" drop constraint "article_tags_tag_id_foreign";`, + ); + + this.addSql( + `alter table "transportation_class" drop constraint "transportation_class_transportation_id_foreign";`, + ); + + this.addSql( + `alter table "transportation_image" drop constraint "transportation_image_transportation_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail" drop constraint "package_detail_transportation_id_foreign";`, + ); + + this.addSql( + `alter table "partner" drop constraint "partner_verification_id_foreign";`, + ); + + this.addSql( + `alter table "order" drop constraint "order_verification_id_foreign";`, + ); + + this.addSql( + `alter table "admin" drop constraint "admin_verification_id_foreign";`, + ); + + this.addSql( + `alter table "package" drop constraint "package_partner_id_foreign";`, + ); + + this.addSql( + `alter table "order" drop constraint "order_partner_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail" drop constraint "package_detail_package_id_foreign";`, + ); + + this.addSql( + `alter table "package_consult_session" drop constraint "package_consult_session_package_id_foreign";`, + ); + + this.addSql( + `alter table "package_detail_tour_hotels" drop constraint "package_detail_tour_hotels_package_detail_id_foreign";`, + ); + + this.addSql( + `alter table "order" drop constraint "order_package_id_foreign";`, + ); + + this.addSql( + `alter table "order_detail" drop constraint "order_detail_order_id_foreign";`, + ); + + this.addSql(`drop table if exists "airline" cascade;`); + + this.addSql(`drop table if exists "article" cascade;`); + + this.addSql(`drop table if exists "country" cascade;`); + + this.addSql(`drop table if exists "city" cascade;`); + + this.addSql(`drop table if exists "airport" cascade;`); + + this.addSql(`drop table if exists "flight" cascade;`); + + this.addSql(`drop table if exists "flight_class" cascade;`); + + this.addSql(`drop table if exists "flight_schedule" cascade;`); + + this.addSql(`drop table if exists "hotel" cascade;`); + + this.addSql(`drop table if exists "hotel_facility" cascade;`); + + this.addSql(`drop table if exists "hotel_facilities" cascade;`); + + this.addSql(`drop table if exists "hotel_image" cascade;`); + + this.addSql(`drop table if exists "package_itinerary_day" cascade;`); + + this.addSql(`drop table if exists "package_itinerary" cascade;`); + + this.addSql(`drop table if exists "package_itinerary_image" cascade;`); + + this.addSql(`drop table if exists "package_itinerary_widget" cascade;`); + + this.addSql(`drop table if exists "tag" cascade;`); + + this.addSql(`drop table if exists "article_tags" cascade;`); + + this.addSql(`drop table if exists "transportation" cascade;`); + + this.addSql(`drop table if exists "transportation_class" cascade;`); + + this.addSql(`drop table if exists "transportation_image" cascade;`); + + this.addSql(`drop table if exists "verification" cascade;`); + + this.addSql(`drop table if exists "partner" cascade;`); + + this.addSql(`drop table if exists "package" cascade;`); + + this.addSql(`drop table if exists "package_detail" cascade;`); + + this.addSql(`drop table if exists "package_detail_tour_hotels" cascade;`); + + this.addSql(`drop table if exists "package_consult_session" cascade;`); + + this.addSql(`drop table if exists "order" cascade;`); + + this.addSql(`drop table if exists "order_detail" cascade;`); + + this.addSql(`drop table if exists "admin" cascade;`); + } +}