@nicnocquee/dataqueue 1.17.0 → 1.18.1

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 +49 -8
  2. package/package.json +2 -2
package/cli.cjs CHANGED
@@ -4,31 +4,72 @@ const { spawnSync } = require('child_process');
4
4
  const path = require('path');
5
5
 
6
6
  function printUsage() {
7
- console.log('Usage: dataqueue-cli migrate');
7
+ console.log('Usage: dataqueue-cli migrate [--envPath <path>]');
8
+ console.log('');
9
+ console.log('Options:');
10
+ console.log(
11
+ ' --envPath <path> Path to a .env file to load environment variables (passed to node-pg-migrate)',
12
+ );
13
+ console.log('');
14
+ console.log('Notes:');
15
+ console.log(
16
+ ' - The PG_DATAQUEUE_DATABASE environment variable must be set to your Postgres connection string.',
17
+ );
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
+ );
8
21
  process.exit(1);
9
22
  }
10
23
 
11
- const [, , command] = process.argv;
24
+ const [, , command, ...restArgs] = process.argv;
12
25
 
13
26
  if (command === 'migrate') {
14
27
  const migrationsDir = path.join(__dirname, 'migrations');
15
28
  const dbUrl = process.env.PG_DATAQUEUE_DATABASE;
16
- console.log(dbUrl);
17
- if (!dbUrl) {
18
- console.error(
19
- 'Error: PG_DATAQUEUE_DATABASE environment variable must be set to your Postgres connection string.',
20
- );
21
- process.exit(1);
29
+
30
+ // Parse search_path from dbUrl if present
31
+ 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
+ }
22
48
  }
49
+ if (hasCustomSchema) {
50
+ schemaArg.push('--create-schema');
51
+ }
52
+
53
+ // Support for --envPath argument
54
+ let envPathArg = [];
55
+ const envPathIndex = restArgs.indexOf('--envPath');
56
+ if (envPathIndex !== -1 && restArgs[envPathIndex + 1]) {
57
+ envPathArg = ['--envPath', restArgs[envPathIndex + 1]];
58
+ }
59
+
23
60
  const result = spawnSync(
24
61
  'npx',
25
62
  [
26
63
  'node-pg-migrate',
27
64
  'up',
65
+ '-t',
66
+ 'dataqueuedev_migrations',
28
67
  '-d',
29
68
  'PG_DATAQUEUE_DATABASE',
30
69
  '-m',
31
70
  migrationsDir,
71
+ ...schemaArg,
72
+ ...envPathArg,
32
73
  ],
33
74
  { stdio: 'inherit' },
34
75
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicnocquee/dataqueue",
3
- "version": "1.17.0",
3
+ "version": "1.18.1",
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",
@@ -64,6 +64,6 @@
64
64
  "dev": "tsup --watch",
65
65
  "migrate": "node-pg-migrate -d $PG_DATAQUEUE_DATABASE -m ./migrations",
66
66
  "changeset:add": "changeset",
67
- "changeset:version": "changeset version && find .changeset -type f -name '*.md' ! -name 'README.md' -delete"
67
+ "changeset:version": "changeset version && find .changeset -type f -name '*.md' ! -name 'README.md' -delete"
68
68
  }
69
69
  }