@happyvertical/smrt-core 0.51.29 → 0.51.30

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.
@@ -1,5 +1,5 @@
1
1
  import { ColumnDefinition, SchemaChange, SchemaDefinition, SchemaDiff, SQLDataType } from '../schema/types.js';
2
- import { DatabaseInterface } from './types.js';
2
+ import { DatabaseInterface, SqlTableSchemaInfo } from './types.js';
3
3
  /**
4
4
  * `mismatch.actual` of the manual change reported when a required column
5
5
  * could not be added to a populated table (#3008): the column is absent.
@@ -66,6 +66,15 @@ export interface DiffOptions {
66
66
  postgresTimestampMigration?: {
67
67
  legacyTimezone: 'UTC';
68
68
  };
69
+ /**
70
+ * How many live-table introspections `compare()` runs concurrently while
71
+ * prefetching every existing manifest table's schema. Defaults to
72
+ * {@link POSTGRES_INTROSPECTION_CONCURRENCY} on PostgreSQL (each
73
+ * `getTableSchema()` is several catalog round trips, so a wide schema over a
74
+ * high-latency link is otherwise dominated by sequential RTTs) and to 1 —
75
+ * the original sequential behavior — on every other engine.
76
+ */
77
+ introspectionConcurrency?: number;
69
78
  }
70
79
  /**
71
80
  * Name of the unique index that backs a `unique: true` column. Mirrors the
@@ -186,6 +195,16 @@ export declare class SchemaComparer {
186
195
  * needed because nothing survives past one `compare()` call).
187
196
  */
188
197
  private renameDataPendingCache;
198
+ /**
199
+ * Partial-index predicates for every `public` table, read in one catalog
200
+ * query per `compare()` run instead of one `pg_indexes` query per table.
201
+ * Same lifetime as {@link renameDataPendingCache}: set inside `compare()`,
202
+ * cleared in its `finally`. `null` means "not precomputed" (standalone
203
+ * `compareTable()`, a non-PostgreSQL engine, or the batched read failed),
204
+ * in which case {@link getDbIndexPredicates} falls back to the per-table
205
+ * query.
206
+ */
207
+ private indexPredicateCache;
189
208
  /**
190
209
  * Cross-table batch queries stay bounded regardless of schema shape: this
191
210
  * caps how many scalar-subquery columns one probe statement packs into a
@@ -217,6 +236,29 @@ export declare class SchemaComparer {
217
236
  * introspect it.
218
237
  */
219
238
  private getLiveSchema;
239
+ /**
240
+ * The live table schemas read by the most recent `compare()` run, keyed by
241
+ * table name. Lets a caller that runs further read-only diagnostics over
242
+ * the same connection in the same command (e.g. `smrt db:status`'s orphan
243
+ * report) reuse them instead of re-introspecting every table. Entries are
244
+ * successful reads only (`getTableSchema()` failures propagate out of
245
+ * `compare()`); `null`/`undefined` mean the adapter reported no table.
246
+ */
247
+ getLiveSchemaSnapshot(): ReadonlyMap<string, SqlTableSchemaInfo | null | undefined>;
248
+ /**
249
+ * Memoize several tables' live schemas with bounded concurrency. Same
250
+ * reads, same failure behavior as calling {@link getLiveSchema} for each
251
+ * in turn (the first failure rejects), but PostgreSQL keeps up to
252
+ * `introspectionConcurrency` introspections in flight on the pool.
253
+ */
254
+ private prefetchLiveSchemas;
255
+ /**
256
+ * Read every `public` table's partial-index predicates in one query
257
+ * (PostgreSQL only). On failure the cache stays `null` and
258
+ * {@link getDbIndexPredicates} keeps its per-table behavior, including its
259
+ * own fallback to predicate-unaware comparison.
260
+ */
261
+ private precomputeIndexPredicates;
220
262
  /**
221
263
  * Plan the pre-R11 `text` -> `uuid` convergence (#2608).
222
264
  *
@@ -1 +1 @@
1
- {"version":3,"file":"differ.d.ts","sourceRoot":"","sources":["../../src/migrations/differ.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAmCH,OAAO,KAAK,EAEV,gBAAgB,EAEhB,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAoB5B,OAAO,KAAK,EAAE,iBAAiB,EAAsB,MAAM,YAAY,CAAC;AAIxE;;;GAGG;AACH,eAAO,MAAM,yBAAyB,uBAAuB,CAAC;AA4B9D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;OAOG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,EAAE,CAIzD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,MAAM,EAAE,CAU5E"}
@@ -4,6 +4,7 @@ import { foreignKeyConstraintName, foreignKeyRelationshipKey, renderForeignKeyAd
4
4
  import { renderNullEqualConflictIndex } from "../schema/ddl/null-equal-index.js";
5
5
  import { detectEngine, getDDLStrategy } from "../schema/ddl/index.js";
6
6
  import { conflictIndexName } from "../schema/conflict-target.js";
7
+ import { mapWithConcurrency } from "../schema/bounded-concurrency.js";
7
8
  import { columnsAllValuesUuidShapedBatch, columnsHaveNonEmptyValueBatch, nonEmptyValuePredicate, resolveRenameDataPendingCandidates, uuidInvalidShapePredicate } from "../schema/column-data-probes.js";
8
9
  import { maskSampleValue, probeCastSafety, renderJsonbColumnConversion, renderTimestamptzColumnConversion } from "../schema/text-cast-probe.js";
9
10
  import { describeForeignKeyTypeConflict, planUuidConvergence, renderUuidConvergenceRepairHint, renderUuidShapeProbe } from "../schema/uuid-convergence.js";
@@ -348,6 +349,16 @@ var SchemaComparer = class SchemaComparer {
348
349
  */
349
350
  renameDataPendingCache = null;
