Feature/305 kysely swap #306
@@ -24,7 +24,7 @@ const SCHEMA = readFileSync(
|
|||||||
*/
|
*/
|
||||||
function mirroredTables(): string[] {
|
function mirroredTables(): string[] {
|
||||||
const block = /export interface DB \{([^}]*)\}/.exec(SCHEMA)?.[1] ?? '';
|
const block = /export interface DB \{([^}]*)\}/.exec(SCHEMA)?.[1] ?? '';
|
||||||
return [...block.matchAll(/^\s*([a-z_]+):/gm)].map((m) => m[1]!).sort();
|
return [...block.matchAll(/^\s*([a-z0-9_]+):/gm)].map((m) => m[1]!).sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function liveTables(): Promise<string[]> {
|
async function liveTables(): Promise<string[]> {
|
||||||
@@ -40,17 +40,21 @@ async function liveTables(): Promise<string[]> {
|
|||||||
/**
|
/**
|
||||||
* The guard for #217.
|
* The guard for #217.
|
||||||
*
|
*
|
||||||
* `src/db-drizzle/schema.ts` is generated by `drizzle-kit pull` and is a
|
* `src/db-kysely/schema.ts` is generated by `npm run db:types` and is a
|
||||||
* read-only mirror of the real schema, which `backend/migrations` owns. Nothing
|
* read-only mirror of the real schema, which `backend/migrations` owns. Nothing
|
||||||
* makes anyone re-pull after writing a migration, and that is not hypothetical:
|
* makes anyone regenerate after writing a migration, and that is not
|
||||||
* the mirror sat missing `item_drafts` and `upload_links` from the moment #222
|
* hypothetical: the mirror sat missing `item_drafts` and `upload_links` from
|
||||||
* landed until #217, because it had been copied into src/ by hand and nobody
|
* the moment #222 landed until #217, because it had been copied into src/ by
|
||||||
* had reason to look at it.
|
* hand and nobody had reason to look at it.
|
||||||
*
|
*
|
||||||
* A stale mirror is worse than no mirror. Drizzle infers row types from it, so
|
* A stale mirror is worse than no mirror. Row types are inferred from it, so a
|
||||||
* a converted query would type-check against a schema the database does not
|
* converted query would type-check against a schema the database does not have
|
||||||
* have and fail at run time with a column that does not exist — the exact class
|
* and fail at run time with a column that does not exist — the exact class of
|
||||||
* of drift the adoption was meant to close.
|
* drift the adoption was meant to close.
|
||||||
|
*
|
||||||
|
* The generator changed in #305 and this test did not, because the drift it
|
||||||
|
* guards is a property of generating a mirror at all rather than of any
|
||||||
|
* library.
|
||||||
*/
|
*/
|
||||||
describe('the generated schema mirror', () => {
|
describe('the generated schema mirror', () => {
|
||||||
it('declares every table the migrations create', async () => {
|
it('declares every table the migrations create', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user