uql-orm 0.101.5 → 0.102.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.
Files changed (37) hide show
  1. package/dist/dialect/abstractSqlDialect.d.ts +12 -3
  2. package/dist/dialect/abstractSqlDialect.js +24 -14
  3. package/dist/dialect/mysqlLikeSqlDialect.d.ts +2 -2
  4. package/dist/dialect/mysqlLikeSqlDialect.js +5 -2
  5. package/dist/dialect/pgLikeSqlDialect.js +1 -0
  6. package/dist/libsql/libsqlDialect.d.ts +5 -0
  7. package/dist/libsql/libsqlDialect.js +5 -0
  8. package/dist/migrate/builder/migrationBuilder.js +1 -1
  9. package/dist/migrate/builder/tableBuilder.js +9 -4
  10. package/dist/migrate/builder/types.d.ts +5 -1
  11. package/dist/migrate/generator/definitionToNode.d.ts +7 -4
  12. package/dist/migrate/generator/definitionToNode.js +12 -13
  13. package/dist/migrate/schemaGenerator.js +1 -1
  14. package/dist/mongodb/mongoDialect.js +1 -0
  15. package/dist/mongodb/mongoIntrospector.js +3 -2
  16. package/dist/mongodb/mongoSchemaGenerator.js +8 -8
  17. package/dist/mssql/mssqlDialect.d.ts +4 -4
  18. package/dist/mssql/mssqlDialect.js +7 -4
  19. package/dist/querier/abstractQuerier.d.ts +52 -17
  20. package/dist/querier/abstractQuerier.js +140 -79
  21. package/dist/querier/abstractSqlQuerier.d.ts +5 -1
  22. package/dist/querier/abstractSqlQuerier.js +16 -1
  23. package/dist/schema/indexDifferences.d.ts +5 -4
  24. package/dist/schema/indexDifferences.js +23 -12
  25. package/dist/schema/schemaASTBuilder.js +3 -3
  26. package/dist/sqlite/hranaQuerier.d.ts +2 -2
  27. package/dist/sqlite/hranaQuerier.js +2 -2
  28. package/dist/sqlite/sqliteDialect.d.ts +4 -3
  29. package/dist/sqlite/sqliteDialect.js +5 -1
  30. package/dist/type/dialect.d.ts +6 -0
  31. package/dist/type/querier.d.ts +6 -0
  32. package/dist/util/ddlExpression.util.d.ts +8 -2
  33. package/dist/util/ddlExpression.util.js +6 -3
  34. package/dist/util/sql.util.d.ts +7 -2
  35. package/dist/util/sql.util.js +16 -3
  36. package/package.json +1 -1
  37. package/skills/uql-orm/SKILL.md +3 -3
@@ -1,6 +1,6 @@
1
1
  import { indexDistance, isVectorIndexType } from '../type/vector.js';
2
2
  import { fulltextConfig } from '../util/dialect.util.js';
3
- import { derivedIndexName } from '../util/sql.util.js';
3
+ import { isDerivedIndexName } from '../util/sql.util.js';
4
4
  import { isColumnEntry } from './indexColumns.js';
5
5
  import { matchByKey } from './matchByKey.js';
6
6
  /**
@@ -25,12 +25,24 @@ export function indexNameStem(name) {
25
25
  }
26
26
  /**
27
27
  * Pairs by name, then what is left by shape: an index the database has under another name is still
28
- * the one asked for. What stays unpaired is created or dropped.
28
+ * the one asked for. A partial index pairs by name alone, since its predicate is in its name.
29
29
  */
30
30
  export function pairIndexes(source, target) {
31
31
  const byName = matchByKey(source, target, (index) => indexNameStem(index.name));
32
- const byShape = matchByKey(byName.created, byName.dropped, indexSignature);
33
- return { created: byShape.created, dropped: byShape.dropped, matched: [...byName.matched, ...byShape.matched] };
32
+ const created = splitPartial(byName.created);
33
+ const dropped = splitPartial(byName.dropped);
34
+ const byShape = matchByKey(created.plain, dropped.plain, indexSignature);
35
+ return {
36
+ created: [...created.partial, ...byShape.created],
37
+ dropped: [...dropped.partial, ...byShape.dropped],
38
+ matched: [...byName.matched, ...byShape.matched],
39
+ };
40
+ }
41
+ function splitPartial(indexes) {
42
+ return {
43
+ plain: indexes.filter((index) => index.where === undefined),
44
+ partial: indexes.filter((index) => index.where !== undefined),
45
+ };
34
46
  }
