mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
5f17a5df50
The repositories typed their Kysely statements against 159 table interfaces written by hand, one or more per repository. Nothing compared them with the schema: a migration that renamed a column or changed its type left them stale while tsc stayed green, and several had already drifted (reservations.accommodation_id is TEXT, not INTEGER). scripts/generate-db-types.ts migrates a throwaway database with the real migrations, reads every table back and writes one interface per table into src/db/kysely/ plus the DB map in db.ts. Every hand-written interface is now Pick<DB, ...> of that type, and npm run check:db-types fails when the committed files no longer match the migrations. A column an insert may leave out (rowid, DEFAULT, nullable) is InsertOptional<T>, declared as ColumnType<T, T | void, T>. The server compiles without strictNullChecks, where Kysely's own Generated<T> still demands the column; that is why the old code kept separate insert-only interfaces. The ids callers pass as number | string are cast to the column type at the bind, so every statement binds the same value as before.
22 lines
780 B
TypeScript
22 lines
780 B
TypeScript
// Generated by scripts/generate-db-types.ts from the migrated schema. Do not edit by hand:
|
|
// change the migration, then run `npm run gen:db-types`.
|
|
|
|
import type { InsertOptional } from './columns';
|
|
|
|
export interface PackingItemsTable {
|
|
id: InsertOptional<number>;
|
|
trip_id: number;
|
|
name: string;
|
|
checked: InsertOptional<number | null>;
|
|
category: InsertOptional<string | null>;
|
|
sort_order: InsertOptional<number | null>;
|
|
created_at: InsertOptional<string | null>;
|
|
weight_grams: InsertOptional<number | null>;
|
|
bag_id: InsertOptional<number | null>;
|
|
quantity: InsertOptional<number>;
|
|
updated_at: InsertOptional<string | null>;
|
|
is_private: InsertOptional<number>;
|
|
owner_id: InsertOptional<number | null>;
|
|
packed_quantity: InsertOptional<number | null>;
|
|
}
|