@nicnocquee/dataqueue 1.18.1 → 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.
Files changed (2) hide show
  1. package/cli.cjs +16 -25
  2. 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('Usage: dataqueue-cli migrate [--envPath <path>]');
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,29 +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
 
30
- // Parse search_path from dbUrl if present
31
+ // Support for -s or --schema argument
31
32
  let schemaArg = [];
32
- let hasCustomSchema = false;
33
- try {
34
- const urlObj = new URL(dbUrl);
35
- if (urlObj.searchParams.has('search_path')) {
36
- const searchPath = urlObj.searchParams.get('search_path');
37
- if (searchPath) {
38
- schemaArg = ['-s', searchPath];
39
- hasCustomSchema = true;
40
- }
41
- }
42
- } catch (e) {
43
- const match = dbUrl.match(/[?&]search_path=([^&]+)/);
44
- if (match && match[1]) {
45
- schemaArg = ['-s', decodeURIComponent(match[1])];
46
- hasCustomSchema = true;
47
- }
48
- }
49
- if (hasCustomSchema) {
50
- 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);
51
41
  }
52
42
 
53
43
  // Support for --envPath argument
@@ -70,6 +60,7 @@ if (command === 'migrate') {
70
60
  migrationsDir,
71
61
  ...schemaArg,
72
62
  ...envPathArg,
63
+ ...restArgs,
73
64
  ],
74
65
  { stdio: 'inherit' },
75
66
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicnocquee/dataqueue",
3
- "version": "1.18.1",
3
+ "version": "1.18.2",
4
4
  "description": "PostgreSQL-based job queue for Node.js applications with support for serverless environments",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",