@sqlanvil/cli 1.25.1 → 1.25.2

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/bundle.js +58 -5
  2. package/package.json +1 -1
package/bundle.js CHANGED
@@ -50646,7 +50646,7 @@ function collectEvaluationQueries(queryOrAction, concatenate, queryModifier = (q
50646
50646
  .filter(validationQuery => !!validationQuery.query);
50647
50647
  }
50648
50648
 
50649
- const version = "1.25.1";
50649
+ const version = "1.25.2";
50650
50650
  const dataformVersion = "3.0.61";
50651
50651
 
50652
50652
  async function build(compiledGraph, runConfig, dbadapter) {
@@ -55992,6 +55992,28 @@ function dependencyBlocked(dependencyKeys, statusByKey) {
55992
55992
  return status !== undefined && status !== "PASS";
55993
55993
  });
55994
55994
  }
55995
+ function rewriteSelfReferences(graph, shadowSuffix, resolveTarget) {
55996
+ var _a;
55997
+ const suffix = `_${shadowSuffix}`;
55998
+ for (const action of [...(graph.tables || []), ...(graph.assertions || [])]) {
55999
+ const target = action.target;
56000
+ if (!((_a = target === null || target === void 0 ? void 0 : target.schema) === null || _a === void 0 ? void 0 : _a.endsWith(suffix))) {
56001
+ continue;
56002
+ }
56003
+ const prodTarget = sqlanvil.Target.create(Object.assign(Object.assign({}, target), { schema: target.schema.slice(0, -suffix.length) }));
56004
+ const shadowName = resolveTarget(target);
56005
+ const prodName = resolveTarget(prodTarget);
56006
+ const rewrite = (sql) => sql.split(shadowName).join(prodName);
56007
+ if (action.query) {
56008
+ action.query = rewrite(action.query);
56009
+ }
56010
+ const table = action;
56011
+ if (table.incrementalQuery) {
56012
+ table.incrementalQuery = rewrite(table.incrementalQuery);
56013
+ }
56014
+ }
56015
+ return graph;
56016
+ }
55995
56017
  const VALIDATE_SHADOW_PREFIX = "sqlanvil_validate_";
55996
56018
  function validateShadowSuffix(nowMs) {
55997
56019
  return `${VALIDATE_SHADOW_PREFIX}${nowMs}`;
@@ -56035,6 +56057,22 @@ function tableType(enumType) {
56035
56057
  function depKeys(deps) {
56036
56058
  return (deps || []).map(targetKey);
56037
56059
  }
56060
+ function stripOps(table) {
56061
+ const bare = sqlanvil.Table.create(table);
56062
+ bare.preOps = [];
56063
+ bare.postOps = [];
56064
+ bare.incrementalPreOps = [];
56065
+ bare.incrementalPostOps = [];
56066
+ return bare;
56067
+ }
56068
+ function collectOps(table) {
56069
+ return [
56070
+ ...(table.preOps || []),
56071
+ ...(table.postOps || []),
56072
+ ...(table.incrementalPreOps || []),
56073
+ ...(table.incrementalPostOps || [])
56074
+ ].filter(op => !!op && !!op.trim());
56075
+ }
56038
56076
  async function validate(compiledGraph, deps, options = {}) {
56039
56077
  const nodes = [];
56040
56078
  for (const table of compiledGraph.tables || []) {
@@ -56119,20 +56157,33 @@ async function validate(compiledGraph, deps, options = {}) {
56119
56157
  results.push({ target: node.target, type: node.type, status: "BLOCKED", errors: [] });
56120
56158
  continue;
56121
56159
  }
56160
+ const evaluationAction = node.kind === "table" ? stripOps(node.table) : node.action;
56122
56161
  const evaluations = node.kind === "script"
56123
56162
  ? await deps.checkScript(node.script)
56124
- : await deps.evaluate(node.action);
56163
+ : await deps.evaluate(evaluationAction);
56125
56164
  const failed = evaluations.some(e => e.status === sqlanvil.QueryEvaluation.QueryEvaluationStatus.FAILURE);
56126
- const status = failed ? "FAILURE" : "PASS";
56127
- statusByKey.set(node.key, status);
56128
- results.push({ target: node.target, type: node.type, status, errors: evaluations });
56165
+ let status = failed ? "FAILURE" : "PASS";
56166
+ let stubCreated = false;
56129
56167
  if (status === "PASS" && node.kind === "table") {
56130
56168
  try {
56131
56169
  await deps.execute(deps.validationStubSql(node.table));
56170
+ stubCreated = true;
56132
56171
  }
56133
56172
  catch (e) {
56134
56173
  }
56135
56174
  }
56175
+ if (status === "PASS" && node.kind === "table" && stubCreated && deps.evaluateOp) {
56176
+ for (const op of collectOps(node.table)) {
56177
+ const opEvaluations = await deps.evaluateOp(op);
56178
+ evaluations.push(...opEvaluations);
56179
+ if (opEvaluations.some(e => e.status === sqlanvil.QueryEvaluation.QueryEvaluationStatus.FAILURE)) {
56180
+ status = "FAILURE";
56181
+ break;
56182
+ }
56183
+ }
56184
+ }
56185
+ statusByKey.set(node.key, status);
56186
+ results.push({ target: node.target, type: node.type, status, errors: evaluations });
56136
56187
  }
56137
56188
  }
56138
56189
  finally {
@@ -57203,6 +57254,7 @@ async function runValidate(argv) {
57203
57254
  tags: argv[tagsOption.name]
57204
57255
  });
57205
57256
  const executionSql = new ExecutionSql(compiledGraph.projectConfig, dataformVersion);
57257
+ rewriteSelfReferences(prunedGraph, shadowSuffix, target => executionSql.resolveTarget(target));
57206
57258
  const shadowSchemas = Array.from(new Set((prunedGraph.tables || []).map(table => table.target.schema)));
57207
57259
  process.on("SIGINT", () => {
57208
57260
  Promise.all(shadowSchemas.map(schema => dbadapter.execute(executionSql.dropSchemaCascadeSql(schema)).catch(() => undefined))).then(() => process.exit(1));
@@ -57211,6 +57263,7 @@ async function runValidate(argv) {
57211
57263
  evaluate: action => dbadapter.evaluate(action.enumType !== undefined
57212
57264
  ? sqlanvil.Table.create(action)
57213
57265
  : sqlanvil.Assertion.create(action)),
57266
+ evaluateOp: warehouse === "bigquery" ? (sql) => dbadapter.evaluate(sql) : undefined,
57214
57267
  execute: sql => dbadapter.execute(sql).then(() => undefined),
57215
57268
  validationStubSql: table => executionSql.validationStubSql(table),
57216
57269
  createSchemaSql: schema => executionSql.createSchemaSql(schema),
package/package.json CHANGED
@@ -71,7 +71,7 @@
71
71
  "bin": {
72
72
  "sqlanvil": "bundle.js"
73
73
  },
74
- "version": "1.25.1",
74
+ "version": "1.25.2",
75
75
  "name": "@sqlanvil/cli",
76
76
  "description": "sqlanvil command line interface.",
77
77
  "main": "bundle.js"