@voltro/database 0.78.0 → 0.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sql.d.ts CHANGED
@@ -603,6 +603,12 @@ declare interface ChangeStreamGap {
603
603
  readonly downForMs?: number;
604
604
  }
605
605
 
606
+ /** A live table's columns that carry a character set, with it. */
607
+ export declare const charsetColumnsOf: (table: TableSnapshot) => ReadonlyArray<{
608
+ readonly column: string;
609
+ readonly charset: string;
610
+ }>;
611
+
606
612
  /** Partition into ≤`n`-sized chunks (disjoint, complete). Exported for the
607
613
  * batching regression test — the introspection's correctness reduces to this
608
614
  * producing a complete, non-overlapping partition of the table list. */
@@ -1685,6 +1691,25 @@ export declare interface ColumnSnapshot {
1685
1691
  * blocks a masking export until classified.
1686
1692
  */
1687
1693
  readonly safe?: boolean;
1694
+ /**
1695
+ * The character set a STRING column is stored in — MySQL / MariaDB only, and
1696
+ * only on columns the engine gives one (text, varchar, enum; never json,
1697
+ * which is `utf8mb4` on MariaDB and charset-less on MySQL by construction,
1698
+ * and never a number, a date or bytes).
1699
+ *
1700
+ * Live side: what `information_schema.columns.character_set_name` reports.
1701
+ * Declared side: the store's declared charset (`store: { dialect, charset }`
1702
+ * in `app.config.ts`), stamped on every string column — ABSENT when the app
1703
+ * declares none. The planner compares it only when BOTH sides carry one, so
1704
+ * an undeclared app never plans a conversion; and the fingerprint never
1705
+ * hashes it, because a live reading against an absent declaration would part
1706
+ * every table's two hashes forever. `storeCharset.ts` carries the reason.
1707
+ *
1708
+ * A `string`, not `MysqlCharset`: the reader reports whatever the column is
1709
+ * in (`latin1` is real), and a conversion FROM it is exactly what the
1710
+ * declaration is for. Only the declared side is limited to the two.
1711
+ */
1712
+ readonly charset?: string;
1688
1713
  /**
1689
1714
  * Type PARAMETERS for the three `ColumnType`s whose DDL is not determined by
1690
1715
  * the type tag alone — `vector(n)`, `array(of)`, `enum(name, values)`.
@@ -1724,10 +1749,39 @@ export declare interface ColumnSnapshot {
1724
1749
  };
1725
1750
  }
1726
1751
 
1752
+ /**
1753
+ * Does the declared column render a STRING type on the mysql family — the
1754
+ * columns a declared charset is stamped on? Mirrors `sqlType(_, 'mariadb')`:
1755
+ * text (LONGTEXT / VARCHAR / TEXT), enum (`ENUM(...)`), a typeid/ulid `id`
1756
+ * (VARCHAR(64)) and a text-stored `reference` (VARCHAR(64)). A numeric id or
1757
+ * reference is BIGINT; json / array are JSON; bytes is LONGBLOB — none carry a
1758
+ * character set. `raw` is the user's own DDL, which the framework does not
1759
+ * read, so it is left alone on both sides.
1760
+ */
1761
+ export declare const columnTakesCharset: (col: Pick<ColumnSnapshot, "type" | "idScheme" | "idStorage" | "referenceStorage">) => boolean;
1762
+
1727
1763
  declare type ColumnType = 'id' | 'text' | 'integer' | 'real' | 'decimal' | 'bigint' | 'boolean' | 'timestamp' | 'date' | 'json' | 'bytes' | 'reference' | 'vector' | 'enum' | 'array' | 'interval' | 'raw';
1728
1764
 
1729
1765
  declare type ColumnType_2 = 'id' | 'text' | 'integer' | 'real' | 'decimal' | 'bigint' | 'boolean' | 'timestamp' | 'date' | 'json' | 'bytes' | 'reference' | 'vector' | 'enum' | 'array' | 'interval' | 'raw';
1730
1766
 
1767
+ /** A live foreign key a charset conversion has to carry across the rewrite. */
1768
+ export declare interface ConvertCharsetForeignKey {
1769
+ /** Catalog name of the constraint. */
1770
+ readonly name: string;
1771
+ /** The child (referencing) side. */
1772
+ readonly table: string;
1773
+ readonly column: string;
1774
+ readonly targetTable: string;
1775
+ readonly targetColumn: string;
1776
+ readonly onDelete?: 'cascade' | 'restrict' | 'setNull' | 'noAction';
1777
+ readonly onUpdate?: 'cascade' | 'restrict' | 'setNull' | 'noAction';
1778
+ /** Which operation re-creates it after the rewrite: this table's, or the
1779
+ * other endpoint's (`'peer'` — that table converts in the same plan and
1780
+ * sorts after this one). Dropping is done by whichever runs first; both
1781
+ * tolerate an already-absent constraint. */
1782
+ readonly restore: 'here' | 'peer';
1783
+ }
1784
+
1731
1785
  /** The tables a plan CREATEs — the set every same-plan operation is checked against. */
1732
1786
  export declare const createdTablesOf: (operations: ReadonlyArray<PlannedOperation>) => ReadonlySet<string>;
1733
1787
 
@@ -2260,13 +2314,24 @@ declare interface DataStore {
2260
2314
  storedTables?(): ReadonlyArray<StoredTableShape>;
2261
2315
  }
2262
2316
 
2317
+ export declare const declaredSnapshot: (tables: ReadonlyArray<TableLike>, dialect?: DialectId, options?: DeclaredSnapshotOptions) => SchemaSnapshot;
2318
+
2263
2319
  /**
2264
2320
  * Build a `SchemaSnapshot` from an array of `TableLike` declarations.
2265
2321
  * Caller is responsible for passing the FULL set of tables (user-
2266
2322
  * declared + framework). The fingerprint over this snapshot is what the
2267
2323
  * boot-time prod check compares against `_voltro_migration_plans`.
2268
2324
  */
2269
- export declare const declaredSnapshot: (tables: ReadonlyArray<TableLike>, dialect?: DialectId) => SchemaSnapshot;
2325
+ export declare interface DeclaredSnapshotOptions {
2326
+ /**
2327
+ * The store's declared character set (`store: { dialect, charset }`) —
2328
+ * stamped on every string column so the planner can compare it with what the
2329
+ * database reports. MySQL / MariaDB only: on any other dialect a charset is a
2330
+ * configuration error and is refused here rather than ignored, so a
2331
+ * declaration that cannot take effect never reads as one that did.
2332
+ */
2333
+ readonly charset?: MysqlCharset | undefined;
2334
+ }
2270
2335
 
2271
2336
  /** The NOTIFY channel a schema emits on when none is configured. */
2272
2337
  export declare const DEFAULT_CDC_CHANNEL = "framework_changes";
@@ -2325,6 +2390,9 @@ export declare const describeOutcome: (outcome: BootMigrationOutcome, dialectId:
2325
2390
  /** `bf_links`, `bf_links.ticket_key` — the spelling a message uses. */
2326
2391
  export declare const describeProbe: (probe: SchemaProbe) => string;
2327
2392
 
2393
+ /** One line per finding, for the CLI and the doctor. */
2394
+ export declare const describeStoreCharsetFinding: (f: StoreCharsetFinding) => string;
2395
+
2328
2396
  /**
2329
2397
  * Parse `VOLTRO_DESTRUCTIVE_OK`.
2330
2398
  *
@@ -2535,6 +2603,31 @@ export declare const emitAddIndexMysql: (op: Extract<MigrationOperation, {
2535
2603
  kind: "add-index";
2536
2604
  }>, declared: ReadonlyArray<TableLike>, engine?: MysqlEngine) => string;
2537
2605
 
2606
+ /**
2607
+ * The statements of a `convert-charset` operation, in order:
2608
+ *
2609
+ * 1. drop every foreign key that touches the table (either end) — the
2610
+ * engines refuse to change the charset of a column a constraint holds;
2611
+ * 2. ONE `ALTER TABLE` that MODIFYs each declared string column to its
2612
+ * declared definition plus `CHARACTER SET`, and sets the table default —
2613
+ * a single rewrite, not one per column, and never the json columns;
2614
+ * 3. re-create the constraints this operation owns (`restore: 'here'`); the
2615
+ * ones between two converting tables come back with the later table.
2616
+ *
2617
+ * Every column is rendered from the DECLARATION (`emitModifyColumnMysql` is
2618
+ * the same renderer the type and nullability operations use), because MODIFY
2619
+ * redefines the column and the declaration is the shape the plan converges
2620
+ * to. A generated column keeps its expression — MODIFY without it would drop
2621
+ * the generation.
2622
+ */
2623
+ export declare const emitConvertCharsetMysql: (op: Extract<MigrationOperation, {
2624
+ kind: "convert-charset";
2625
+ }>, declared: ReadonlyArray<TableLike>) => {
2626
+ readonly drops: ReadonlyArray<string>;
2627
+ readonly rewrite: string;
2628
+ readonly restores: ReadonlyArray<string>;
2629
+ };
2630
+
2538
2631
  export declare const emitCreateTableMssql: (op: Extract<MigrationOperation, {
2539
2632
  kind: "create-table";
2540
2633
  }>) => ReadonlyArray<string>;
@@ -2613,7 +2706,7 @@ cdcChannel?: string) => string;
2613
2706
  * containers are a deliberate non-goal (each tenant namespace is
2614
2707
  * self-contained for its own tables).
2615
2708
  */
2616
- export declare const emitNamespacedSchemaSql: (tables: ReadonlyArray<AnyTable>, dialect: DialectId, namespace: string, sqliteFile?: string) => string;
2709
+ export declare const emitNamespacedSchemaSql: (tables: ReadonlyArray<AnyTable>, dialect: DialectId, namespace: string, sqliteFile?: string, options?: SchemaEmitOptions) => string;
2617
2710
 
2618
2711
  /**
2619
2712
  * DDL that creates a tenant's namespace CONTAINER, per dialect:
@@ -2629,12 +2722,17 @@ export declare const emitNamespacedSchemaSql: (tables: ReadonlyArray<AnyTable>,
2629
2722
  * errors if the alias is already attached, which the migrator treats as
2630
2723
  * "already provisioned".
2631
2724
  */
2632
- export declare const emitNamespaceProvisionDdl: (namespace: string, dialect: DialectId, sqliteFile?: string) => string;
2725
+ export declare const emitNamespaceProvisionDdl: (namespace: string, dialect: DialectId, sqliteFile?: string,
2726
+ /** The declared store charset (mysql family) — the new database's default,
2727
+ * so its tables inherit the declaration rather than the server default.
2728
+ * `IF NOT EXISTS` leaves an existing database's default alone (measured on
2729
+ * both engines); the tables' own column charsets still land. */
2730
+ charset?: MysqlCharset) => string;
2633
2731
 
2634
2732
  export declare const emitSchemaSql: (entities: ReadonlyArray<AnyTable | AnyView>, dialect: DialectId,
2635
2733
  /** NOTIFY channel for the reactive triggers. Must match the store's
2636
2734
  * `cdcChannel`, or writes emit where nothing is listening. */
2637
- cdcChannel?: string) => string;
2735
+ cdcChannel?: string, options?: SchemaEmitOptions) => string;
2638
2736
 
