/** * Shared SQLite catalog helpers used by both the Kysely-based introspector * (sqlite.ts) and the wrangler-based D1 introspector (d1.ts). * * All three routines are pure mappings of SQLite's declared type / pragma * values to canonical migrate-ts types and carry no I/O dependencies. */ import type { CheckDescriptor, ColumnDefault, FkAction, IndexDescriptor } from "../types.js"; import type { SqlType } from "../sql-type.js"; export declare const SQLITE_EXPR_DEFAULT_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp]; export declare function parseSqliteDefault(raw: string | null): ColumnDefault | undefined; export declare function sqliteTypeToSqlType(declaredType: string): SqlType; /** * Parse NAMED CHECK constraints (`CONSTRAINT CHECK ()`) out of a * table's CREATE TABLE statement (sqlite_master.sql). SQLite exposes no pragma * for CHECK constraints, so the stored DDL text is the only catalog. * * This is what makes CHECK evolution CONVERGE on sqlite: the diff proposes a * check change → the emitter recreate-and-copies the table with the new inline * CHECK → this reads the very DDL that recreate wrote, so the re-diff is empty. * Without it the actual side always reported `checks: []` and every expected * check re-surfaced as add-check on every single run. * * Unnamed inline checks (`CHECK (…)` with no CONSTRAINT clause — the idiomatic * hand-written-migration form) ARE parsed, with an empty name. They have no * identity to match by name, so the diff reconciles them by NORMALIZED EXPRESSION * on sqlite/d1: an anonymous DB check that already enforces a modeled constraint * is matched to the expected named check rather than re-proposed as add-check. * (Before, they were skipped entirely, so every modeled check over such a table * re-surfaced as false drift on `verify --dialect d1` on every run.) * * The expression is scanned with balanced parens and string-literal awareness * (an enum member may contain `(`/`)`), and returned verbatim — the diff's * checkExprEquals normalizes both sides before comparing. */ export declare function parseSqliteChecks(createSql: string | null | undefined): CheckDescriptor[]; export interface ParsedSqliteIndexDef { /** Raw key-list text between the balanced parens after `ON `. */ keyList: string; /** Raw partial-index predicate after WHERE; undefined for a full index. */ where?: string; } /** * Parse a stored `CREATE [UNIQUE] INDEX … ON
() [WHERE ]` * statement (sqlite_master.sql). SQLite has no pragma exposing an index's key * EXPRESSIONS or its partial-index predicate — the stored DDL is the only * catalog — so this powers reading `@expr` / `@where` indexes back for the diff * to converge. Quote-aware: parens inside string literals or quoted identifiers * never confuse the balanced scan. */ export declare function parseSqliteIndexDef(createSql: string | null | undefined): ParsedSqliteIndexDef | undefined; /** pragma_index_list row, dialect-neutrally coerced by the caller. */ export interface SqliteIndexListEntry { name: string; unique: boolean; partial: boolean; } /** A KEY column row from pragma_index_xinfo (key=1 rows only, seqno order). */ export interface SqliteIndexKeyColumn { /** Column name; null for an expression key (cid = -2). */ name: string | null; /** true when the key is sorted DESC. */ desc: boolean; } /** * Assemble an IndexDescriptor from the SQLite catalog pieces: pragma_index_list * (unique/partial), pragma_index_xinfo key columns (names + DESC bits; name null * for an expression key), and the stored CREATE INDEX DDL (expression key list + * partial predicate — neither is exposed by any pragma). * * Mirrors the expected side's shape rules: an expression index carries the whole * key list in `expr` with `columns: []`; `orders` is attached only when some key * is DESC (all-ascending serializes as absent, like buildExpectedSchema). */ export declare function buildSqliteIndexDescriptor(entry: SqliteIndexListEntry, keyColumns: readonly SqliteIndexKeyColumn[], createSql: string | null | undefined): IndexDescriptor; export declare function sqliteRuleToAction(rule: string): FkAction; //# sourceMappingURL=sqlite-shared.d.ts.map