@sqlanvil/cli 1.1.2 → 1.2.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/bundle.js +49 -3
- package/package.json +1 -1
package/bundle.js
CHANGED
|
@@ -38608,7 +38608,7 @@ function collectEvaluationQueries(queryOrAction, concatenate, queryModifier = (q
|
|
|
38608
38608
|
.filter(validationQuery => !!validationQuery.query);
|
|
38609
38609
|
}
|
|
38610
38610
|
|
|
38611
|
-
const version = "1.
|
|
38611
|
+
const version = "1.2.0";
|
|
38612
38612
|
const dataformVersion = "3.0.59";
|
|
38613
38613
|
|
|
38614
38614
|
async function build(compiledGraph, runConfig, dbadapter) {
|
|
@@ -38885,6 +38885,19 @@ function read(credentialsPath, warehouse = "bigquery") {
|
|
|
38885
38885
|
return credentials;
|
|
38886
38886
|
}
|
|
38887
38887
|
}
|
|
38888
|
+
function readConnections(credentialsPath) {
|
|
38889
|
+
if (!fs__namespace$1.existsSync(credentialsPath)) {
|
|
38890
|
+
return {};
|
|
38891
|
+
}
|
|
38892
|
+
let credentialsAsJson;
|
|
38893
|
+
try {
|
|
38894
|
+
credentialsAsJson = JSON.parse(fs__namespace$1.readFileSync(credentialsPath, "utf8"));
|
|
38895
|
+
}
|
|
38896
|
+
catch (e) {
|
|
38897
|
+
throw new Error(`Error reading credentials file: ${e.message}`);
|
|
38898
|
+
}
|
|
38899
|
+
return credentialsAsJson.connections || {};
|
|
38900
|
+
}
|
|
38888
38901
|
var TestResultStatus;
|
|
38889
38902
|
(function (TestResultStatus) {
|
|
38890
38903
|
TestResultStatus[TestResultStatus["SUCCESSFUL"] = 0] = "SUCCESSFUL";
|
|
@@ -39195,6 +39208,31 @@ function introspectToSqlx(projectDir, connectionName, tableRef, options) {
|
|
|
39195
39208
|
});
|
|
39196
39209
|
}
|
|
39197
39210
|
|
|
39211
|
+
const CONNECTION_TOKEN = /\$\{SA_CONN:([^:}]+):([^}]+)\}/g;
|
|
39212
|
+
function substituteConnectionCredentials(statement, connections) {
|
|
39213
|
+
return statement.replace(CONNECTION_TOKEN, (_match, connectionName, field) => {
|
|
39214
|
+
const entry = connections[connectionName];
|
|
39215
|
+
if (!entry) {
|
|
39216
|
+
throw new Error(`Connection "${connectionName}" is referenced by an FDW bridge but has no entry under ` +
|
|
39217
|
+
`"connections" in .df-credentials.json. Add connections.${connectionName} with the ` +
|
|
39218
|
+
`source user/password.`);
|
|
39219
|
+
}
|
|
39220
|
+
const value = entry[field];
|
|
39221
|
+
if (value === undefined || value === null || value === "") {
|
|
39222
|
+
throw new Error(`Connection "${connectionName}" is missing "${field}" under "connections.${connectionName}" ` +
|
|
39223
|
+
`in .df-credentials.json.`);
|
|
39224
|
+
}
|
|
39225
|
+
return String(value).replace(/'/g, "''");
|
|
39226
|
+
});
|
|
39227
|
+
}
|
|
39228
|
+
function assertConnectionCredentialsAvailable(graph, connections) {
|
|
39229
|
+
(graph.actions || []).forEach(action => (action.tasks || []).forEach(task => {
|
|
39230
|
+
if (task.statement) {
|
|
39231
|
+
substituteConnectionCredentials(task.statement, connections);
|
|
39232
|
+
}
|
|
39233
|
+
}));
|
|
39234
|
+
}
|
|
39235
|
+
|
|
39198
39236
|
function parseArgvFlags(argv) {
|
|
39199
39237
|
const parsedArgv = {};
|
|
39200
39238
|
const splitArgv = [];
|
|
@@ -39595,7 +39633,10 @@ class Runner {
|
|
|
39595
39633
|
}
|
|
39596
39634
|
else {
|
|
39597
39635
|
try {
|
|
39598
|
-
const
|
|
39636
|
+
const statement = this.executionOptions.connectionCredentials
|
|
39637
|
+
? substituteConnectionCredentials(task.statement, this.executionOptions.connectionCredentials)
|
|
39638
|
+
: task.statement;
|
|
39639
|
+
const { rows, metadata } = await retry(() => client.execute(statement, {
|
|
39599
39640
|
onCancel: handleCancel => this.eEmitter.on(CANCEL_EVENT, handleCancel),
|
|
39600
39641
|
rowLimit: 1,
|
|
39601
39642
|
bigquery: options.bigquery
|
|
@@ -42456,13 +42497,18 @@ function runCli() {
|
|
|
42456
42497
|
print("No actions to run.\n");
|
|
42457
42498
|
return 0;
|
|
42458
42499
|
}
|
|
42500
|
+
const connectionCredentials = readConnections(getCredentialsPath(argv[projectDirOption.name], argv[credentialsOption.name]));
|
|
42501
|
+
assertConnectionCredentialsAvailable(executionGraph, connectionCredentials);
|
|
42459
42502
|
if (argv[dryRunOptionName]) {
|
|
42460
42503
|
print("Dry running (no changes to the warehouse will be applied)...");
|
|
42461
42504
|
}
|
|
42462
42505
|
else {
|
|
42463
42506
|
print("Running...\n");
|
|
42464
42507
|
}
|
|
42465
|
-
const runner = run(dbadapter, executionGraph, {
|
|
42508
|
+
const runner = run(dbadapter, executionGraph, {
|
|
42509
|
+
bigquery: bigqueryOptions,
|
|
42510
|
+
connectionCredentials
|
|
42511
|
+
});
|
|
42466
42512
|
process.on("SIGINT", () => {
|
|
42467
42513
|
runner.cancel();
|
|
42468
42514
|
});
|