@malloy-publisher/server 0.0.239 → 0.0.240

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 (2) hide show
  1. package/dist/server.mjs +45 -26
  2. package/package.json +1 -1
package/dist/server.mjs CHANGED
@@ -276144,9 +276144,10 @@ class IncrementalLedgerRepository {
276144
276144
  constructor(db) {
276145
276145
  this.db = db;
276146
276146
  }
276147
- async get(environmentId, packageName, sourceEntityId) {
276147
+ async get(environmentId, connectionName, physicalTableName) {
276148
276148
  const row = await this.db.get(`SELECT * FROM incremental_ledger
276149
- WHERE environment_id = ? AND package_name = ? AND source_entity_id = ?`, [environmentId, packageName, sourceEntityId]);
276149
+ WHERE environment_id = ? AND connection_name = ?
276150
+ AND physical_table_name = ?`, [environmentId, connectionName, physicalTableName]);
276150
276151
  return row ? mapRow(row) : null;
276151
276152
  }
276152
276153
  async upsert(entry) {
@@ -276158,14 +276159,15 @@ class IncrementalLedgerRepository {
276158
276159
  physical_table_name, connection_name,
276159
276160
  advanced_by_materialization_id, advanced_at, created_at
276160
276161
  ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
276161
- ON CONFLICT (environment_id, package_name, source_entity_id) DO UPDATE SET
276162
+ ON CONFLICT (environment_id, connection_name, physical_table_name)
276163
+ DO UPDATE SET
276164
+ package_name = EXCLUDED.package_name,
276165
+ source_entity_id = EXCLUDED.source_entity_id,
276162
276166
  covered_through_value = EXCLUDED.covered_through_value,
276163
276167
  covered_through_type = EXCLUDED.covered_through_type,
276164
276168
  watermark_dimension = EXCLUDED.watermark_dimension,
276165
276169
  merge_key_dimensions = EXCLUDED.merge_key_dimensions,
276166
276170
  derived_strategy = EXCLUDED.derived_strategy,
276167
- physical_table_name = EXCLUDED.physical_table_name,
276168
- connection_name = EXCLUDED.connection_name,
276169
276171
  advanced_by_materialization_id = EXCLUDED.advanced_by_materialization_id,
276170
276172
  advanced_at = EXCLUDED.advanced_at
276171
276173
  RETURNING *`, [
@@ -276185,9 +276187,10 @@ class IncrementalLedgerRepository {
276185
276187
  ]);
276186
276188
  return mapRow(rows[0]);
276187
276189
  }
276188
- async deleteEntry(environmentId, packageName, sourceEntityId) {
276190
+ async deleteEntry(environmentId, connectionName, physicalTableName) {
276189
276191
  await this.db.run(`DELETE FROM incremental_ledger
276190
- WHERE environment_id = ? AND package_name = ? AND source_entity_id = ?`, [environmentId, packageName, sourceEntityId]);
276192
+ WHERE environment_id = ? AND connection_name = ?
276193
+ AND physical_table_name = ?`, [environmentId, connectionName, physicalTableName]);
276191
276194
  }
276192
276195
  async deleteByEnvironmentId(environmentId) {
276193
276196
  await this.db.run("DELETE FROM incremental_ledger WHERE environment_id = ?", [environmentId]);
@@ -276695,14 +276698,14 @@ class DuckDBRepository {
276695
276698
  async deleteMaterialization(id) {
276696
276699
  return this.materializationRepo.deleteById(id);
276697
276700
  }
276698
- async getIncrementalLedgerEntry(environmentId, packageName, sourceEntityId) {
276699
- return this.incrementalLedgerRepo.get(environmentId, packageName, sourceEntityId);
276701
+ async getIncrementalLedgerEntry(environmentId, connectionName, physicalTableName) {
276702
+ return this.incrementalLedgerRepo.get(environmentId, connectionName, physicalTableName);
276700
276703
  }
276701
276704
  async upsertIncrementalLedgerEntry(entry) {
276702
276705
  return this.incrementalLedgerRepo.upsert(entry);
276703
276706
  }
276704
- async deleteIncrementalLedgerEntry(environmentId, packageName, sourceEntityId) {
276705
- return this.incrementalLedgerRepo.deleteEntry(environmentId, packageName, sourceEntityId);
276707
+ async deleteIncrementalLedgerEntry(environmentId, connectionName, physicalTableName) {
276708
+ return this.incrementalLedgerRepo.deleteEntry(environmentId, connectionName, physicalTableName);
276706
276709
  }
276707
276710
  }
276708
276711
 
@@ -276717,6 +276720,7 @@ async function initializeSchema(db, force = false) {
276717
276720
  await dropLegacyProjectSchema(db);
276718
276721
  logger.info("Creating database schema for the first time...");
276719
276722
  }
276723
+ await dropPackageKeyedIncrementalLedger(db);
276720
276724
  await db.run(`
276721
276725
  CREATE TABLE IF NOT EXISTS environments (
276722
276726
  id VARCHAR PRIMARY KEY,
@@ -276800,7 +276804,7 @@ async function initializeSchema(db, force = false) {
276800
276804
  advanced_by_materialization_id VARCHAR,
276801
276805
  advanced_at TIMESTAMP NOT NULL,
276802
276806
  created_at TIMESTAMP NOT NULL,
276803
- PRIMARY KEY (environment_id, package_name, source_entity_id)
276807
+ PRIMARY KEY (environment_id, connection_name, physical_table_name)
276804
276808
  )
276805
276809
  `);
276806
276810
  await db.run(`
@@ -276819,6 +276823,19 @@ async function initializeSchema(db, force = false) {
276819
276823
  await db.run("CREATE UNIQUE INDEX IF NOT EXISTS idx_materializations_active_key ON materializations(active_key)");
276820
276824
  await db.run("CREATE INDEX IF NOT EXISTS idx_incremental_ledger_environment_package ON incremental_ledger(environment_id, package_name)");
276821
276825
  }
276826
+ async function dropPackageKeyedIncrementalLedger(db) {
276827
+ const present = await db.all("SELECT name FROM sqlite_master WHERE type='table' AND name='incremental_ledger'");
276828
+ if (!present || present.length === 0) {
276829
+ return;
276830
+ }
276831
+ const columns = await db.all("PRAGMA table_info('incremental_ledger')");
276832
+ const keyedOnPackage = columns.some((column) => column.name === "package_name" && Boolean(column.pk));
276833
+ if (!keyedOnPackage) {
276834
+ return;
276835
+ }
276836
+ logger.info("Re-keying the incremental ledger onto (environment, connection, table); " + "recorded covered_through boundaries are discarded, so each incremental " + "source rebuilds in full once and then resumes advancing by delta");
276837
+ await db.run("DROP TABLE IF EXISTS incremental_ledger");
276838
+ }
276822
276839
  async function createEntityEmbeddingsTable(db) {
276823
276840
  await db.run(`
276824
276841
  CREATE TABLE IF NOT EXISTS entity_embeddings (
@@ -280634,6 +280651,9 @@ function ledgerLineageMismatch(entry, lineage) {
280634
280651
  };
280635
280652
  }
280636
280653
  const changed = (reason) => ({ reasonCode: "lineage_changed", reason });
280654
+ if (entry.sourceEntityId !== lineage.sourceEntityId) {
280655
+ return changed(`the source's content address changed, so the recorded boundary was ` + `measured over different SQL than this refresh would apply a delta to`);
280656
+ }
280637
280657
  if (entry.connectionName !== lineage.connectionName) {
280638
280658
  return changed(`the recorded boundary was advanced on connection ` + `"${entry.connectionName}", not "${lineage.connectionName}"`);
280639
280659
  }
@@ -292740,6 +292760,7 @@ function incrementalLineage(params) {
292740
292760
  return {
292741
292761
  physicalTableName: params.physicalTableName,
292742
292762
  connectionName: params.connectionName,
292763
+ sourceEntityId: params.sourceEntityId,
292743
292764
  watermarkName: watermark.name,
292744
292765
  watermarkType: watermark.malloyType,
292745
292766
  mergeKeys,
@@ -292750,7 +292771,7 @@ async function planSourceRefresh(params) {
292750
292771
  const { context, lineage } = params;
292751
292772
  let ledgerEntry = null;
292752
292773
  try {
292753
- ledgerEntry = await context.ledger.getIncrementalLedgerEntry(context.environmentId, context.packageName, params.sourceEntityId);
292774
+ ledgerEntry = await context.ledger.getIncrementalLedgerEntry(context.environmentId, lineage.connectionName, lineage.physicalTableName);
292754
292775
  } catch (err) {
292755
292776
  return {
292756
292777
  mode: "seed",
@@ -292786,7 +292807,7 @@ async function advanceLedger(params) {
292786
292807
  await context.ledger.upsertIncrementalLedgerEntry({
292787
292808
  environmentId: context.environmentId,
292788
292809
  packageName: context.packageName,
292789
- sourceEntityId: params.sourceEntityId,
292810
+ sourceEntityId: lineage.sourceEntityId,
292790
292811
  coveredThroughValue: params.coveredThrough.value,
292791
292812
  coveredThroughType: params.coveredThrough.malloyType,
292792
292813
  watermarkDimension: lineage.watermarkName,
@@ -292799,18 +292820,19 @@ async function advanceLedger(params) {
292799
292820
  } catch (err) {
292800
292821
  logger.warn("Failed to advance the covered_through boundary", {
292801
292822
  packageName: context.packageName,
292802
- sourceEntityId: params.sourceEntityId,
292823
+ physicalTableName: lineage.physicalTableName,
292824
+ sourceEntityId: lineage.sourceEntityId,
292803
292825
  error: errMessage(err)
292804
292826
  });
292805
292827
  }
292806
292828
  }
292807
- async function resetLedger(context, sourceEntityId) {
292829
+ async function resetLedger(context, lineage) {
292808
292830
  try {
292809
- await context.ledger.deleteIncrementalLedgerEntry(context.environmentId, context.packageName, sourceEntityId);
292831
+ await context.ledger.deleteIncrementalLedgerEntry(context.environmentId, lineage.connectionName, lineage.physicalTableName);
292810
292832
  } catch (err) {
292811
292833
  logger.warn("Failed to clear the covered_through boundary", {
292812
292834
  packageName: context.packageName,
292813
- sourceEntityId,
292835
+ physicalTableName: lineage.physicalTableName,
292814
292836
  error: errMessage(err)
292815
292837
  });
292816
292838
  }
@@ -292821,7 +292843,7 @@ async function advanceLedgerAfterSeed(params) {
292821
292843
  if (boundary.error) {
292822
292844
  logger.warn("Could not read a covered_through boundary after a full rebuild; " + "the next refresh will rebuild again", {
292823
292845
  packageName: params.context.packageName,
292824
- sourceEntityId: params.sourceEntityId,
292846
+ physicalTableName: params.lineage.physicalTableName,
292825
292847
  error: boundary.error
292826
292848
  });
292827
292849
  }
@@ -292830,7 +292852,6 @@ async function advanceLedgerAfterSeed(params) {
292830
292852
  await advanceLedger({
292831
292853
  context: params.context,
292832
292854
  lineage: params.lineage,
292833
- sourceEntityId: params.sourceEntityId,
292834
292855
  coveredThrough: boundary.bound
292835
292856
  });
292836
292857
  return boundary.bound;
@@ -293407,6 +293428,7 @@ class MaterializationService {
293407
293428
  dialect: persistSource.dialectName,
293408
293429
  physicalTableName: logicalName,
293409
293430
  connectionName: persistSource.connectionName,
293431
+ sourceEntityId,
293410
293432
  isStorageBuild: destination !== undefined
293411
293433
  }) !== undefined;
293412
293434
  const prior = priorEntries[sourceEntityId];
@@ -293760,12 +293782,12 @@ class MaterializationService {
293760
293782
  dialect,
293761
293783
  physicalTableName,
293762
293784
  connectionName: persistSource.connectionName,
293785
+ sourceEntityId: contentSourceEntityId,
293763
293786
  isStorageBuild
293764
293787
  }) : undefined;
293765
293788
  const incrementalRefresh = incremental && lineage && contentSourceEntityId ? {
293766
293789
  context: incremental,
293767
- lineage,
293768
- ledgerKey: contentSourceEntityId
293790
+ lineage
293769
293791
  } : undefined;
293770
293792
  if (incrementalRefresh) {
293771
293793
  const applied = await this.refreshOneSourceIncrementally({
@@ -293787,7 +293809,7 @@ class MaterializationService {
293787
293809
  const quotedPhysical = quotedPhysicalPath;
293788
293810
  const quotedBareName = quoteIdentifier(bareName, dialect);
293789
293811
  if (incrementalRefresh) {
293790
- await resetLedger(incrementalRefresh.context, incrementalRefresh.ledgerKey);
293812
+ await resetLedger(incrementalRefresh.context, incrementalRefresh.lineage);
293791
293813
  }
293792
293814
  const startTime = performance.now();
293793
293815
  await connection.runSQL(`DROP TABLE IF EXISTS ${quotedStaging}`, runOptions);
@@ -293817,7 +293839,6 @@ class MaterializationService {
293817
293839
  const seededThrough = incrementalRefresh ? await advanceLedgerAfterSeed({
293818
293840
  context: incrementalRefresh.context,
293819
293841
  lineage: incrementalRefresh.lineage,
293820
- sourceEntityId: incrementalRefresh.ledgerKey,
293821
293842
  quotedTablePath: quotedPhysical,
293822
293843
  dialect,
293823
293844
  runner: (sql) => connection.runSQL(sql, runOptions)
@@ -293842,7 +293863,6 @@ class MaterializationService {
293842
293863
  context,
293843
293864
  lineage,
293844
293865
  persistSource,
293845
- sourceEntityId: params.ledgerKey,
293846
293866
  quotedTablePath: params.quotedTablePath,
293847
293867
  sourceSQL: params.buildSQL,
293848
293868
  columns: deriveColumns(persistSource).map((c) => String(c.name)),
@@ -293865,7 +293885,6 @@ class MaterializationService {
293865
293885
  await advanceLedger({
293866
293886
  context,
293867
293887
  lineage,
293868
- sourceEntityId: params.ledgerKey,
293869
293888
  coveredThrough: step.coveredThrough
293870
293889
  });
293871
293890
  const durationMs = Math.round(performance.now() - startTime);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/server",
3
3
  "description": "Malloy Publisher Server",
4
- "version": "0.0.239",
4
+ "version": "0.0.240",
5
5
  "main": "dist/server.mjs",
6
6
  "bin": {
7
7
  "malloy-publisher": "dist/server.mjs"