2639
2737
  declare type EmptyMerge = unknown;
2640
2738
 
@@ -3315,6 +3413,8 @@ export declare const isAlreadySatisfied: (err: unknown, rules: ReadonlyArray<Alr
3315
3413
  /** Type-guard for the discovery walker. */
3316
3414
  export declare const isFileMigration: (value: unknown) => value is FileMigration;
3317
3415
 
3416
+ export declare const isMysqlCharset: (value: unknown) => value is MysqlCharset;
3417
+
3318
3418
  /** Type guard — narrows an unknown value to a {@link RawSqlFragment}. */
3319
3419
  export declare const isRawSqlFragment: (value: unknown) => value is RawSqlFragment;
3320
3420
 
@@ -3643,6 +3743,30 @@ export declare type MigrationOperation = {
3643
3743
  readonly validation: 'value' | 'container';
3644
3744
  readonly previousValidation: 'value' | 'container' | 'unverified' | 'absent';
3645
3745
  readonly dropConstraints: ReadonlyArray<string>;
3746
+ }
3747
+ /**
3748
+ * Bring every string column of ONE table to the declared character set —
3749
+ * MySQL / MariaDB only. A table REWRITE: each named column is `MODIFY`ed to
3750
+ * its declared definition plus `CHARACTER SET`, and the table's default is
3751
+ * set so a later `ADD COLUMN` inherits it. json columns are never in
3752
+ * `columns` (their charset is the engine's, not the declaration's).
3753
+ *
3754
+ * `foreignKeys` are the constraints that touch this table — either end —
3755
+ * because neither engine changes the character set of a column a foreign
3756
+ * key holds (MariaDB 1832/1833, MySQL 3780). Each is dropped before the
3757
+ * rewrite and re-created after it; `restore` says which endpoint's operation
3758
+ * re-creates it, so a constraint between two converting tables comes back
3759
+ * only once both sides are at the target (the later of the two, by name).
3760
+ */
3761
+ | {
3762
+ readonly kind: 'convert-charset';
3763
+ readonly table: string;
3764
+ readonly charset: MysqlCharset;
3765
+ /** The string columns to rewrite, in declaration order. */
3766
+ readonly columns: ReadonlyArray<string>;
3767
+ /** The character sets those columns are in today (for the plan line). */
3768
+ readonly from: ReadonlyArray<string>;
3769
+ readonly foreignKeys: ReadonlyArray<ConvertCharsetForeignKey>;
3646
3770
  };
3647
3771
 
3648
3772
  /**
@@ -3881,6 +4005,16 @@ declare interface MixinIndex {
3881
4005
  readonly kindOptions?: IndexKindOptions;
3882
4006
  }
3883
4007
 
4008
+ export declare const MYSQL_CHARSETS: ReadonlyArray<MysqlCharset>;
4009
+
4010
+ /**
4011
+ * The character sets a store can declare for its string columns on MySQL /
4012
+ * MariaDB. `utf8mb4` holds every Unicode scalar; `utf8mb3` (the engines' old
4013
+ * `utf8`) stops at three bytes and refuses emoji and most supplementary-plane
4014
+ * characters with errno 1366.
4015
+ */
4016
+ export declare type MysqlCharset = 'utf8mb3' | 'utf8mb4';
4017
+
3884
4018
  /** Which engine a `mysql`-dialect connection is actually talking to. */
3885
4019
  export declare type MysqlEngine = 'mysql' | 'mariadb';
3886
4020
 
@@ -3903,6 +4037,11 @@ export declare type MysqlEngine = 'mysql' | 'mariadb';
3903
4037
  */
3904
4038
  export declare const mysqlIndexPrefixFor: (col: ColumnSnapshot | undefined) => number | undefined;
3905
4039
 
4040
+ export declare interface NamespaceCharsetReport {
4041
+ readonly namespace: string;
4042
+ readonly findings: ReadonlyArray<StoreCharsetFinding>;
4043
+ }
4044
+
3906
4045
  /**
3907
4046
  * Type-narrowing migration marker. Tells the planner that this column
3908
4047
  * previously had type `from` and is now being narrowed/converted to its
@@ -4128,6 +4267,16 @@ export declare interface PlanInput {
4128
4267
  * CLI populates it from `VOLTRO_DB_IGNORE_TABLES` (comma-separated names).
4129
4268
  */
4130
4269
  readonly ignoreTables?: ReadonlyArray<string>;
4270
+ /**
4271
+ * The store's declared character set — `store: { dialect, charset }` in
4272
+ * `app.config.ts`. MySQL / MariaDB only; `declaredSnapshot` refuses it for
4273
+ * any other dialect. Declared, every table the app declares is CREATED with
4274
+ * it and, when a live table's string columns are stored otherwise, CONVERTED
4275
+ * to it (`convert-charset`, a table rewrite that carries the table's foreign
4276
+ * keys across). Absent, nothing is planned about character sets — see
4277
+ * `storeCharset.ts` for why that is the default and what is reported instead.
4278
+ */
4279
+ readonly charset?: MysqlCharset | undefined;
4131
4280
  }
