pgpm 0.2.0 → 0.2.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.
package/README.md CHANGED
@@ -25,14 +25,17 @@ npm install -g pgpm
25
25
  ### Create Your First Project
26
26
 
27
27
  ```bash
28
- # Initialize a new workspace
28
+ # 1. Create workspace
29
29
  pgpm init --workspace
30
- cd my-project
30
+ cd my-app
31
31
 
32
- # Create your first module
32
+ # 2. Create your first module
33
33
  pgpm init
34
34
 
35
- # Deploy to your database
35
+ # 3. Add some SQL migrations to sql/ directory
36
+ pgpm add some_change
37
+
38
+ # 4. Deploy to database
36
39
  pgpm deploy --createdb
37
40
  ```
38
41
 
@@ -111,6 +114,19 @@ pgpm install
111
114
  pgpm deploy --createdb
112
115
  ```
113
116
 
117
+ ### Testing a pgpm module in a workspace
118
+
119
+ ```bash
120
+ # 1. Install dependencies
121
+ pgpm install
122
+
123
+ # 2. Enter the packages/<yourmodule>
124
+ cd packages/yourmodule
125
+
126
+ # 3. Test the module in watch mode
127
+ pnpm test:watch
128
+ ```
129
+
114
130
  ### Database Operations
115
131
 
116
132
  #### `pgpm deploy`
@@ -0,0 +1,4 @@
1
+ import { Inquirerer } from 'inquirerer';
2
+ import { ParsedArgs } from 'minimist';
3
+ declare const _default: (argv: Partial<ParsedArgs>, _prompter: Inquirerer) => Promise<void>;
4
+ export default _default;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const child_process_1 = require("child_process");
4
+ const pg_env_1 = require("pg-env");
5
+ const envUsageText = `
6
+ Environment Command:
7
+
8
+ pgpm env [OPTIONS] [COMMAND...]
9
+
10
+ Manage PostgreSQL environment variables with profile support.
11
+
12
+ Profiles:
13
+ (default) Use local Postgres development profile
14
+ --supabase Use Supabase local development profile
15
+
16
+ Modes:
17
+ No command Print export statements for shell evaluation
18
+ With command Execute command with environment variables applied
19
+
20
+ Options:
21
+ --help, -h Show this help message
22
+ --supabase Use Supabase profile instead of default Postgres
23
+
24
+ Examples:
25
+ pgpm env Print default Postgres env exports
26
+ pgpm env --supabase Print Supabase env exports
27
+ eval "$(pgpm env)" Load default Postgres env into shell
28
+ eval "$(pgpm env --supabase)" Load Supabase env into shell
29
+ pgpm env lql deploy --database db1 Run command with default Postgres env
30
+ pgpm env createdb mydb Run command with default Postgres env
31
+ pgpm env --supabase lql deploy --database db1 Run command with Supabase env
32
+ pgpm env --supabase createdb mydb Run command with Supabase env
33
+ `;
34
+ const SUPABASE_PROFILE = {
35
+ host: 'localhost',
36
+ port: 54322,
37
+ user: 'supabase_admin',
38
+ password: 'postgres',
39
+ database: 'postgres'
40
+ };
41
+ const DEFAULT_PROFILE = {
42
+ ...pg_env_1.defaultPgConfig
43
+ };
44
+ function configToEnvVars(config) {
45
+ return {
46
+ PGHOST: config.host,
47
+ PGPORT: String(config.port),
48
+ PGUSER: config.user,
49
+ PGPASSWORD: config.password,
50
+ PGDATABASE: config.database
51
+ };
52
+ }
53
+ function printExports(config) {
54
+ const envVars = configToEnvVars(config);
55
+ for (const [key, value] of Object.entries(envVars)) {
56
+ const escapedValue = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
57
+ console.log(`export ${key}="${escapedValue}"`);
58
+ }
59
+ }
60
+ function executeCommand(config, command, args) {
61
+ return new Promise((resolve, reject) => {
62
+ const envVars = configToEnvVars(config);
63
+ const env = {
64
+ ...process.env,
65
+ ...envVars
66
+ };
67
+ const child = (0, child_process_1.spawn)(command, args, {
68
+ env,
69
+ stdio: 'inherit',
70
+ shell: false
71
+ });
72
+ child.on('error', (error) => {
73
+ reject(error);
74
+ });
75
+ child.on('close', (code) => {
76
+ resolve(code ?? 0);
77
+ });
78
+ });
79
+ }
80
+ exports.default = async (argv, _prompter) => {
81
+ if (argv.help || argv.h) {
82
+ console.log(envUsageText);
83
+ process.exit(0);
84
+ }
85
+ const useSupabase = argv.supabase === true || typeof argv.supabase === 'string';
86
+ const profile = useSupabase ? SUPABASE_PROFILE : DEFAULT_PROFILE;
87
+ const rawArgs = process.argv.slice(2);
88
+ let envIndex = rawArgs.findIndex(arg => arg === 'env');
89
+ if (envIndex === -1) {
90
+ envIndex = 0;
91
+ }
92
+ const argsAfterEnv = rawArgs.slice(envIndex + 1);
93
+ const supabaseIndex = argsAfterEnv.findIndex(arg => arg === '--supabase');
94
+ let commandArgs;
95
+ if (supabaseIndex !== -1) {
96
+ commandArgs = argsAfterEnv.slice(supabaseIndex + 1);
97
+ }
98
+ else {
99
+ commandArgs = argsAfterEnv;
100
+ }
101
+ commandArgs = commandArgs.filter(arg => arg !== '--cwd' && !arg.startsWith('--cwd='));
102
+ const cwdIndex = commandArgs.findIndex(arg => arg === '--cwd');
103
+ if (cwdIndex !== -1 && cwdIndex + 1 < commandArgs.length) {
104
+ commandArgs.splice(cwdIndex, 2);
105
+ }
106
+ if (commandArgs.length === 0) {
107
+ printExports(profile);
108
+ return;
109
+ }
110
+ const [command, ...args] = commandArgs;
111
+ try {
112
+ const exitCode = await executeCommand(profile, command, args);
113
+ process.exit(exitCode);
114
+ }
115
+ catch (error) {
116
+ if (error instanceof Error) {
117
+ console.error(`Error executing command: ${error.message}`);
118
+ }
119
+ else {
120
+ console.error(`Error executing command: ${String(error)}`);
121
+ }
122
+ process.exit(1);
123
+ }
124
+ };
package/commands.js CHANGED
@@ -10,6 +10,7 @@ const admin_users_1 = __importDefault(require("./commands/admin-users"));
10
10
  const analyze_1 = __importDefault(require("./commands/analyze"));
11
11
  const clear_1 = __importDefault(require("./commands/clear"));
12
12
  const deploy_1 = __importDefault(require("./commands/deploy"));
13
+ const env_1 = __importDefault(require("./commands/env"));
13
14
  const export_1 = __importDefault(require("./commands/export"));
14
15
  const extension_1 = __importDefault(require("./commands/extension"));
15
16
  const init_1 = __importDefault(require("./commands/init"));
@@ -43,6 +44,7 @@ const createPgpmCommandMap = (skipPgTeardown = false) => {
43
44
  'admin-users': pgt(admin_users_1.default),
44
45
  clear: pgt(clear_1.default),
45
46
  deploy: pgt(deploy_1.default),
47
+ env: env_1.default,
46
48
  verify: pgt(verify_1.default),
47
49
  revert: pgt(revert_1.default),
48
50
  remove: pgt(remove_1.default),
@@ -0,0 +1,122 @@
1
+ import { spawn } from 'child_process';
2
+ import { defaultPgConfig } from 'pg-env';
3
+ const envUsageText = `
4
+ Environment Command:
5
+
6
+ pgpm env [OPTIONS] [COMMAND...]
7
+
8
+ Manage PostgreSQL environment variables with profile support.
9
+
10
+ Profiles:
11
+ (default) Use local Postgres development profile
12
+ --supabase Use Supabase local development profile
13
+
14
+ Modes:
15
+ No command Print export statements for shell evaluation
16
+ With command Execute command with environment variables applied
17
+
18
+ Options:
19
+ --help, -h Show this help message
20
+ --supabase Use Supabase profile instead of default Postgres
21
+
22
+ Examples:
23
+ pgpm env Print default Postgres env exports
24
+ pgpm env --supabase Print Supabase env exports
25
+ eval "$(pgpm env)" Load default Postgres env into shell
26
+ eval "$(pgpm env --supabase)" Load Supabase env into shell
27
+ pgpm env lql deploy --database db1 Run command with default Postgres env
28
+ pgpm env createdb mydb Run command with default Postgres env
29
+ pgpm env --supabase lql deploy --database db1 Run command with Supabase env
30
+ pgpm env --supabase createdb mydb Run command with Supabase env
31
+ `;
32
+ const SUPABASE_PROFILE = {
33
+ host: 'localhost',
34
+ port: 54322,
35
+ user: 'supabase_admin',
36
+ password: 'postgres',
37
+ database: 'postgres'
38
+ };
39
+ const DEFAULT_PROFILE = {
40
+ ...defaultPgConfig
41
+ };
42
+ function configToEnvVars(config) {
43
+ return {
44
+ PGHOST: config.host,
45
+ PGPORT: String(config.port),
46
+ PGUSER: config.user,
47
+ PGPASSWORD: config.password,
48
+ PGDATABASE: config.database
49
+ };
50
+ }
51
+ function printExports(config) {
52
+ const envVars = configToEnvVars(config);
53
+ for (const [key, value] of Object.entries(envVars)) {
54
+ const escapedValue = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
55
+ console.log(`export ${key}="${escapedValue}"`);
56
+ }
57
+ }
58
+ function executeCommand(config, command, args) {
59
+ return new Promise((resolve, reject) => {
60
+ const envVars = configToEnvVars(config);
61
+ const env = {
62
+ ...process.env,
63
+ ...envVars
64
+ };
65
+ const child = spawn(command, args, {
66
+ env,
67
+ stdio: 'inherit',
68
+ shell: false
69
+ });
70
+ child.on('error', (error) => {
71
+ reject(error);
72
+ });
73
+ child.on('close', (code) => {
74
+ resolve(code ?? 0);
75
+ });
76
+ });
77
+ }
78
+ export default async (argv, _prompter) => {
79
+ if (argv.help || argv.h) {
80
+ console.log(envUsageText);
81
+ process.exit(0);
82
+ }
83
+ const useSupabase = argv.supabase === true || typeof argv.supabase === 'string';
84
+ const profile = useSupabase ? SUPABASE_PROFILE : DEFAULT_PROFILE;
85
+ const rawArgs = process.argv.slice(2);
86
+ let envIndex = rawArgs.findIndex(arg => arg === 'env');
87
+ if (envIndex === -1) {
88
+ envIndex = 0;
89
+ }
90
+ const argsAfterEnv = rawArgs.slice(envIndex + 1);
91
+ const supabaseIndex = argsAfterEnv.findIndex(arg => arg === '--supabase');
92
+ let commandArgs;
93
+ if (supabaseIndex !== -1) {
94
+ commandArgs = argsAfterEnv.slice(supabaseIndex + 1);
95
+ }
96
+ else {
97
+ commandArgs = argsAfterEnv;
98
+ }
99
+ commandArgs = commandArgs.filter(arg => arg !== '--cwd' && !arg.startsWith('--cwd='));
100
+ const cwdIndex = commandArgs.findIndex(arg => arg === '--cwd');
101
+ if (cwdIndex !== -1 && cwdIndex + 1 < commandArgs.length) {
102
+ commandArgs.splice(cwdIndex, 2);
103
+ }
104
+ if (commandArgs.length === 0) {
105
+ printExports(profile);
106
+ return;
107
+ }
108
+ const [command, ...args] = commandArgs;
109
+ try {
110
+ const exitCode = await executeCommand(profile, command, args);
111
+ process.exit(exitCode);
112
+ }
113
+ catch (error) {
114
+ if (error instanceof Error) {
115
+ console.error(`Error executing command: ${error.message}`);
116
+ }
117
+ else {
118
+ console.error(`Error executing command: ${String(error)}`);
119
+ }
120
+ process.exit(1);
121
+ }
122
+ };
package/esm/commands.js CHANGED
@@ -4,6 +4,7 @@ import adminUsers from './commands/admin-users';
4
4
  import analyze from './commands/analyze';
5
5
  import clear from './commands/clear';
6
6
  import deploy from './commands/deploy';
7
+ import env from './commands/env';
7
8
  import _export from './commands/export';
8
9
  import extension from './commands/extension';
9
10
  import init from './commands/init';
@@ -37,6 +38,7 @@ export const createPgpmCommandMap = (skipPgTeardown = false) => {
37
38
  'admin-users': pgt(adminUsers),
38
39
  clear: pgt(clear),
39
40
  deploy: pgt(deploy),
41
+ env,
40
42
  verify: pgt(verify),
41
43
  revert: pgt(revert),
42
44
  remove: pgt(remove),
package/esm/index.js CHANGED
@@ -9,6 +9,7 @@ export { default as adminUsers } from './commands/admin-users';
9
9
  export { default as analyze } from './commands/analyze';
10
10
  export { default as clear } from './commands/clear';
11
11
  export { default as deploy } from './commands/deploy';
12
+ export { default as env } from './commands/env';
12
13
  export { default as _export } from './commands/export';
13
14
  export { default as extension } from './commands/extension';
14
15
  export { default as install } from './commands/install';
package/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { default as adminUsers } from './commands/admin-users';
7
7
  export { default as analyze } from './commands/analyze';
8
8
  export { default as clear } from './commands/clear';
9
9
  export { default as deploy } from './commands/deploy';
10
+ export { default as env } from './commands/env';
10
11
  export { default as _export } from './commands/export';
11
12
  export { default as extension } from './commands/extension';
12
13
  export { default as install } from './commands/install';
package/index.js CHANGED
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.options = exports.verify = exports.tag = exports.revert = exports.renameCmd = exports.remove = exports.plan = exports._package = exports.migrate = exports.kill = exports.install = exports.extension = exports._export = exports.deploy = exports.clear = exports.analyze = exports.adminUsers = exports.add = exports.createPgpmCommandMap = void 0;
21
+ exports.options = exports.verify = exports.tag = exports.revert = exports.renameCmd = exports.remove = exports.plan = exports._package = exports.migrate = exports.kill = exports.install = exports.extension = exports._export = exports.env = exports.deploy = exports.clear = exports.analyze = exports.adminUsers = exports.add = exports.createPgpmCommandMap = void 0;
22
22
  const fs_1 = require("fs");
23
23
  const inquirerer_1 = require("inquirerer");
24
24
  const path_1 = require("path");
@@ -34,6 +34,8 @@ var clear_1 = require("./commands/clear");
34
34
  Object.defineProperty(exports, "clear", { enumerable: true, get: function () { return __importDefault(clear_1).default; } });
35
35
  var deploy_1 = require("./commands/deploy");
36
36
  Object.defineProperty(exports, "deploy", { enumerable: true, get: function () { return __importDefault(deploy_1).default; } });
37
+ var env_1 = require("./commands/env");
38
+ Object.defineProperty(exports, "env", { enumerable: true, get: function () { return __importDefault(env_1).default; } });
37
39
  var export_1 = require("./commands/export");
38
40
  Object.defineProperty(exports, "_export", { enumerable: true, get: function () { return __importDefault(export_1).default; } });
39
41
  var extension_1 = require("./commands/extension");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgpm",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "PostgreSQL Package Manager - Database migration and package management CLI",
6
6
  "main": "index.js",
@@ -45,16 +45,16 @@
45
45
  "ts-node": "^10.9.2"
46
46
  },
47
47
  "dependencies": {
48
- "@launchql/core": "^2.15.0",
48
+ "@launchql/core": "^2.15.1",
49
49
  "@launchql/env": "^2.5.0",
50
- "@launchql/logger": "^1.1.4",
50
+ "@launchql/logger": "^1.1.5",
51
51
  "@launchql/templatizer": "^2.5.0",
52
52
  "@launchql/types": "^2.8.0",
53
53
  "chalk": "^4.1.0",
54
54
  "inquirerer": "^2.0.8",
55
55
  "js-yaml": "^4.1.0",
56
56
  "minimist": "^1.2.8",
57
- "pg-cache": "^1.4.0",
57
+ "pg-cache": "^1.4.1",
58
58
  "pg-env": "^1.1.2",
59
59
  "shelljs": "^0.9.2"
60
60
  },
@@ -70,5 +70,5 @@
70
70
  "pg",
71
71
  "pgsql"
72
72
  ],
73
- "gitHead": "810621bb74659b75a5360634c9cf91bf0996ce19"
73
+ "gitHead": "2bc45c48444fc9c2cce9f082cf33d533915bb048"
74
74
  }