setup database, entities, and migrations

This commit is contained in:
ItsMalma
2025-11-04 18:02:28 +07:00
parent 9aa0de17ee
commit b347ab0250
25 changed files with 3608 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
import { databaseConfig } from "@/configs/database.config";
import { Migrator } from "@mikro-orm/migrations";
import { defineConfig } from "@mikro-orm/postgresql";
export default defineConfig({
host: databaseConfig.host,
port: databaseConfig.port,
user: databaseConfig.username,
password: databaseConfig.password,
dbName: databaseConfig.name,
entities: ["src/database/entities/*.entity.ts"],
entitiesTs: ["src/database/entities/*.entity.ts"],
extensions: [Migrator],
migrations: {
tableName: "_migrations",
path: "src/database/migrations",
pathTs: "src/database/migrations",
},
});

View File

@@ -0,0 +1,56 @@
import { Flight } from "@/database/entities/flight.entity";
import { SkytraxType } from "@/database/enums/skytrax-type.enum";
import {
Collection,
Entity,
Enum,
OneToMany,
PrimaryKey,
Property,
Unique,
} from "@mikro-orm/core";
@Entity()
export class Airline {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 10 })
@Unique()
code!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@Property({ type: "varchar", length: 100 })
name!: string;
@Property({ type: "varchar", length: 100 })
@Unique()
logo!: string;
@Property({ type: "int", nullable: true })
skytraxRating!: number;
@Enum(() => SkytraxType)
skytraxType!: SkytraxType;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@OneToMany(() => Flight, (flight) => flight.airline)
flights = new Collection<Flight>(this);
}

View File

@@ -0,0 +1,53 @@
import { City } from "@/database/entities/city.entity";
import { Flight } from "@/database/entities/flight.entity";
import {
Collection,
Entity,
ManyToOne,
OneToMany,
PrimaryKey,
Property,
type Rel,
Unique,
} from "@mikro-orm/core";
@Entity()
export class Airport {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 10 })
@Unique()
code!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@Property({ type: "varchar", length: 100 })
name!: string;
@ManyToOne(() => City)
city!: Rel<City>;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@OneToMany(() => Flight, (flight) => flight.departureAirport)
departureFlights = new Collection<Flight>(this);
@OneToMany(() => Flight, (flight) => flight.arrivalAirport)
arrivalFlights = new Collection<Flight>(this);
}

View File

@@ -0,0 +1,50 @@
import { Airport } from "@/database/entities/airport.entity";
import { Country } from "@/database/entities/country.entity";
import { Hotel } from "@/database/entities/hotel.entity";
import {
Collection,
Entity,
ManyToOne,
OneToMany,
PrimaryKey,
Property,
Unique,
type Rel,
} from "@mikro-orm/core";
@Entity()
export class City {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@Property({ type: "varchar", length: 100 })
name!: string;
@ManyToOne(() => Country)
country!: Rel<Country>;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@OneToMany(() => Airport, (airport) => airport.city)
cities = new Collection<City>(this);
@OneToMany(() => Hotel, (hotel) => hotel.city)
hotels = new Collection<Hotel>(this);
}

View File

@@ -0,0 +1,40 @@
import { City } from "@/database/entities/city.entity";
import {
Collection,
Entity,
OneToMany,
PrimaryKey,
Property,
Unique,
} from "@mikro-orm/core";
@Entity()
export class Country {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@Property({ type: "varchar", length: 100 })
name!: string;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@OneToMany(() => City, (city) => city.country)
cities = new Collection<City>(this);
}

View File

