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