350
351
  /**
352
+ * Partial-index predicates for every `public` table, read in one catalog
353
+ * query per `compare()` run instead of one `pg_indexes` query per table.
354
+ * Same lifetime as {@link renameDataPendingCache}: set inside `compare()`,
355
+ * cleared in its `finally`. `null` means "not precomputed" (standalone
356
+ * `compareTable()`, a non-PostgreSQL engine, or the batched read failed),
357
+ * in which case {@link getDbIndexPredicates} falls back to the per-table
358
+ * query.
359
+ */
360
+ indexPredicateCache = null;
361
+ /**
351
362
  * Cross-table batch queries stay bounded regardless of schema shape: this
352
363
  * caps how many scalar-subquery columns one probe statement packs into a
353
364
  * single row. Conservative relative to PostgreSQL's ~1600 column limit
@@ -387,8 +398,11 @@ var SchemaComparer = class SchemaComparer {
387
398
  };
388
399
  this.liveSchemas.clear();
389
400
  this.renameDataPendingCache = null;
401
+ this.indexPredicateCache = null;
390
402
  try {
391
403
  const existingTables = await this.getExistingTables();
404
+ await this.prefetchLiveSchemas(Object.keys(manifestSchemas).filter((tableName) => existingTables.has(tableName)));
405
+ await this.precomputeIndexPredicates();
392
406
  await this.precomputeRenameDataPending(manifestSchemas, existingTables);
393
407
  this.uuidConvergence = await this.buildUuidConvergencePlan(manifestSchemas, existingTables);
394
408
  for (const change of this.uuidConvergenceChanges(manifestSchemas)) {
@@ -419,6 +433,7 @@ var SchemaComparer = class SchemaComparer {
419
433
  return diff;
420
434
  } finally {
421
435
  this.renameDataPendingCache = null;
436
+ this.indexPredicateCache = null;
422
437
  }
423
438
  }
424
439
  /**
@@ -504,6 +519,59 @@ var SchemaComparer = class SchemaComparer {
504
519
  return schema ?? void 0;
505
520
  }
506
521
  /**
522
+ * The live table schemas read by the most recent `compare()` run, keyed by
523
+ * table name. Lets a caller that runs further read-only diagnostics over
524
+ * the same connection in the same command (e.g. `smrt db:status`'s orphan
525
+ * report) reuse them instead of re-introspecting every table. Entries are
526
+ * successful reads only (`getTableSchema()` failures propagate out of
527
+ * `compare()`); `null`/`undefined` mean the adapter reported no table.
528
+ */
529
+ getLiveSchemaSnapshot() {
530
+ return new Map(this.liveSchemas);
531
+ }
532
+ /**
533
+ * Memoize several tables' live schemas with bounded concurrency. Same
534
+ * reads, same failure behavior as calling {@link getLiveSchema} for each
535
+ * in turn (the first failure rejects), but PostgreSQL keeps up to
536
+ * `introspectionConcurrency` introspections in flight on the pool.
537
+ */
538
+ async prefetchLiveSchemas(tableNames) {
539
+ if (typeof this.db.getTableSchema !== "function") return;
540
+ const pending = tableNames.filter((tableName) => !this.liveSchemas.has(tableName));
541
+ const schemas = await mapWithConcurrency(pending, this.options.introspectionConcurrency ?? (this.engine === "postgres" ? 8 : 1), (tableName) => Promise.resolve(this.db.getTableSchema?.(tableName)));
542
+ pending.forEach((tableName, index) => {
543
+ this.liveSchemas.set(tableName, schemas[index]);
544
+ });
545
+ }
546
+ /**
547
+ * Read every `public` table's partial-index predicates in one query
548
+ * (PostgreSQL only). On failure the cache stays `null` and
549
+ * {@link getDbIndexPredicates} keeps its per-table behavior, including its
550
+ * own fallback to predicate-unaware comparison.
551
+ */
552
+ async precomputeIndexPredicates() {
553
+ this.indexPredicateCache = null;
554
+ if (this.engine !== "postgres") return;
555
+ try {
556
+ const result = await this.db.query(`SELECT tablename, indexname, indexdef FROM pg_indexes WHERE schemaname = 'public'`);
557
+ const cache = /* @__PURE__ */ new Map();
558
+ for (const row of result.rows) {
559
+ if (!row.tablename || !row.indexname || !row.indexdef) continue;
560
+ const predicate = extractIndexPredicate(row.indexdef);
561
+ if (!predicate) continue;
562
+ let predicates = cache.get(row.tablename);
563
+ if (!predicates) {
564
+ predicates = /* @__PURE__ */ new Map();
565
+ cache.set(row.tablename, predicates);
566
+ }
567
+ predicates.set(row.indexname, predicate);
568
+ }
569
+ this.indexPredicateCache = cache;
570
+ } catch (err) {
571
+ logger.debug("[SchemaComparer] Batched partial-index predicate introspection failed; falling back to per-table reads", { error: err instanceof Error ? err.message : String(err) });
572
+ }
573
+ }
574
+ /**
507
575
  * Plan the pre-R11 `text` -> `uuid` convergence (#2608).
508
576
  *
509
577
  * PostgreSQL only: SQLite stores UUIDs as text by design and DuckDB cannot
@@ -2036,6 +2104,7 @@ var SchemaComparer = class SchemaComparer {
2036
2104
  */
2037
2105
  async getDbIndexPredicates(tableName) {
2038
2106
  if (!this.supportsPartialIndexes()) return null;
2107
+ if (this.engine === "postgres" && this.indexPredicateCache) return new Map(this.indexPredicateCache.get(tableName) ?? []);
2039
2108
  const predicates = /* @__PURE__ */ new Map();
2040
2109
  try {
2041
2110
  if (this.engine === "postgres") {