4132
4281
 
4133
4282
  /**
@@ -5280,6 +5429,9 @@ export declare interface RunPlannedMigrationsCtx {
5280
5429
  /** How long a soft-drop snapshot may sit before the boot warns about it
5281
5430
  * (`database.softDropRetentionDays`; default 7). */
5282
5431
  readonly softDropRetentionDays?: number;
5432
+ /** The store's declared character set (`store: { dialect, charset }`),
5433
+ * MySQL / MariaDB only — threaded into every plan this boot computes. */
5434
+ readonly charset?: MysqlCharset | undefined;
5283
5435
  }
5284
5436
 
5285
5437
  /**
@@ -5295,6 +5447,9 @@ export declare interface RunPlannedMigrationsCtx {
5295
5447
  */
5296
5448
  export declare const runSchemaOp: (sql: SqlClient.SqlClient, op: MigrationSchemaOp, live: SchemaSnapshot) => Effect.Effect<void, SqlError_2>;
5297
5449
 
5450
+ /** Runs one Effect over the connection — the shape `ManagedRuntime.runPromise` and a store's `run` share. */
5451
+ export declare type RunSql = <A>(effect: Effect.Effect<A, SqlError_2, SqlClient.SqlClient>) => Promise<A>;
5452
+
5298
5453
  /**
5299
5454
  * Effect that applies the emitted DDL to the provided SqlClient. Splits
5300
5455
  * on `;` only outside dollar-quoted blocks (the postgres NOTIFY trigger
@@ -5320,11 +5475,22 @@ export declare const runSchemaOp: (sql: SqlClient.SqlClient, op: MigrationSchema
5320
5475
  * absent → `DB_SCHEMA` from the environment, the same configuration the
5321
5476
  * connection's `search_path` pin reads.
5322
5477
  */