35
47
  /**
36
48
  * The indexes a table lacks, the ones it no longer needs, and the ones to rebuild, differing in what
@@ -56,12 +68,7 @@ export function indexChanges(table, declared, current, facets) {
56
68
  */
57
69
  function hasDerivedName(table, index) {
58
70
  const parts = index.entries.map((entry, at) => (isColumnEntry(entry) ? entry.column : `expr${at}`));
59
- const derived = [
60
- derivedIndexName(table, parts),
61
- derivedIndexName(table, parts, true),
62
- `idx_${table}_${parts.join('_')}`,
63
- ];
64
- return derived.includes(index.name);
71
+ return isDerivedIndexName(table, parts, index.name);
65
72
  }
66
73
  /** What this version emits. */
67
74
  const KIND_SUFFIX = /_(?:idx|fk|ck|pk|uk|uq)$/i;
@@ -72,8 +79,9 @@ const KIND_SUFFIX = /_(?:idx|fk|ck|pk|uk|uq)$/i;
72
79
  */
73
80
  const KIND_PREFIX = /^(?:idx|fk|ck|pk|uk|uq)_/i;
74
81
  /**
75
- * What two indexes differ by, comparing only what both sides state structurally: an expression, a JSON
76
- * path or a predicate is reprinted by the engine, so never compared.
82
+ * What two indexes differ by, comparing only what both sides state structurally. An expression or a JSON
83
+ * path is reprinted by the engine, so never compared; a predicate only by whether there is one, its text
84
+ * being in an unnamed index's name.
77
85
  */
78
86
  export function describeIndexDifferences(source, target, facets) {
79
87
  const differences = [];
@@ -90,6 +98,9 @@ export function describeIndexDifferences(source, target, facets) {
90
98
  differences.push(`config: ${actual} -> ${expected}`);
91
99
  }
92
100
  }
101
+ if ((source.where === undefined) !== (target.where === undefined)) {
102
+ differences.push(`predicate: ${target.where ?? 'none'} -> ${source.where ?? 'none'}`);
103
+ }
93
104
  if (source.unique !== target.unique) {
94
105
  differences.push(`unique: ${target.unique} -> ${source.unique}`);
95
106
  }
@@ -184,16 +184,16 @@ function addCompositeIndex(ctx, table, meta, { columns, include, where, ...optio
184
184
  });
185
185
  if (!resolved.length)
186
186
  return;
187
- const name = declaredIndexName(options.name, table.name, resolved);
187
+ const predicate = where && ctx.compileIndexPredicate(where, meta.entity, declaredIndexName(options.name, table.name, resolved));
188
188
  ctx.ast.addIndex({
189
189
  ...options,
190
- name,
190
+ name: declaredIndexName(options.name, table.name, resolved, { where: predicate }),
191
191
  table,
192
192
  entries: resolved.map((entry) => renderIndexColumn(entry, (sql) => ctx.compileDdl(sql, meta.entity))),
193
193
  // An `include` column is named like any other, so a custom naming has to reach it too.
194
194
  include: include?.map((column) => fieldColumn(ctx, meta, column) ?? column),
195
195
  unique: options.unique ?? false,
196
- where: where && ctx.compileIndexPredicate(where, meta.entity, name),
196
+ where: predicate,
197
197
  });
