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,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);
}