@@ -0,0 +1,71 @@
import { Flight } from "@/database/entities/flight.entity";
import { PackageDetail } from "@/database/entities/package-detail.entity";
import {
Collection,
Entity,
ManyToMany,
ManyToOne,
PrimaryKey,
Property,
Unique,
type Rel,
} from "@mikro-orm/core";
@Entity()
@Unique({ properties: ["flight", "class"] })
export class FlightClass {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 420 })
@Unique()
slug!: string;
@ManyToOne(() => Flight)
flight!: Rel<Flight>;
@Property({ type: "varchar", length: 100 })
class!: string;
@Property({ type: "varchar", length: 10 })
seatLayout!: string;
@Property({ type: "integer", unsigned: true })
baggage!: number;
@Property({ type: "integer", unsigned: true })
cabinBaggage!: number;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@ManyToMany(
() => PackageDetail,
(packageDetail) => packageDetail.tourFlightClasses,
)
tourPackageDetails = new Collection<PackageDetail>(this);
@ManyToMany(
() => PackageDetail,
(packageDetail) => packageDetail.outboundFlightClasses,
)
outboundPackageDetails = new Collection<PackageDetail>(this);
@ManyToMany(
() => PackageDetail,
(packageDetail) => packageDetail.inboundFlightClasses,
)
inboundPackageDetails = new Collection<PackageDetail>(this);
}

View File

@@ -0,0 +1,75 @@
import { Airline } from "@/database/entities/airline.entity";
import { Airport } from "@/database/entities/airport.entity";
import { FlightClass } from "@/database/entities/flight-class.entity";
import {
Collection,
Entity,
ManyToOne,
OneToMany,
PrimaryKey,
Property,
Unique,
type Rel,
} from "@mikro-orm/core";
@Entity()
@Unique({ properties: ["airline", "number"] })
export class Flight {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 220 })
@Unique()
slug!: string;
@ManyToOne(() => Airline)
airline!: Rel<Airline>;
@Property({ type: "integer", unsigned: true })
number!: number;
@ManyToOne(() => Airport)
departureAirport!: Rel<Airport>;
@Property({ type: "varchar", length: 100, nullable: true })
departureTerminal?: string;
@Property({ type: "varchar", length: 100, nullable: true })
departureGate?: string;
@Property({ type: "time" })
departureTime!: string;
@ManyToOne(() => Airport)
arrivalAirport!: Rel<Airport>;
@Property({ type: "varchar", length: 100, nullable: true })
arrivalTerminal?: string;
@Property({ type: "varchar", length: 100, nullable: true })
arrivalGate?: string;
@Property({ type: "integer", unsigned: true })
duration!: number;
@Property({ type: "varchar", length: 100 })
aircraft!: string;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@OneToMany(() => FlightClass, (flightClass) => flightClass.flight)
classes = new Collection<FlightClass>(this);
}

View File

@@ -0,0 +1,43 @@
import { Hotel } from "@/database/entities/hotel.entity";
import {
Collection,
Entity,
ManyToMany,
PrimaryKey,
Property,
Unique,
} from "@mikro-orm/core";
@Entity()
export class HotelFacility {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@Property({ type: "varchar", length: 100 })
name!: string;
@Property({ type: "varchar", length: 100 })
icon!: string;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@ManyToMany(() => Hotel, (hotel) => hotel.facilities)
hotels = new Collection<HotelFacility>(this);
}

View File

@@ -0,0 +1,34 @@
import { Hotel } from "@/database/entities/hotel.entity";
import {
Entity,
ManyToOne,
PrimaryKey,
Property,
type Rel,
} from "@mikro-orm/core";
@Entity()
export class HotelImage {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@ManyToOne(() => Hotel)
hotel!: Rel<Hotel>;
@Property({ type: "varchar", length: 100 })
src!: string;
@Property({ type: "varchar", length: 100 })
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
}

View File