198
198
  if (ctx.textScoreIndexes) {
199
199
  addTextScoreIndexes(ctx, table, options.type, resolved);
@@ -1,4 +1,4 @@
1
- import type { ExtraOptions, RawRow } from '../type/index.js';
1
+ import type { ExtraOptions, RawRow, TransactionOptions } from '../type/index.js';
2
2
  import { AbstractSqliteQuerier, type SqliteBindValue } from './abstractSqliteQuerier.js';
3
3
  import type { SqliteDialect } from './sqliteDialect.js';
4
4
  export type HranaInValue = SqliteBindValue | ArrayBuffer | Date;
@@ -47,7 +47,7 @@ export declare class HranaQuerier extends AbstractSqliteQuerier {
47
47
  rows: RawRow[];
48
48
  changes: number;
49
49
  }>;
50
- protected internalBegin(): Promise<void>;
50
+ protected internalBegin(opts?: TransactionOptions): Promise<void>;
51
51
  /**
52
52
  * Both drop the handle before the call, not after: one that outlived a failed commit would carry
53
53
  * every later statement into a transaction the server may already have ended.
@@ -21,8 +21,8 @@ export class HranaQuerier extends AbstractSqliteQuerier {
21
21
  const res = await (this.tx ?? this.client).execute({ sql: query, args: values });
22
22
  return { rows: res.rows, changes: res.rowsAffected };
23
23
  }
24
- async internalBegin() {
25
- this.tx = await this.client.transaction('write');
24
+ async internalBegin(opts) {
25
+ this.tx = await this.client.transaction(opts?.readOnly ? 'read' : 'write');
26
26
  }
27
27
  /**
28
28
  * Both drop the handle before the call, not after: one that outlived a failed commit would carry
@@ -1,6 +1,6 @@
1
1
  import { AbstractSqlDialect, type DerivedRelation, type RelationRows, type SelectTerm } from '../dialect/abstractSqlDialect.js';
2
2
  import { type JsonAccessMode, type JsonSlot } from '../dialect/jsonSql.js';
3
- import { type EntityMeta, type FieldOptions, type Query, type QueryContext, type QueryTextSearchOptions, type QueryWhere, type SqlDialectFeatures, type SqlValues, type VectorDistance, type VectorMetric } from '../type/index.js';
3
+ import { type EntityMeta, type FieldOptions, type Query, type QueryContext, type QueryTextSearchOptions, type QueryWhere, type SqlDialectFeatures, type SqlValues, type VectorDistance, type VectorMetric, type TransactionOptions } from '../type/index.js';
4
4
  /** What SQLite and the engines derived from it have. */
5
5
  export declare const SQLITE_FEATURES: SqlDialectFeatures;
6
6
  export declare class SqliteDialect extends AbstractSqlDialect {
@@ -8,8 +8,9 @@ export declare class SqliteDialect extends AbstractSqlDialect {
8
8
  readonly dialectName = "sqlite";
9
9
  readonly escapeIdChar = "`";
10
10
  readonly autoIncrementSuffix = "PRIMARY KEY AUTOINCREMENT";
11
- readonly beginTransactionCommand = "BEGIN TRANSACTION";
12
- readonly isolationLevelStrategy = "none";
11
+ readonly beginTransactionCommand: string;
12
+ /** No level to set: SQLite serializes writers. A read-only transaction defers its lock to its first write. */
13
+ getBeginTransactionStatements({ readOnly }?: TransactionOptions): string[];
13
14
  readonly booleanLiteral = "integer";
14
15
  /**
15
16
  * The clock and today in the same text as a bound `Date`, where `CURRENT_TIMESTAMP` writes whole seconds and
@@ -31,6 +31,7 @@ export const SQLITE_FEATURES = {
31
31
  serverSideCursors: false,
32
32
  correlatedWrites: true,
33
33
  rowLocks: false,
34
+ writeReturning: true,
34
35
  nullsSortLowest: true,
35
36
  nullsOrdering: 'clause',
36
37
  textScoreIndexes: false,
@@ -56,7 +57,10 @@ export class SqliteDialect extends AbstractSqlDialect {
56
57
  escapeIdChar = '`';
57
58
  autoIncrementSuffix = 'PRIMARY KEY AUTOINCREMENT';
58
59
  beginTransactionCommand = 'BEGIN TRANSACTION';
59
- isolationLevelStrategy = 'none';
60
+ /** No level to set: SQLite serializes writers. A read-only transaction defers its lock to its first write. */
61
+ getBeginTransactionStatements({ readOnly } = {}) {
62
+ return [readOnly ? 'BEGIN DEFERRED' : this.beginTransactionCommand];
63
+ }
60
64
  booleanLiteral = 'integer';
61
65
  /**
62
66
  * The clock and today in the same text as a bound `Date`, where `CURRENT_TIMESTAMP` writes whole seconds and
@@ -134,6 +134,12 @@ export interface DialectFeatures {
134
134
  * such a write reads the ids of the rows it names first.
135
135
  */
136
136
  readonly correlatedWrites: boolean;
137
+ /**
138
+ * Whether an `UPDATE` and a `DELETE` report the rows they wrote (`RETURNING`), so a write `returning` them
139
+ * in one statement reads them off it: the Postgres and SQLite families. MariaDB returns from a `DELETE`
140
+ * only, and SQL Server's `OUTPUT` fails on a table with a trigger, so both read their rows first.
141
+ */
142
+ readonly writeReturning: boolean;
137
143
  /**
138
144
  * What the engine's row locks can do, or `false` where it has none: the SQLite family locks the
139
145
  * database and MongoDB has no row lock at all, so both refuse `$lock` rather than ignoring it. One
@@ -21,6 +21,12 @@ export type TransactionOptions = {
21
21
  * failed start leaves it on the connection: set it per transaction that needs it.
22
22
  */
23
23
  readonly isolationLevel?: IsolationLevel;
24
+ /**
25
+ * A transaction that only reads, so the engine refuses its writes where it has the mode (Postgres,
26
+ * CockroachDB, MySQL, MariaDB, libSQL's client), and the SQLite family takes no write lock for it.
27
+ * SQL Server and MongoDB have no such mode and ignore it.
28
+ */
29
+ readonly readOnly?: boolean;
24
30
  };
25
31
  export type DialectName = SqlDialectName | 'mongodb';
26
32
  /**
@@ -15,8 +15,14 @@ export declare function declaredIndexes<E>(meta: EntityMeta<E>): EntityIndexMeta
15
15
  export declare function renderIndexColumn(entry: EntityIndexColumn, render: (statement: QuerySql) => string): IndexColumnSchema;
16
16
  /** What an unnamed index's name is built from: each entry's column, or `expr<n>` for an expression, which has none. */
17
17
  export declare function indexNameParts(entries: readonly EntityIndexColumn[]): string[];
18
- /** The name an index is created and read by: its own, else one derived from its table, entries' columns and uniqueness. */
19
- export declare function declaredIndexName(name: string | undefined, table: string, entries: readonly EntityIndexColumn[], unique?: boolean): string;
18
+ /**
19
+ * The name an index is created and read by: its own, else one derived from its table, entries, uniqueness and
20
+ * rendered predicate. A caller renders the predicate first, since an unnamed partial index's name carries its hash.
21
+ */
22
+ export declare function declaredIndexName(name: string | undefined, table: string, entries: readonly EntityIndexColumn[], { unique, where }?: {
23
+ readonly unique?: boolean;
24
+ readonly where?: string;
25
+ }): string;
20
26
  /**
21
27
  * A check as uql installs it: named for its table and `label`, the author's name or `ck`, then a hash
22
28
  * of `expression`, so an edited check is a new name and reordering the checks renames none.
@@ -36,9 +36,12 @@ export function renderIndexColumn(entry, render) {
36
36
  export function indexNameParts(entries) {
37
37
  return entries.map((entry, at) => (typeof entry.column === 'string' ? entry.column : `expr${at}`));
38
38
  }
39
- /** The name an index is created and read by: its own, else one derived from its table, entries' columns and uniqueness. */
40
- export function declaredIndexName(name, table, entries, unique = false) {
41
- return name ?? derivedIndexName(table, indexNameParts(entries), unique);
39
+ /**
40
+ * The name an index is created and read by: its own, else one derived from its table, entries, uniqueness and
41
+ * rendered predicate. A caller renders the predicate first, since an unnamed partial index's name carries its hash.
42
+ */
43
+ export function declaredIndexName(name, table, entries, { unique = false, where } = {}) {
44
+ return name ?? derivedIndexName(table, indexNameParts(entries), unique, where);
42
45
  }
43
46
  /**
44
47
  * A check as uql installs it: named for its table and `label`, the author's name or `ck`, then a hash
@@ -26,9 +26,14 @@ export declare function isOwnedName(name: string): boolean;
26
26
  export declare function ownedName(table: string, label: string, content: string): string;
27
27
  /**
28
28
  * The name a derived index gets when nothing named it: `Order__total_idx`, or `Order__total_uk` for a
29
- * unique one - which the builder has always spelled apart, and which reads as what it enforces.
29
+ * unique one. A partial index also carries a hash of its `where`, so an edited predicate is a new name.
30
30
  */
31
- export declare function derivedIndexName(table: string, columns: readonly string[], unique?: boolean): string;
31
+ export declare function derivedIndexName(table: string, columns: readonly string[], unique?: boolean, where?: string): string;
32
+ /**
33
+ * Whether uql named the index `name` itself from `columns`: `derivedIndexName`'s forms, with a predicate's hash or
34
+ * without, and the `idx_<table>_<columns>` spelling an older uql gave one.
35
+ */
36
+ export declare function isDerivedIndexName(table: string, columns: readonly string[], name: string): boolean;
32
37
  /**
33
38
  * The constraint name a primary key gets when we name one: `Enrolment__studentId_courseId_pk`.
34
39
  *
@@ -68,10 +68,23 @@ function hashIdentifier(value) {
68
68
  }
69
69
  /**
70
70
  * The name a derived index gets when nothing named it: `Order__total_idx`, or `Order__total_uk` for a
71
- * unique one - which the builder has always spelled apart, and which reads as what it enforces.
71
+ * unique one. A partial index also carries a hash of its `where`, so an edited predicate is a new name.
72
72
  */
73
- export function derivedIndexName(table, columns, unique = false) {
74
- return derivedConstraintName(table, columns, unique ? 'uk' : 'idx');
73
+ export function derivedIndexName(table, columns, unique = false, where) {
74
+ const parts = where === undefined ? columns : [...columns, hashIdentifier(where)];
75
+ return derivedConstraintName(table, parts, unique ? 'uk' : 'idx');
76
+ }
77
+ /** The hash a partial index's derived name carries before its kind. */
78
+ const PREDICATE_HASH = new RegExp(`_[0-9a-f]{${NAME_HASH_LENGTH}}(?=_(?:idx|uk)$)`);
79
+ /**
80
+ * Whether uql named the index `name` itself from `columns`: `derivedIndexName`'s forms, with a predicate's hash or
81
+ * without, and the `idx_<table>_<columns>` spelling an older uql gave one.
82
+ */
83
+ export function isDerivedIndexName(table, columns, name) {
84
+ const plain = [derivedIndexName(table, columns), derivedIndexName(table, columns, true)];
85
+ return (plain.includes(name) ||
86
+ plain.includes(name.replace(PREDICATE_HASH, '')) ||
87
+ name === `idx_${table}_${columns.join('_')}`);
75
88
  }
76
89
  /**
77
90
  * The constraint name a primary key gets when we name one: `Enrolment__studentId_courseId_pk`.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "homepage": "https://uql-orm.dev",
4
4
  "description": "JSON-native TypeScript ORM for Bun, Browsers, Edge, Node, Workers. Supports PostgreSQL, PGlite, MySQL, MariaDB, SQLite, CockroachDB, SQL Server, Turso, Neon, Cloudflare D1 and MongoDB. Queries are plain JSON, typed to the leaf.",
5
5
  "license": "MIT",
6
- "version": "0.101.5",
6
+ "version": "0.102.0",
7
7
  "type": "module",
8
8
  "engines": {
9
9
  "node": ">=22.18"
@@ -116,7 +116,7 @@ const users = await pool.findMany(User, {
116
116
  - A query is plain data, so it can be built dynamically, stored, or sent from a browser to `uql-orm/http`, whose handler serves only the entities its required `include` names.
117
117
  - Methods: `findMany`, `findOne`, `findOneById`, `findManyAndCount`, `findManyPage`, `findManyStream`, `count`, `exists`, `aggregate`, `insertOne`, `insertMany`, `updateOneById`, `updateMany`, `saveOne`, `saveMany`, `upsertOne`, `upsertMany`, `deleteOneById`, `deleteMany`. Each takes the entity class first.
118
118
  - `upsertOne(Entity, { email: true }, row, update?)`: a conflicting row takes `update`, an update's payload with its operators (`{ uses: { $inc: 1 } }`), instead of `row`; a new one inserts `row`. An empty `{}` leaves a conflicting row as it is: insert if absent. Cascaded relations write on either branch, a found row's replaced, as `updateMany` does. It resolves to the row's id.
119
- - Every write takes `{ returning: { id: true, createdAt: true } }` as its last argument and then resolves to those rows (an update or delete by id: the row or `undefined`), read back in the same transaction; without it, inserts, saves and upserts resolve to ids, updates and deletes to a count.
119
+ - Every write takes `{ returning: { id: true, createdAt: true } }` as its last argument and then resolves to those rows (an update or delete by id: the row or `undefined`), read back in the same transaction; without it, inserts, saves and upserts resolve to ids, updates and deletes to a count. An update or delete writes exactly the rows it reports: on Postgres, CockroachDB and the SQLite family a plain one is a single statement whose `RETURNING` reports them; elsewhere, or paged, through a relation, versioned, or with hooks or cascades on a delete, it reads them first in a transaction that holds them, so a racing writer waits for the commit (SQLite and MongoDB fail it with a retryable error instead).
120
120
  - `updateMany` and `deleteMany` naming no rows - no `$where` holding a value (an empty group holds none), no `$limit` - throw; `{ unfiltered: true }` means the whole table.
121
121
  - An update takes `{ stock: { $inc: -1 } }` to add, or `$mul` to multiply, in the statement, a NULL counting as 0, so a guard in `$where` (`stock: { $gte: 1 }`) makes a decrement race-safe. On SQL the step may be a ref or `sql` of the field's type (`{ total: { $inc: newRow.amount } }` in a trigger). JSON fields take `$set`, `$unset`, `$push`, `$pull`.
122
122
  - `$lock: true` locks the rows a read returns (`{ $wait: 'skip' | 'nowait' }` says what to do about a row someone else holds) and needs an open transaction; SQLite, libSQL, Turso, D1 and MongoDB have no row lock and refuse it.
@@ -134,7 +134,7 @@ await pool.transaction(async (querier) => {
134
134
  });
135
135
  ```
136
136
 
137
- The callback commits when it returns and rolls back when it throws; `beginTransaction` / `commitTransaction` / `rollbackTransaction` are for a transaction that opens in one place and ends in another. Inside the callback, a `pool` call runs on the callback's querier, so it is part of the transaction. A `transaction()` inside another is a savepoint, whose failure undoes its own writes alone (MongoDB, with none, refuses it). A transaction holds its connection: a statement from outside its callback waits for it. `querier.onCommit(fn)` (or a hook's `onCommit`) runs `fn` after the outermost commit, never on a rollback: use it for mails and queued jobs. A querier from `pool.getQuerier()` is yours to release: bind it with `await using`.
137
+ The callback commits when it returns and rolls back when it throws; `beginTransaction` / `commitTransaction` / `rollbackTransaction` are for a transaction that opens in one place and ends in another. Inside the callback, a `pool` call runs on the callback's querier, so it is part of the transaction. A `transaction()` inside another is a savepoint, whose failure undoes its own writes alone (MongoDB, with none, refuses it). A transaction holds its connection: a statement from outside its callback waits for it. `{ readOnly: true }` opens a transaction that only reads: Postgres, CockroachDB, MySQL and MariaDB refuse its writes, and libSQL and Turso skip the write lock they otherwise take at `BEGIN`. `querier.onCommit(fn)` (or a hook's `onCommit`) runs `fn` after the outermost commit, never on a rollback: use it for mails and queued jobs. A querier from `pool.getQuerier()` is yours to release: bind it with `await using`.
138
138
 
139
139
  A `findManyStream` holds its querier until the loop ends, which refuses any other statement meanwhile: inside the loop, run them on another connection; inside a transaction, or on SQLite and PGlite (one shared connection), run them after the loop. That includes an `@AfterLoad` querying through its `querier` on a streamed row. A statement binding more values than the engine takes (100 on D1, 2098 on SQL Server) is refused too: split a long `$in`.
140
140
 
@@ -146,7 +146,7 @@ A `findManyStream` holds its querier until the loop ends, which refuses any othe
146
146
  - `generate:entities` writes the diff as a migration file to review. It renames a column a naming strategy spells otherwise (`firstName` to `first_name`); any other renamed column is a drop and an add it warns about, with the `renameColumn(table, from, to)` to write instead. It refuses a required column with no default on a table holding rows.
147
147
  - `up` and `down` apply and revert migrations, each in its own transaction, holding a lock so concurrent instances run each migration once. From code, `await new Migrator(pool, { migrationsPath }).up()` before the app starts: it rejects with the first failing migration's error, the ones before it applied. `down()` reverts the last one; `down({ step: Infinity })` every one.
148
148
  - `generate:from-db` writes entity classes from an existing database.
149
- - `drift:check` fails when the database no longer matches.
149
+ - `drift:check` fails when the database no longer matches. An unnamed partial index carries a hash of its `where` in its name, so editing the predicate replaces it; a named one's predicate is compared only by whether it is there. An index expression and a stored computed column's expression are not compared, so changing one is written by hand in the migration.
150
150
  - `sync --dry-run` prints only SQL on stdout, to append to a migration file another tool applies: on Cloudflare D1, wrangler's (https://uql-orm.dev/cloudflare-d1.md).
151
151
 
152
152
  Checks, an enum's included, and triggers are part of the diff: uql owns the `_uql_`-prefixed ones and never touches another. On MongoDB, checks and enums are the collection's validator, which uql owns whole, and a check fails a document lacking the field it compares.