feat: add world travel database schema
This commit is contained in:
51
apps/api/src/world/entities/location-connection.entity.ts
Normal file
51
apps/api/src/world/entities/location-connection.entity.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
Index,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { LocationDefinition } from './location-definition.entity';
|
||||
|
||||
@Entity({ name: 'location_connections' })
|
||||
@Index(
|
||||
'IDX_location_connection_direction',
|
||||
['fromLocationId', 'toLocationId'],
|
||||
{
|
||||
unique: true,
|
||||
},
|
||||
)
|
||||
export class LocationConnection {
|
||||
@PrimaryGeneratedColumn('uuid', { name: 'id' })
|
||||
id!: string;
|
||||
|
||||
@Column({ name: 'from_location_id', type: 'uuid' })
|
||||
fromLocationId!: string;
|
||||
|
||||
@Column({ name: 'to_location_id', type: 'uuid' })
|
||||
toLocationId!: string;
|
||||
|
||||
@Column({ name: 'travel_duration_seconds', type: 'integer' })
|
||||
travelDurationSeconds!: number;
|
||||
|
||||
@Column({ name: 'ambush_chance', type: 'numeric', precision: 5, scale: 4 })
|
||||
ambushChance!: string;
|
||||
|
||||
@Column({ name: 'enabled', type: 'boolean' })
|
||||
enabled!: boolean;
|
||||
|
||||
@ManyToOne(
|
||||
() => LocationDefinition,
|
||||
(location) => location.outgoingConnections,
|
||||
)
|
||||
@JoinColumn({ name: 'from_location_id' })
|
||||
fromLocation!: LocationDefinition;
|
||||
|
||||
@ManyToOne(
|
||||
() => LocationDefinition,
|
||||
(location) => location.incomingConnections,
|
||||
)
|
||||
@JoinColumn({ name: 'to_location_id' })
|
||||
toLocation!: LocationDefinition;
|
||||
}
|
||||
63
apps/api/src/world/entities/location-definition.entity.ts
Normal file
63
apps/api/src/world/entities/location-definition.entity.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { Character } from '../../characters/entities/character.entity';
|
||||
import { LocationConnection } from './location-connection.entity';
|
||||
|
||||
@Entity({ name: 'location_definitions' })
|
||||
@Index('IDX_location_definitions_key', ['key'], { unique: true })
|
||||
export class LocationDefinition {
|
||||
@PrimaryGeneratedColumn('uuid', { name: 'id' })
|
||||
id!: string;
|
||||
|
||||
@Column({ name: 'key', type: 'varchar', length: 100 })
|
||||
key!: string;
|
||||
|
||||
@Column({ name: 'name', type: 'varchar', length: 150 })
|
||||
name!: string;
|
||||
|
||||
@Column({ name: 'description', type: 'text' })
|
||||
description!: string;
|
||||
|
||||
@Column({ name: 'region_key', type: 'varchar', length: 100 })
|
||||
regionKey!: string;
|
||||
|
||||
@Column({ name: 'min_recommended_level', type: 'integer' })
|
||||
minRecommendedLevel!: number;
|
||||
|
||||
@Column({ name: 'max_recommended_level', type: 'integer' })
|
||||
maxRecommendedLevel!: number;
|
||||
|
||||
@Column({ name: 'danger_level', type: 'integer' })
|
||||
dangerLevel!: number;
|
||||
|
||||
@Column({ name: 'is_safe', type: 'boolean' })
|
||||
isSafe!: boolean;
|
||||
|
||||
@Column({ name: 'hunting_enabled', type: 'boolean' })
|
||||
huntingEnabled!: boolean;
|
||||
|
||||
@Column({ name: 'artwork_path', type: 'varchar', length: 255 })
|
||||
artworkPath!: string;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
||||
updatedAt!: Date;
|
||||
|
||||
@OneToMany(() => Character, (character) => character.currentLocation)
|
||||
characters!: Character[];
|
||||
|
||||
@OneToMany(() => LocationConnection, (connection) => connection.fromLocation)
|
||||
outgoingConnections!: LocationConnection[];
|
||||
|
||||
@OneToMany(() => LocationConnection, (connection) => connection.toLocation)
|
||||
incomingConnections!: LocationConnection[];
|
||||
}
|
||||
Reference in New Issue
Block a user