@@ -0,0 +1,96 @@
import { City } from "@/database/entities/city.entity";
import { HotelFacility } from "@/database/entities/hotel-facility.entity";
import { HotelImage } from "@/database/entities/hotel-image.entity";
import { PackageDetail } from "@/database/entities/package-detail.entity";
import {
Collection,
Entity,
ManyToMany,
ManyToOne,
OneToMany,
PrimaryKey,
Property,
Unique,
type Rel,
} from "@mikro-orm/core";
@Entity()
export class Hotel {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@Property({ type: "varchar", length: 100 })
name!: string;
@ManyToOne(() => City)
city!: Rel<City>;
@Property({ type: "integer", unsigned: true })
star!: number;
@Property({ type: "varchar", length: 500 })
googleMapsLink!: string;
@Property({ type: "varchar", length: 500 })
googleMapsEmbed!: string;
@Property({ type: "varchar", length: 500 })
googleReviewsLink!: string;
@Property({ type: "varchar", length: 1000 })
description!: string;
@Property({ type: "varchar", length: 100 })
address!: string;
@Property({ type: "varchar", length: 100 })
landmark!: string;
@Property({ type: "decimal" })
distanceToLandmark!: string;
@Property({ type: "varchar", length: 100 })
foodType!: string;
@Property({ type: "integer", unsigned: true })
foodAmount!: string;
@Property({ type: "varchar", length: 100 })
foodMenu!: string;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@OneToMany(() => HotelImage, (hotelImage) => hotelImage.hotel)
images = new Collection<HotelImage>(this);
@ManyToMany(() => HotelFacility, (hotelFacility) => hotelFacility.hotels, {
owner: true,
})
facilities = new Collection<HotelFacility>(this);
@ManyToMany(() => PackageDetail, (packageDetail) => packageDetail.tourHotels)
tourPackageDetails = new Collection<PackageDetail>(this);
@OneToMany(() => PackageDetail, (packageDetail) => packageDetail.makkahHotel)
makkahPackageDetails = new Collection<PackageDetail>(this);
@OneToMany(() => PackageDetail, (packageDetail) => packageDetail.madinahHotel)
madinahPackageDetails = new Collection<PackageDetail>(this);
}

View File

@@ -0,0 +1,103 @@
import { FlightClass } from "@/database/entities/flight-class.entity";
import { Hotel } from "@/database/entities/hotel.entity";
import { Package } from "@/database/entities/package.entity";
import { TransportationClass } from "@/database/entities/transportation-class.entity";
import {
Collection,
Entity,
ManyToMany,
ManyToOne,
PrimaryKey,
Property,
Unique,
type Rel,
} from "@mikro-orm/core";
@Entity()
@Unique({ properties: ["package", "departureDate"] })
export class PackageDetail {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@ManyToOne(() => Package)
package!: Rel<Package>;
@Property({ type: "date" })
departureDate!: Date;
@ManyToOne(() => Hotel)
makkahHotel!: Rel<Hotel>;
@ManyToOne(() => Hotel)
madinahHotel!: Rel<Hotel>;
@ManyToOne(() => TransportationClass)
transportation!: Rel<TransportationClass>;
@Property({ type: "decimal", unsigned: true })
quadPrice!: number;
@Property({ type: "decimal", unsigned: true })
triplePrice!: number;
@Property({ type: "decimal", unsigned: true })
doublePrice!: number;
@Property({ type: "decimal", nullable: true, unsigned: true })
infantPrice?: number;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@ManyToMany(
() => FlightClass,
(flightClass) => flightClass.tourPackageDetails,
{
owner: true,
fixedOrder: true,
},
)
tourFlightClasses = new Collection<FlightClass>(this);
@ManyToMany(
() => FlightClass,
(flightClass) => flightClass.outboundPackageDetails,
{
owner: true,
fixedOrder: true,
},
)
outboundFlightClasses = new Collection<FlightClass>(this);
@ManyToMany(
() => FlightClass,
(flightClass) => flightClass.inboundPackageDetails,
{
owner: true,
fixedOrder: true,
},
)
inboundFlightClasses = new Collection<FlightClass>(this);
@ManyToMany(() => Hotel, (hotel) => hotel.tourPackageDetails, {
owner: true,
fixedOrder: true,
})
tourHotels = new Collection<Hotel>(this);
}

View File