5323
- export declare interface SchemaApplyOptions {
5478
+ export declare interface SchemaApplyOptions extends SchemaEmitOptions {
5324
5479
  readonly retryFilter?: (error: unknown) => RetryDecision;
5325
5480
  readonly lockSchema?: string;
5326
5481
  }
5327
5482
 
5483
+ export declare interface SchemaEmitOptions {
5484
+ /**
5485
+ * The store's declared character set — MySQL / MariaDB only. Every CREATE
5486
+ * TABLE carries it as the table default, so the bring-up path creates the
5487
+ * same tables the planner's `create-table` does. Refused for any other
5488
+ * dialect (a declaration that cannot take effect must not read as one that
5489
+ * did).
5490
+ */
5491
+ readonly charset?: MysqlCharset | undefined;
5492
+ }
5493
+
5328
5494
  /** What a schema operation on the migration context found to do. */
5329
5495
  export declare type SchemaOpOutcome = 'applied' | 'already-absent' | 'already-present';
5330
5496
 
@@ -5518,6 +5684,57 @@ export declare interface SquashResult {
5518
5684
  readonly snapshotId: string;
5519
5685
  }
5520
5686
 
5687
+ /** The declared snapshot's tables with the store charset stamped on every string column. */
5688
+ export declare const stampDeclaredCharset: (tables: ReadonlyArray<TableSnapshot>, charset: MysqlCharset) => ReadonlyArray<TableSnapshot>;
5689
+
5690
+ /**
5691
+ * What to do about the findings, once. Names the real config field and the
5692
+ * command that applies it; nothing here is an env var.
5693
+ */
5694
+ export declare const STORE_CHARSET_REMEDY: string;
5695
+
5696
+ /**
5697
+ * One table the store's character set is wrong about.
5698
+ *
5699
+ * - `disagrees-with-declaration` — the app declares a charset and these
5700
+ * columns are stored in another one. The plan carries the conversion; the
5701
+ * doctor names it for the operator who has not run `voltro db plan`.
5702
+ * - `json-outruns-text` — no declaration, and the table has a json column
5703
+ * (which holds every Unicode character on both engines) next to string
5704
+ * columns that do not. The reported symptom, as a line.
5705
+ * - `mixed` — no declaration, no json, and the table's string columns are not
5706
+ * all in one charset: a column converted by hand, or a column added under a
5707
+ * different database default. Two columns of one declaration disagree about
5708
+ * what a string is.
5709
+ */
5710
+ export declare interface StoreCharsetFinding {
5711
+ readonly table: string;
5712
+ readonly kind: 'disagrees-with-declaration' | 'json-outruns-text' | 'mixed';
5713
+ /** The columns that are not where they should be, with the charset they are in. */
5714
+ readonly columns: ReadonlyArray<{
5715
+ readonly column: string;
5716
+ readonly charset: string;
5717
+ }>;
5718
+ /** What the finding measures against: the declaration, or `utf8mb4` for json. */
5719
+ readonly expected: string;
5720
+ }
5721
+
5722
+ /**
5723
+ * The tables whose string columns cannot hold what they should. Pure — over a
5724
+ * live snapshot the caller has already read — so `voltro db plan`, `voltro
5725
+ * doctor` and a test can ask the same question of the same reading.
5726
+ *
5727
+ * Zero findings on a healthy database is the contract: a `utf8mb4` database
5728
+ * with no declaration reports nothing, and so does any database whose every
5729
+ * string column matches its declaration. Measured against both engines in
5730
+ * `storeCharset.integration.test.ts`.
5731
+ */
5732
+ export declare const storeCharsetFindings: (input: {
5733
+ readonly live: SchemaSnapshot;
5734
+ readonly dialect: DialectId;
5735
+ readonly charset?: MysqlCharset | undefined;
5736
+ }) => ReadonlyArray<StoreCharsetFinding>;
5737
+
5521
5738
  /** One table as a store that has no catalog can describe it. See {@link DataStore.storedTables}. */
5522
5739
  declare interface StoredTableShape {
5523
5740
  /** The table's name, unqualified by any namespace the reporting view is bound to. */
@@ -6159,6 +6376,20 @@ declare interface TableUnique {
6159
6376
  };
6160
6377
  }
6161
6378
 
6379
+ /**
6380
+ * The tenant databases whose string columns are stored otherwise than the
6381
+ * declaration — or, undeclared, otherwise than their json columns. Only the
6382
+ * charset facts are read (type kind, charset), which is all the question
6383
+ * needs; a full introspection per tenant would be a catalog scan per tenant.
6384
+ *
6385
+ * Empty on a server with no tenant database, and empty when every tenant
6386
+ * agrees. Namespaces come out sorted.
6387
+ */
6388
+ export declare const tenantNamespaceCharsetFindings: (run: RunSql, options: {
6389
+ readonly charset?: MysqlCharset | undefined;
6390
+ readonly dialect?: "mysql" | "mariadb";
6391
+ }) => Promise<ReadonlyArray<NamespaceCharsetReport>>;
6392
+
6162
6393
  /**
6163
6394
  * A `transactional` migration whose body committed the transaction from
6164
6395
  * inside — DDL on the MySQL family, or an explicit COMMIT. The body's work