56 lines
2.4 KiB
TypeScript
56 lines
2.4 KiB
TypeScript
import { integer, real, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||
|
||
// Drizzle schema for the game state. Column names/types here are the source of
|
||
// truth; the matching CREATE TABLE statements live in lib/db/client.ts (DDL) and
|
||
// must stay in sync with this file.
|
||
|
||
export const planes = sqliteTable('planes', {
|
||
id: text('id').primaryKey().notNull(),
|
||
model: text('model').notNull(),
|
||
status: text('status', { enum: ['available', 'flying'] }).notNull(),
|
||
fuel: real('fuel').notNull(),
|
||
maxFuel: real('max_fuel').notNull(),
|
||
locationIcao: text('location_icao').notNull(),
|
||
contractId: text('contract_id'),
|
||
lat: real('lat').notNull(),
|
||
lon: real('lon').notNull(),
|
||
// Sim-clock departure time of the current flight (null when available). While
|
||
// flying, `fuel` is frozen at its departure value — live position/fuel are pure
|
||
// functions of the clock (lib/sim/movement.ts), recomputed on read.
|
||
departureSimTime: integer('departure_sim_time'),
|
||
});
|
||
|
||
export const contracts = sqliteTable('contracts', {
|
||
id: text('id').primaryKey().notNull(),
|
||
originIcao: text('origin_icao').notNull(),
|
||
destIcao: text('dest_icao').notNull(),
|
||
reward: real('reward').notNull(),
|
||
cargoType: text('cargo_type').notNull(),
|
||
cargoCount: integer('cargo_count').notNull(),
|
||
deadlineSimTime: integer('deadline_sim_time').notNull(),
|
||
// 'expired' = an open contract whose deadline passed (v0.7.0). Accepted/
|
||
// in-flight contracts never expire — they complete.
|
||
status: text('status', { enum: ['open', 'accepted', 'completed', 'expired'] }).notNull(),
|
||
planeId: text('plane_id'),
|
||
createdSimTime: integer('created_sim_time').notNull(),
|
||
});
|
||
|
||
export const account = sqliteTable('account', {
|
||
cash: real('cash').notNull(),
|
||
reputation: real('reputation').notNull(),
|
||
});
|
||
|
||
export const simState = sqliteTable('sim_state', {
|
||
clockMs: integer('clock_ms').notNull(),
|
||
timeScale: real('time_scale').notNull(),
|
||
paused: integer('paused', { mode: 'boolean' }).notNull(),
|
||
// Real-time (Date.now()) of the last tick — the tick-on-read engine advances
|
||
// clockMs by (now - lastRealTickMs) × timeScale, clamped per tick.
|
||
lastRealTickMs: integer('last_real_tick_ms').notNull(),
|
||
});
|
||
|
||
export type PlaneRow = typeof planes.$inferSelect;
|
||
export type ContractRow = typeof contracts.$inferSelect;
|
||
export type AccountRow = typeof account.$inferSelect;
|
||
export type SimStateRow = typeof simState.$inferSelect;
|