@nicnocquee/dataqueue 1.18.0 → 1.18.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.
- package/cli.cjs +16 -32
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -4,20 +4,22 @@ const { spawnSync } = require('child_process');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
6
|
function printUsage() {
|
|
7
|
-
console.log(
|
|
7
|
+
console.log(
|
|
8
|
+
'Usage: dataqueue-cli migrate [--envPath <path>] [-s <schema> | --schema <schema>]',
|
|
9
|
+
);
|
|
8
10
|
console.log('');
|
|
9
11
|
console.log('Options:');
|
|
10
12
|
console.log(
|
|
11
13
|
' --envPath <path> Path to a .env file to load environment variables (passed to node-pg-migrate)',
|
|
12
14
|
);
|
|
15
|
+
console.log(
|
|
16
|
+
' -s, --schema <schema> Set the schema to use (passed to node-pg-migrate)',
|
|
17
|
+
);
|
|
13
18
|
console.log('');
|
|
14
19
|
console.log('Notes:');
|
|
15
20
|
console.log(
|
|
16
21
|
' - The PG_DATAQUEUE_DATABASE environment variable must be set to your Postgres connection string.',
|
|
17
22
|
);
|
|
18
|
-
console.log(
|
|
19
|
-
' - If the connection string contains a search_path parameter, the CLI will automatically set the schema and add --create-schema.',
|
|
20
|
-
);
|
|
21
23
|
process.exit(1);
|
|
22
24
|
}
|
|
23
25
|
|
|
@@ -25,36 +27,17 @@ const [, , command, ...restArgs] = process.argv;
|
|
|
25
27
|
|
|
26
28
|
if (command === 'migrate') {
|
|
27
29
|
const migrationsDir = path.join(__dirname, 'migrations');
|
|
28
|
-
const dbUrl = process.env.PG_DATAQUEUE_DATABASE;
|
|
29
|
-
|
|
30
|
-
if (!dbUrl) {
|
|
31
|
-
console.error(
|
|
32
|
-
'Error: PG_DATAQUEUE_DATABASE environment variable must be set to your Postgres connection string.',
|
|
33
|
-
);
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
30
|
|
|
37
|
-
//
|
|
31
|
+
// Support for -s or --schema argument
|
|
38
32
|
let schemaArg = [];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
} catch (e) {
|
|
50
|
-
const match = dbUrl.match(/[?&]search_path=([^&]+)/);
|
|
51
|
-
if (match && match[1]) {
|
|
52
|
-
schemaArg = ['-s', decodeURIComponent(match[1])];
|
|
53
|
-
hasCustomSchema = true;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (hasCustomSchema) {
|
|
57
|
-
schemaArg.push('--create-schema');
|
|
33
|
+
const sIndex = restArgs.indexOf('-s');
|
|
34
|
+
const schemaIndex = restArgs.indexOf('--schema');
|
|
35
|
+
if (sIndex !== -1 && restArgs[sIndex + 1]) {
|
|
36
|
+
schemaArg = ['-s', restArgs[sIndex + 1], '--create-schema'];
|
|
37
|
+
restArgs.splice(sIndex, 2);
|
|
38
|
+
} else if (schemaIndex !== -1 && restArgs[schemaIndex + 1]) {
|
|
39
|
+
schemaArg = ['-s', restArgs[schemaIndex + 1], '--create-schema'];
|
|
40
|
+
restArgs.splice(schemaIndex, 2);
|
|
58
41
|
}
|
|
59
42
|
|
|
60
43
|
// Support for --envPath argument
|
|
@@ -77,6 +60,7 @@ if (command === 'migrate') {
|
|
|
77
60
|
migrationsDir,
|
|
78
61
|
...schemaArg,
|
|
79
62
|
...envPathArg,
|
|
63
|
+
...restArgs,
|
|
80
64
|
],
|
|
81
65
|
{ stdio: 'inherit' },
|
|
82
66
|
);
|
package/package.json
CHANGED