@@ -0,0 +1,56 @@
import { PackageDetail } from "@/database/entities/package-detail.entity";
import { PackageClass } from "@/database/enums/package-class.enum";
import { PackageType } from "@/database/enums/package-type.enum";
import {
Collection,
Entity,
Enum,
OneToMany,
PrimaryKey,
Property,
Unique,
} from "@mikro-orm/core";
@Entity()
export class Package {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@Property({ type: "varchar", length: 100 })
name!: string;
@Enum(() => PackageType)
type!: PackageType;
@Enum(() => PackageClass)
class!: PackageClass;
@Property({ type: "varchar", length: 100 })
@Unique()
thumbnail!: string;
@Property({ type: "boolean" })
useFastTrain!: boolean;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@OneToMany(() => PackageDetail, (packageDetail) => packageDetail.package)
details = new Collection<PackageDetail>(this);
}

View File

@@ -0,0 +1,34 @@
import { TransportationClass } from "@/database/entities/transportation-class.entity";
import {
Entity,
ManyToOne,
PrimaryKey,
Property,
type Rel,
} from "@mikro-orm/core";
@Entity()
export class TransportationClassImage {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@ManyToOne(() => TransportationClass)
transportationClass!: Rel<TransportationClass>;
@Property({ type: "varchar", length: 100 })
src!: string;
@Property({ type: "varchar", length: 100 })
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
}

View File

@@ -0,0 +1,60 @@
import { PackageDetail } from "@/database/entities/package-detail.entity";
import { TransportationClassImage } from "@/database/entities/transportation-class-image.entity";
import { Transportation } from "@/database/entities/transportation.entity";
import {
Collection,
Entity,
ManyToOne,
OneToMany,
PrimaryKey,
Property,
Unique,
type Rel,
} from "@mikro-orm/core";
@Entity()
@Unique({ properties: ["transportation", "class"] })
export class TransportationClass {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 400 })
@Unique()
slug!: string;
@ManyToOne(() => Transportation)
transportation!: Rel<Transportation>;
@Property({ type: "varchar", length: 100 })
class!: string;
@Property({ type: "integer", unsigned: true })
totalSeats!: number;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@OneToMany(
() => TransportationClassImage,
(transportationClassImage) => transportationClassImage.transportationClass,
)
images = new Collection<TransportationClass>(this);
@OneToMany(
() => PackageDetail,
(packageDetail) => packageDetail.transportation,
)
packageDetails = new Collection<PackageDetail>(this);
}

View File

@@ -0,0 +1,46 @@
import { TransportationClass } from "@/database/entities/transportation-class.entity";
import {
Collection,
Entity,
OneToMany,
PrimaryKey,
Property,
Unique,
} from "@mikro-orm/core";
@Entity()
export class Transportation {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 100 })
@Unique()
slug!: string;
@Property({ type: "varchar", length: 100 })
name!: string;
@Property({ type: "varchar", length: 100 })
type!: string;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Collections
@OneToMany(
() => TransportationClass,
(transportationClass) => transportationClass.transportation,
)
transportationClasses = new Collection<TransportationClass>(this);
}

View File

@@ -0,0 +1,5 @@
export enum PackageClass {
silver = "silver",
gold = "gold",
platinum = "platinum",
}

View File

@@ -0,0 +1,4 @@
export enum PackageType {
reguler = "reguler",
plus = "plus",
}

View File

