setup database, entities, and migrations
This commit is contained in:
53
src/database/entities/airport.entity.ts
Normal file
53
src/database/entities/airport.entity.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user