@@ -0,0 +1,4 @@
export enum SkytraxType {
fullService = "full_service",
lowCost = "low_cost",
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,367 @@
import { Migration } from "@mikro-orm/migrations";
export class Migration20251104110158 extends Migration {
override async up(): Promise<void> {
this.addSql(
`create table "airline" ("id" varchar(30) not null, "code" varchar(10) not null, "slug" varchar(200) not null, "name" varchar(100) not null, "logo" varchar(100) not null, "skytrax_rating" int 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(
`alter table "airline" add constraint "airline_slug_unique" unique ("slug");`,
);
this.addSql(
`alter table "airline" add constraint "airline_logo_unique" unique ("logo");`,
);
this.addSql(
`create table "country" ("id" varchar(30) not null, "slug" varchar(200) 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(
`alter table "country" add constraint "country_slug_unique" unique ("slug");`,
);
this.addSql(
`create table "city" ("id" varchar(30) not null, "slug" varchar(200) 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(
`alter table "city" add constraint "city_slug_unique" unique ("slug");`,
);
this.addSql(
`create table "airport" ("id" varchar(30) not null, "code" varchar(10) not null, "slug" varchar(200) not null, "name" varchar(100) 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(
`alter table "airport" add constraint "airport_slug_unique" unique ("slug");`,
);
this.addSql(
`create table "flight" ("id" varchar(30) not null, "slug" varchar(220) 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_slug_unique" unique ("slug");`,
);
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, "slug" varchar(420) 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_slug_unique" unique ("slug");`,
);
this.addSql(
`alter table "flight_class" add constraint "flight_class_flight_id_class_unique" unique ("flight_id", "class");`,
);
this.addSql(
`create table "hotel" ("id" varchar(30) not null, "slug" varchar(200) not null, "name" varchar(100) not null, "city_id" varchar(30) not null, "star" int not null, "google_maps_link" varchar(500) not null, "google_maps_embed" varchar(500) not null, "google_reviews_link" varchar(500) 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(
`alter table "hotel" add constraint "hotel_slug_unique" unique ("slug");`,
);
this.addSql(
`create table "hotel_facility" ("id" varchar(30) not null, "slug" varchar(200) 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(
`alter table "hotel_facility" add constraint "hotel_facility_slug_unique" unique ("slug");`,
);
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" ("id" varchar(30) not null, "slug" varchar(200) 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, "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(
`alter table "package" add constraint "package_thumbnail_unique" unique ("thumbnail");`,
);
this.addSql(
`create table "transportation" ("id" varchar(30) not null, "slug" varchar(100) 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(
`alter table "transportation" add constraint "transportation_slug_unique" unique ("slug");`,
);
this.addSql(
`create table "transportation_class" ("id" varchar(30) not null, "slug" varchar(400) 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_slug_unique" unique ("slug");`,
);
this.addSql(
`alter table "transportation_class" add constraint "transportation_class_transportation_id_class_unique" unique ("transportation_id", "class");`,
);
this.addSql(
`create table "package_detail" ("id" varchar(30) not null, "slug" varchar(200) not null, "package_id" varchar(30) not null, "departure_date" date not null, "makkah_hotel_id" varchar(30) not null, "madinah_hotel_id" varchar(30) not 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, "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_slug_unique" unique ("slug");`,
);
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" ("id" serial primary key, "package_detail_id" varchar(30) not null, "hotel_id" varchar(30) not null);`,
);
this.addSql(
`create table "package_detail_tour_flight_classes" ("id" serial primary key, "package_detail_id" varchar(30) not null, "flight_class_id" varchar(30) not null);`,
);
this.addSql(
`create table "package_detail_outbound_flight_classes" ("id" serial primary key, "package_detail_id" varchar(30) not null, "flight_class_id" varchar(30) not null);`,
);
this.addSql(
`create table "package_detail_inbound_flight_classes" ("id" serial primary key, "package_detail_id" varchar(30) not null, "flight_class_id" varchar(30) not null);`,
);
this.addSql(
`create table "transportation_class_image" ("id" varchar(30) not null, "transportation_class_id" varchar(30) not null, "src" varchar(100) not null, "created_at" varchar(100) not null, "updated_at" timestamptz not null, constraint "transportation_class_image_pkey" primary key ("id"));`,
);
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 "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 "transportation_class" add constraint "transportation_class_transportation_id_foreign" foreign key ("transportation_id") references "transportation" ("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_makkah_hotel_id_foreign" foreign key ("makkah_hotel_id") references "hotel" ("id") on update cascade;`,
);
this.addSql(
`alter table "package_detail" add constraint "package_detail_madinah_hotel_id_foreign" foreign key ("madinah_hotel_id") references "hotel" ("id") on update 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_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_detail_tour_flight_classes" add constraint "package_detail_tour_flight_classes_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_flight_classes" add constraint "package_detail_tour_flight_classes_flight_class_id_foreign" foreign key ("flight_class_id") references "flight_class" ("id") on update cascade on delete cascade;`,
);
this.addSql(
`alter table "package_detail_outbound_flight_classes" add constraint "package_detail_outbound_flight_classes_package_d_8b70d_foreign" foreign key ("package_detail_id") references "package_detail" ("id") on update cascade on delete cascade;`,
);
this.addSql(
`alter table "package_detail_outbound_flight_classes" add constraint "package_detail_outbound_flight_classes_flight_class_id_foreign" foreign key ("flight_class_id") references "flight_class" ("id") on update cascade on delete cascade;`,
);
this.addSql(
`alter table "package_detail_inbound_flight_classes" add constraint "package_detail_inbound_flight_classes_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_inbound_flight_classes" add constraint "package_detail_inbound_flight_classes_flight_class_id_foreign" foreign key ("flight_class_id") references "flight_class" ("id") on update cascade on delete cascade;`,
);
this.addSql(
`alter table "transportation_class_image" add constraint "transportation_class_image_transportation_class_id_foreign" foreign key ("transportation_class_id") references "transportation_class" ("id") on update cascade;`,
);
}
override async down(): Promise<void> {
this.addSql(
`alter table "flight" drop constraint "flight_airline_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 "package_detail_tour_flight_classes" drop constraint "package_detail_tour_flight_classes_flight_class_id_foreign";`,
);
this.addSql(
`alter table "package_detail_outbound_flight_classes" drop constraint "package_detail_outbound_flight_classes_flight_class_id_foreign";`,
);
this.addSql(
`alter table "package_detail_inbound_flight_classes" drop constraint "package_detail_inbound_flight_classes_flight_class_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_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_detail" drop constraint "package_detail_package_id_foreign";`,
);
this.addSql(
`alter table "transportation_class" drop constraint "transportation_class_transportation_id_foreign";`,
);
this.addSql(
`alter table "package_detail" drop constraint "package_detail_transportation_id_foreign";`,
);
this.addSql(
`alter table "transportation_class_image" drop constraint "transportation_class_image_transportation_class_id_foreign";`,
);
this.addSql(
`alter table "package_detail_tour_hotels" drop constraint "package_detail_tour_hotels_package_detail_id_foreign";`,
);
this.addSql(
`alter table "package_detail_tour_flight_classes" drop constraint "package_detail_tour_flight_classes_package_detail_id_foreign";`,
);
this.addSql(
`alter table "package_detail_outbound_flight_classes" drop constraint "package_detail_outbound_flight_classes_package_d_8b70d_foreign";`,
);
this.addSql(
`alter table "package_detail_inbound_flight_classes" drop constraint "package_detail_inbound_flight_classes_package_detail_id_foreign";`,
);
this.addSql(`drop table if exists "airline" 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 "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" cascade;`);
this.addSql(`drop table if exists "transportation" cascade;`);
this.addSql(`drop table if exists "transportation_class" 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_detail_tour_flight_classes" cascade;`,
);
this.addSql(
`drop table if exists "package_detail_outbound_flight_classes" cascade;`,
);
this.addSql(
`drop table if exists "package_detail_inbound_flight_classes" cascade;`,
);
this.addSql(`drop table if exists "transportation_class_image" cascade;`);
}
}

12
src/database/orm.ts Normal file
View File

@@ -0,0 +1,12 @@
import { databaseConfig } from "@/configs/database.config";
import { MikroORM } from "@mikro-orm/postgresql";
export const orm = await MikroORM.init({
host: databaseConfig.host,
port: databaseConfig.port,
user: databaseConfig.username,
password: databaseConfig.password,
dbName: databaseConfig.name,
entities: ["src/database/entities/*.entity.ts"],
entitiesTs: ["src/database/entities/*.entity.ts"],
});

View File

@@ -1,3 +1,5 @@
import "reflect-metadata";
import { Application } from "@/application";
process.on("uncaughtException", (err) => {