pgpm 0.0.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 +416 -0
- package/commands/add.d.ts +7 -0
- package/commands/add.js +86 -0
- package/commands/admin-users/add.d.ts +4 -0
- package/commands/admin-users/add.js +89 -0
- package/commands/admin-users/bootstrap.d.ts +4 -0
- package/commands/admin-users/bootstrap.js +50 -0
- package/commands/admin-users/remove.d.ts +4 -0
- package/commands/admin-users/remove.js +82 -0
- package/commands/admin-users.d.ts +4 -0
- package/commands/admin-users.js +68 -0
- package/commands/analyze.d.ts +4 -0
- package/commands/analyze.js +21 -0
- package/commands/clear.d.ts +3 -0
- package/commands/clear.js +59 -0
- package/commands/deploy.d.ts +4 -0
- package/commands/deploy.js +146 -0
- package/commands/explorer.d.ts +3 -0
- package/commands/explorer.js +94 -0
- package/commands/export.d.ts +3 -0
- package/commands/export.js +129 -0
- package/commands/extension.d.ts +4 -0
- package/commands/extension.js +48 -0
- package/commands/init/index.d.ts +7 -0
- package/commands/init/index.js +47 -0
- package/commands/init/module.d.ts +4 -0
- package/commands/init/module.js +71 -0
- package/commands/init/workspace.d.ts +4 -0
- package/commands/init/workspace.js +52 -0
- package/commands/install.d.ts +4 -0
- package/commands/install.js +37 -0
- package/commands/kill.d.ts +3 -0
- package/commands/kill.js +107 -0
- package/commands/migrate/deps.d.ts +4 -0
- package/commands/migrate/deps.js +186 -0
- package/commands/migrate/init.d.ts +4 -0
- package/commands/migrate/init.js +65 -0
- package/commands/migrate/list.d.ts +4 -0
- package/commands/migrate/list.js +85 -0
- package/commands/migrate/status.d.ts +4 -0
- package/commands/migrate/status.js +94 -0
- package/commands/migrate.d.ts +4 -0
- package/commands/migrate.js +69 -0
- package/commands/package.d.ts +3 -0
- package/commands/package.js +65 -0
- package/commands/plan.d.ts +3 -0
- package/commands/plan.js +62 -0
- package/commands/remove.d.ts +3 -0
- package/commands/remove.js +42 -0
- package/commands/rename.d.ts +4 -0
- package/commands/rename.js +35 -0
- package/commands/revert.d.ts +3 -0
- package/commands/revert.js +107 -0
- package/commands/server.d.ts +3 -0
- package/commands/server.js +187 -0
- package/commands/tag.d.ts +6 -0
- package/commands/tag.js +168 -0
- package/commands/verify.d.ts +3 -0
- package/commands/verify.js +85 -0
- package/commands.d.ts +5 -0
- package/commands.js +118 -0
- package/dist/README.md +416 -0
- package/dist/package.json +77 -0
- package/esm/commands/add.js +51 -0
- package/esm/commands/admin-users/add.js +87 -0
- package/esm/commands/admin-users/bootstrap.js +48 -0
- package/esm/commands/admin-users/remove.js +80 -0
- package/esm/commands/admin-users.js +63 -0
- package/esm/commands/analyze.js +16 -0
- package/esm/commands/clear.js +54 -0
- package/esm/commands/deploy.js +144 -0
- package/esm/commands/explorer.js +92 -0
- package/esm/commands/export.js +127 -0
- package/esm/commands/extension.js +46 -0
- package/esm/commands/init/index.js +42 -0
- package/esm/commands/init/module.js +68 -0
- package/esm/commands/init/workspace.js +46 -0
- package/esm/commands/install.js +35 -0
- package/esm/commands/kill.js +105 -0
- package/esm/commands/migrate/deps.js +184 -0
- package/esm/commands/migrate/init.js +63 -0
- package/esm/commands/migrate/list.js +83 -0
- package/esm/commands/migrate/status.js +92 -0
- package/esm/commands/migrate.js +64 -0
- package/esm/commands/package.js +63 -0
- package/esm/commands/plan.js +60 -0
- package/esm/commands/remove.js +40 -0
- package/esm/commands/rename.js +30 -0
- package/esm/commands/revert.js +105 -0
- package/esm/commands/server.js +185 -0
- package/esm/commands/tag.js +133 -0
- package/esm/commands/verify.js +83 -0
- package/esm/commands.js +111 -0
- package/esm/index.js +20 -0
- package/esm/package.js +26 -0
- package/esm/utils/argv.js +92 -0
- package/esm/utils/cli-error.js +48 -0
- package/esm/utils/database.js +78 -0
- package/esm/utils/deployed-changes.js +68 -0
- package/esm/utils/display.js +58 -0
- package/esm/utils/index.js +3 -0
- package/esm/utils/module-utils.js +51 -0
- package/index.d.ts +3 -0
- package/index.js +23 -0
- package/package.d.ts +1 -0
- package/package.js +29 -0
- package/package.json +77 -0
- package/utils/argv.d.ts +46 -0
- package/utils/argv.js +100 -0
- package/utils/cli-error.d.ts +8 -0
- package/utils/cli-error.js +52 -0
- package/utils/database.d.ts +21 -0
- package/utils/database.js +83 -0
- package/utils/deployed-changes.d.ts +4 -0
- package/utils/deployed-changes.js +72 -0
- package/utils/display.d.ts +3 -0
- package/utils/display.js +66 -0
- package/utils/index.d.ts +3 -0
- package/utils/index.js +19 -0
- package/utils/module-utils.d.ts +8 -0
- package/utils/module-utils.js +54 -0
package/package.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readAndParsePackageJson = readAndParsePackageJson;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
// need to search due to the dist/ folder and src/, etc.
|
|
7
|
+
function findPackageJson(currentDir) {
|
|
8
|
+
const filePath = (0, path_1.join)(currentDir, 'package.json');
|
|
9
|
+
// Check if package.json exists in the current directory
|
|
10
|
+
if ((0, fs_1.existsSync)(filePath)) {
|
|
11
|
+
return filePath;
|
|
12
|
+
}
|
|
13
|
+
// Get the parent directory
|
|
14
|
+
const parentDir = (0, path_1.dirname)(currentDir);
|
|
15
|
+
// If reached the root directory, package.json is not found
|
|
16
|
+
if (parentDir === currentDir) {
|
|
17
|
+
throw new Error('package.json not found in any parent directory');
|
|
18
|
+
}
|
|
19
|
+
// Recursively look in the parent directory
|
|
20
|
+
return findPackageJson(parentDir);
|
|
21
|
+
}
|
|
22
|
+
function readAndParsePackageJson() {
|
|
23
|
+
// Start searching from the current directory
|
|
24
|
+
const pkgPath = findPackageJson(__dirname);
|
|
25
|
+
// Read and parse the package.json
|
|
26
|
+
const str = (0, fs_1.readFileSync)(pkgPath, 'utf8');
|
|
27
|
+
const pkg = JSON.parse(str);
|
|
28
|
+
return pkg;
|
|
29
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pgpm",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
|
+
"description": "LaunchQL CLI",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"homepage": "https://github.com/launchql/launchql",
|
|
10
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"lql": "index.js",
|
|
17
|
+
"launchql": "index.js"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/launchql/launchql"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/launchql/launchql/issues"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
|
|
28
|
+
"clean": "rimraf dist/**",
|
|
29
|
+
"prepare": "npm run build",
|
|
30
|
+
"build": "npm run clean; tsc -p tsconfig.json; tsc -p tsconfig.esm.json; npm run copy",
|
|
31
|
+
"build:dev": "npm run clean; tsc -p tsconfig.json --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
|
|
32
|
+
"dev": "ts-node ./src/index.ts",
|
|
33
|
+
"lint": "eslint . --fix",
|
|
34
|
+
"test": "jest",
|
|
35
|
+
"test:watch": "jest --watch"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/glob": "^8.1.0",
|
|
39
|
+
"@types/js-yaml": "^4.0.9",
|
|
40
|
+
"@types/minimist": "^1.2.5",
|
|
41
|
+
"@types/node": "^20.12.7",
|
|
42
|
+
"@types/pg": "^8.15.2",
|
|
43
|
+
"@types/shelljs": "^0.8.16",
|
|
44
|
+
"glob": "^11.0.2",
|
|
45
|
+
"pg": "^8.16.0",
|
|
46
|
+
"ts-node": "^10.9.2"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@launchql/core": "^2.14.3",
|
|
50
|
+
"@launchql/env": "^2.4.5",
|
|
51
|
+
"@launchql/explorer": "^2.6.1",
|
|
52
|
+
"@launchql/logger": "^1.1.3",
|
|
53
|
+
"@launchql/server": "^2.6.1",
|
|
54
|
+
"@launchql/server-utils": "^2.5.1",
|
|
55
|
+
"@launchql/templatizer": "^2.4.5",
|
|
56
|
+
"@launchql/types": "^2.7.0",
|
|
57
|
+
"chalk": "^4.1.0",
|
|
58
|
+
"inquirerer": "^2.0.8",
|
|
59
|
+
"js-yaml": "^4.1.0",
|
|
60
|
+
"minimist": "^1.2.8",
|
|
61
|
+
"pg-cache": "^1.3.8",
|
|
62
|
+
"pg-env": "^1.1.1",
|
|
63
|
+
"shelljs": "^0.9.2"
|
|
64
|
+
},
|
|
65
|
+
"keywords": [
|
|
66
|
+
"cli",
|
|
67
|
+
"command-line",
|
|
68
|
+
"tool",
|
|
69
|
+
"launchql",
|
|
70
|
+
"utilities",
|
|
71
|
+
"pg",
|
|
72
|
+
"pgsql",
|
|
73
|
+
"postgres",
|
|
74
|
+
"graphile"
|
|
75
|
+
],
|
|
76
|
+
"gitHead": "2e8a123c53d33ee10377b0f034392b0dff1e8a88"
|
|
77
|
+
}
|
package/utils/argv.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ParsedArgs } from 'minimist';
|
|
2
|
+
export declare const extractFirst: (argv: Partial<ParsedArgs>) => {
|
|
3
|
+
first: string;
|
|
4
|
+
newArgv: {
|
|
5
|
+
_: string[];
|
|
6
|
+
"--"?: string[] | undefined;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Common CLI argument validation and processing utilities
|
|
11
|
+
*/
|
|
12
|
+
export interface ValidatedArgv extends ParsedArgs {
|
|
13
|
+
cwd: string;
|
|
14
|
+
database?: string;
|
|
15
|
+
package?: string;
|
|
16
|
+
to?: string;
|
|
17
|
+
recursive?: boolean;
|
|
18
|
+
yes?: boolean;
|
|
19
|
+
tx?: boolean;
|
|
20
|
+
fast?: boolean;
|
|
21
|
+
logOnly?: boolean;
|
|
22
|
+
createdb?: boolean;
|
|
23
|
+
usePlan?: boolean;
|
|
24
|
+
cache?: boolean;
|
|
25
|
+
drop?: boolean;
|
|
26
|
+
all?: boolean;
|
|
27
|
+
summary?: boolean;
|
|
28
|
+
help?: boolean;
|
|
29
|
+
h?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validates and normalizes common CLI arguments
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateCommonArgs(argv: Partial<ParsedArgs>): ValidatedArgv;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if required flags are provided when certain conditions are met
|
|
37
|
+
*/
|
|
38
|
+
export declare function validateFlagDependencies(argv: ValidatedArgv): void;
|
|
39
|
+
/**
|
|
40
|
+
* Logs the effective CLI arguments for debugging
|
|
41
|
+
*/
|
|
42
|
+
export declare function logEffectiveArgs(argv: ValidatedArgv, commandName: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Constructs a deployment target string from package and to arguments
|
|
45
|
+
*/
|
|
46
|
+
export declare function constructTarget(argv: ValidatedArgv, packageName?: string): string | undefined;
|
package/utils/argv.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractFirst = void 0;
|
|
4
|
+
exports.validateCommonArgs = validateCommonArgs;
|
|
5
|
+
exports.validateFlagDependencies = validateFlagDependencies;
|
|
6
|
+
exports.logEffectiveArgs = logEffectiveArgs;
|
|
7
|
+
exports.constructTarget = constructTarget;
|
|
8
|
+
const logger_1 = require("@launchql/logger");
|
|
9
|
+
const log = new logger_1.Logger('argv-utils');
|
|
10
|
+
const extractFirst = (argv) => {
|
|
11
|
+
const first = argv._?.[0];
|
|
12
|
+
const newArgv = {
|
|
13
|
+
...argv,
|
|
14
|
+
_: argv._?.slice(1) ?? []
|
|
15
|
+
};
|
|
16
|
+
return { first, newArgv };
|
|
17
|
+
};
|
|
18
|
+
exports.extractFirst = extractFirst;
|
|
19
|
+
/**
|
|
20
|
+
* Validates and normalizes common CLI arguments
|
|
21
|
+
*/
|
|
22
|
+
function validateCommonArgs(argv) {
|
|
23
|
+
const validated = {
|
|
24
|
+
...argv,
|
|
25
|
+
cwd: argv.cwd || process.cwd(),
|
|
26
|
+
_: argv._ || []
|
|
27
|
+
};
|
|
28
|
+
const booleanFlags = ['recursive', 'yes', 'tx', 'fast', 'logOnly', 'createdb', 'usePlan', 'cache', 'drop', 'all', 'summary', 'help', 'h'];
|
|
29
|
+
for (const flag of booleanFlags) {
|
|
30
|
+
if (argv[flag] !== undefined && typeof argv[flag] !== 'boolean') {
|
|
31
|
+
log.warn(`--${flag} flag should be boolean, converting to true`);
|
|
32
|
+
validated[flag] = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const stringFlags = ['package', 'to', 'database'];
|
|
36
|
+
for (const flag of stringFlags) {
|
|
37
|
+
if (argv[flag] !== undefined && typeof argv[flag] !== 'string') {
|
|
38
|
+
log.warn(`--${flag} should be a string, converting`);
|
|
39
|
+
validated[flag] = String(argv[flag]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return validated;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Checks if required flags are provided when certain conditions are met
|
|
46
|
+
*/
|
|
47
|
+
function validateFlagDependencies(argv) {
|
|
48
|
+
if (argv.to && !argv.package && !argv.recursive) {
|
|
49
|
+
log.warn('--to flag provided without --package or --recursive. Target may not work as expected.');
|
|
50
|
+
}
|
|
51
|
+
if (argv.package && argv.recursive) {
|
|
52
|
+
if (argv.package.includes(':')) {
|
|
53
|
+
log.warn('--package should not contain ":" when using --recursive. Use --to for target specification.');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Logs the effective CLI arguments for debugging
|
|
59
|
+
*/
|
|
60
|
+
function logEffectiveArgs(argv, commandName) {
|
|
61
|
+
const relevantArgs = {
|
|
62
|
+
cwd: argv.cwd,
|
|
63
|
+
database: argv.database,
|
|
64
|
+
package: argv.package,
|
|
65
|
+
to: argv.to,
|
|
66
|
+
recursive: argv.recursive,
|
|
67
|
+
yes: argv.yes,
|
|
68
|
+
tx: argv.tx,
|
|
69
|
+
fast: argv.fast,
|
|
70
|
+
logOnly: argv.logOnly,
|
|
71
|
+
createdb: argv.createdb,
|
|
72
|
+
usePlan: argv.usePlan,
|
|
73
|
+
cache: argv.cache,
|
|
74
|
+
drop: argv.drop,
|
|
75
|
+
all: argv.all,
|
|
76
|
+
summary: argv.summary
|
|
77
|
+
};
|
|
78
|
+
const definedArgs = Object.fromEntries(Object.entries(relevantArgs).filter(([_, value]) => value !== undefined));
|
|
79
|
+
if (Object.keys(definedArgs).length > 1) { // More than just cwd
|
|
80
|
+
log.debug(`${commandName} effective arguments:`, definedArgs);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Constructs a deployment target string from package and to arguments
|
|
85
|
+
*/
|
|
86
|
+
function constructTarget(argv, packageName) {
|
|
87
|
+
if (packageName && argv.to) {
|
|
88
|
+
return `${packageName}:${argv.to}`;
|
|
89
|
+
}
|
|
90
|
+
else if (packageName) {
|
|
91
|
+
return packageName;
|
|
92
|
+
}
|
|
93
|
+
else if (argv.package && argv.to) {
|
|
94
|
+
return `${argv.package}:${argv.to}`;
|
|
95
|
+
}
|
|
96
|
+
else if (argv.package) {
|
|
97
|
+
return argv.package;
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LaunchQLError } from '@launchql/types';
|
|
2
|
+
/**
|
|
3
|
+
* CLI error utility that logs error information and exits with code 1.
|
|
4
|
+
* Provides consistent error handling and user experience across all CLI commands.
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT: This function properly cleans up PostgreSQL connections before exiting.
|
|
7
|
+
*/
|
|
8
|
+
export declare const cliExitWithError: (error: LaunchQLError | Error | string, context?: Record<string, any>) => Promise<never>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cliExitWithError = void 0;
|
|
4
|
+
const types_1 = require("@launchql/types");
|
|
5
|
+
const logger_1 = require("@launchql/logger");
|
|
6
|
+
const pg_cache_1 = require("pg-cache");
|
|
7
|
+
const log = new logger_1.Logger('cli');
|
|
8
|
+
/**
|
|
9
|
+
* CLI error utility that logs error information and exits with code 1.
|
|
10
|
+
* Provides consistent error handling and user experience across all CLI commands.
|
|
11
|
+
*
|
|
12
|
+
* IMPORTANT: This function properly cleans up PostgreSQL connections before exiting.
|
|
13
|
+
*/
|
|
14
|
+
const cliExitWithError = async (error, context) => {
|
|
15
|
+
if (error instanceof types_1.LaunchQLError) {
|
|
16
|
+
// For LaunchQLError instances, use structured logging
|
|
17
|
+
log.error(`Error: ${error.message}`);
|
|
18
|
+
// Log additional context if available
|
|
19
|
+
if (error.context && Object.keys(error.context).length > 0) {
|
|
20
|
+
log.debug('Error context:', error.context);
|
|
21
|
+
}
|
|
22
|
+
// Log any additional context provided
|
|
23
|
+
if (context) {
|
|
24
|
+
log.debug('Additional context:', context);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (error instanceof Error) {
|
|
28
|
+
// For generic Error instances
|
|
29
|
+
log.error(`Error: ${error.message}`);
|
|
30
|
+
if (context) {
|
|
31
|
+
log.debug('Context:', context);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (typeof error === 'string') {
|
|
35
|
+
// For simple string messages
|
|
36
|
+
log.error(`Error: ${error}`);
|
|
37
|
+
if (context) {
|
|
38
|
+
log.debug('Context:', context);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Perform cleanup before exiting
|
|
42
|
+
try {
|
|
43
|
+
await (0, pg_cache_1.teardownPgPools)();
|
|
44
|
+
log.debug('Database connections cleaned up');
|
|
45
|
+
}
|
|
46
|
+
catch (cleanupError) {
|
|
47
|
+
log.warn('Failed to cleanup database connections:', cleanupError);
|
|
48
|
+
// Don't let cleanup errors prevent the exit
|
|
49
|
+
}
|
|
50
|
+
process.exit(1);
|
|
51
|
+
};
|
|
52
|
+
exports.cliExitWithError = cliExitWithError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Inquirerer } from 'inquirerer';
|
|
2
|
+
import { ParsedArgs } from 'minimist';
|
|
3
|
+
export interface DatabaseSelectionOptions {
|
|
4
|
+
message?: string;
|
|
5
|
+
excludeTemplates?: boolean;
|
|
6
|
+
excludePostgres?: boolean;
|
|
7
|
+
excludeSystemDbs?: boolean;
|
|
8
|
+
multiple?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Get list of available databases from PostgreSQL
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAvailableDatabases(options?: DatabaseSelectionOptions): Promise<string[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Prompt user to select a database
|
|
16
|
+
*/
|
|
17
|
+
export declare function selectDatabase(argv: Partial<ParsedArgs>, prompter: Inquirerer, options?: DatabaseSelectionOptions): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Get target database with fallback to environment
|
|
20
|
+
*/
|
|
21
|
+
export declare function getTargetDatabase(argv: Partial<ParsedArgs>, prompter: Inquirerer, options?: DatabaseSelectionOptions): Promise<string>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAvailableDatabases = getAvailableDatabases;
|
|
4
|
+
exports.selectDatabase = selectDatabase;
|
|
5
|
+
exports.getTargetDatabase = getTargetDatabase;
|
|
6
|
+
const pg_cache_1 = require("pg-cache");
|
|
7
|
+
const pg_env_1 = require("pg-env");
|
|
8
|
+
/**
|
|
9
|
+
* Get list of available databases from PostgreSQL
|
|
10
|
+
*/
|
|
11
|
+
async function getAvailableDatabases(options = {}) {
|
|
12
|
+
const { excludeTemplates = true, excludePostgres = true, excludeSystemDbs = true } = options;
|
|
13
|
+
const db = await (0, pg_cache_1.getPgPool)({
|
|
14
|
+
database: 'postgres'
|
|
15
|
+
});
|
|
16
|
+
let query = `
|
|
17
|
+
SELECT datname FROM pg_catalog.pg_database
|
|
18
|
+
WHERE 1=1
|
|
19
|
+
`;
|
|
20
|
+
if (excludeTemplates) {
|
|
21
|
+
query += ` AND datistemplate = FALSE`;
|
|
22
|
+
}
|
|
23
|
+
if (excludePostgres) {
|
|
24
|
+
query += ` AND datname NOT IN ('postgres')`;
|
|
25
|
+
}
|
|
26
|
+
if (excludeSystemDbs) {
|
|
27
|
+
query += ` AND datname !~ '^pg_'`;
|
|
28
|
+
}
|
|
29
|
+
query += ` ORDER BY datname`;
|
|
30
|
+
const result = await db.query(query);
|
|
31
|
+
return result.rows.map((row) => row.datname);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Prompt user to select a database
|
|
35
|
+
*/
|
|
36
|
+
async function selectDatabase(argv, prompter, options = {}) {
|
|
37
|
+
const { message = 'Select target database', multiple = false } = options;
|
|
38
|
+
// Check if database is already specified
|
|
39
|
+
if (!multiple && (argv.db || argv.database)) {
|
|
40
|
+
return argv.db || argv.database;
|
|
41
|
+
}
|
|
42
|
+
// Get available databases
|
|
43
|
+
const databases = await getAvailableDatabases(options);
|
|
44
|
+
if (databases.length === 0) {
|
|
45
|
+
throw new Error('No databases found');
|
|
46
|
+
}
|
|
47
|
+
// If only one database and not forcing selection, use it
|
|
48
|
+
if (!multiple && databases.length === 1 && !argv.interactive) {
|
|
49
|
+
return databases[0];
|
|
50
|
+
}
|
|
51
|
+
// Prompt for selection
|
|
52
|
+
const answer = await prompter.prompt(argv, [
|
|
53
|
+
{
|
|
54
|
+
type: multiple ? 'checkbox' : 'autocomplete',
|
|
55
|
+
name: 'database',
|
|
56
|
+
message,
|
|
57
|
+
options: databases,
|
|
58
|
+
required: true
|
|
59
|
+
}
|
|
60
|
+
]);
|
|
61
|
+
return answer.database;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get target database with fallback to environment
|
|
65
|
+
*/
|
|
66
|
+
async function getTargetDatabase(argv, prompter, options = {}) {
|
|
67
|
+
// If database is specified in args, use it
|
|
68
|
+
if (argv.db || argv.database) {
|
|
69
|
+
return argv.db || argv.database;
|
|
70
|
+
}
|
|
71
|
+
// Try to select from available databases
|
|
72
|
+
try {
|
|
73
|
+
return await selectDatabase(argv, prompter, options);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
// Fall back to environment database
|
|
77
|
+
const pgEnv = (0, pg_env_1.getPgEnvOptions)();
|
|
78
|
+
if (pgEnv.database) {
|
|
79
|
+
return pgEnv.database;
|
|
80
|
+
}
|
|
81
|
+
throw new Error('No database specified and no default database found');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Logger } from '@launchql/logger';
|
|
2
|
+
import { Inquirerer } from 'inquirerer';
|
|
3
|
+
export declare function selectDeployedChange(database: string, argv: Partial<Record<string, any>>, prompter: Inquirerer, log: Logger, action?: 'revert' | 'verify'): Promise<string | undefined>;
|
|
4
|
+
export declare function selectDeployedPackage(database: string, argv: Partial<Record<string, any>>, prompter: Inquirerer, log: Logger, action?: 'revert' | 'verify'): Promise<string | undefined>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectDeployedChange = selectDeployedChange;
|
|
4
|
+
exports.selectDeployedPackage = selectDeployedPackage;
|
|
5
|
+
const core_1 = require("@launchql/core");
|
|
6
|
+
const pg_env_1 = require("pg-env");
|
|
7
|
+
async function selectDeployedChange(database, argv, prompter, log, action = 'revert') {
|
|
8
|
+
const pgEnv = (0, pg_env_1.getPgEnvOptions)({ database });
|
|
9
|
+
const client = new core_1.LaunchQLMigrate(pgEnv);
|
|
10
|
+
let selectedPackage;
|
|
11
|
+
if (argv.package) {
|
|
12
|
+
selectedPackage = argv.package;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const packageStatuses = await client.status();
|
|
16
|
+
if (packageStatuses.length === 0) {
|
|
17
|
+
log.warn('No deployed packages found in database');
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const packageAnswer = await prompter.prompt(argv, [{
|
|
21
|
+
type: 'autocomplete',
|
|
22
|
+
name: 'package',
|
|
23
|
+
message: `Select package to ${action} from:`,
|
|
24
|
+
options: packageStatuses.map(status => ({
|
|
25
|
+
name: status.package,
|
|
26
|
+
value: status.package,
|
|
27
|
+
description: `${status.totalDeployed} changes, last: ${status.lastChange}`
|
|
28
|
+
}))
|
|
29
|
+
}]);
|
|
30
|
+
selectedPackage = packageAnswer.package;
|
|
31
|
+
}
|
|
32
|
+
const deployedChanges = await client.getDeployedChanges(database, selectedPackage);
|
|
33
|
+
if (deployedChanges.length === 0) {
|
|
34
|
+
log.warn(`No deployed changes found for package ${selectedPackage}`);
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const changeAnswer = await prompter.prompt(argv, [{
|
|
38
|
+
type: 'autocomplete',
|
|
39
|
+
name: 'change',
|
|
40
|
+
message: `Select change to ${action} to in ${selectedPackage}:`,
|
|
41
|
+
options: deployedChanges.map(change => ({
|
|
42
|
+
name: change.change_name,
|
|
43
|
+
value: change.change_name,
|
|
44
|
+
description: `Deployed: ${new Date(change.deployed_at).toLocaleString()}`
|
|
45
|
+
}))
|
|
46
|
+
}]);
|
|
47
|
+
const selectedChange = changeAnswer.change;
|
|
48
|
+
return `${selectedPackage}:${selectedChange}`;
|
|
49
|
+
}
|
|
50
|
+
async function selectDeployedPackage(database, argv, prompter, log, action = 'revert') {
|
|
51
|
+
if (argv.package) {
|
|
52
|
+
return argv.package;
|
|
53
|
+
}
|
|
54
|
+
const pgEnv = (0, pg_env_1.getPgEnvOptions)({ database });
|
|
55
|
+
const client = new core_1.LaunchQLMigrate(pgEnv);
|
|
56
|
+
const packageStatuses = await client.status();
|
|
57
|
+
if (packageStatuses.length === 0) {
|
|
58
|
+
log.warn('No deployed packages found in database');
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const packageAnswer = await prompter.prompt(argv, [{
|
|
62
|
+
type: 'autocomplete',
|
|
63
|
+
name: 'package',
|
|
64
|
+
message: `Select package to ${action}:`,
|
|
65
|
+
options: packageStatuses.map(status => ({
|
|
66
|
+
name: status.package,
|
|
67
|
+
value: status.package,
|
|
68
|
+
description: `${status.totalDeployed} changes, last: ${status.lastChange}`
|
|
69
|
+
}))
|
|
70
|
+
}]);
|
|
71
|
+
return packageAnswer.package;
|
|
72
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function displayVersion(): void;
|
|
2
|
+
export declare const usageText = "\n Usage: lql <command> [options]\n launchql <command> [options]\n \n Core Database Operations:\n add Add database changes to plans and create SQL files\n deploy Deploy database changes and migrations\n verify Verify database state and migrations\n revert Revert database changes and migrations\n \n Project Management:\n init Initialize LaunchQL workspace or module\n extension Manage module dependencies\n plan Generate module deployment plans\n package Package module for distribution\n \n Development Tools:\n server Start LaunchQL GraphQL server\n explorer Launch GraphiQL explorer interface\n export Export database migrations from existing databases\n \n Database Administration:\n kill Terminate database connections and optionally drop databases\n install Install LaunchQL modules\n tag Add tags to changes for versioning\n \n Migration Tools:\n migrate Migration management subcommands\n init Initialize migration tracking\n status Show migration status\n list List all changes\n deps Show change dependencies\n \n Global Options:\n -h, --help Display this help information\n -v, --version Display version information\n --cwd <directory> Working directory (default: current directory)\n \n Individual Command Help:\n lql <command> --help Display detailed help for specific command\n lql <command> -h Display detailed help for specific command\n \n Examples:\n lql deploy --help Show deploy command options\n lql server --port 8080 Start server on port 8080\n lql init --workspace Initialize new workspace\n ";
|
|
3
|
+
export declare function displayUsage(): void;
|
package/utils/display.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.usageText = void 0;
|
|
7
|
+
exports.displayVersion = displayVersion;
|
|
8
|
+
exports.displayUsage = displayUsage;
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const package_1 = require("../package");
|
|
11
|
+
// Function to display the version information
|
|
12
|
+
function displayVersion() {
|
|
13
|
+
const pkg = (0, package_1.readAndParsePackageJson)();
|
|
14
|
+
console.log(chalk_1.default.green(`Name: ${pkg.name}`));
|
|
15
|
+
console.log(chalk_1.default.blue(`Version: ${pkg.version}`));
|
|
16
|
+
}
|
|
17
|
+
exports.usageText = `
|
|
18
|
+
Usage: lql <command> [options]
|
|
19
|
+
launchql <command> [options]
|
|
20
|
+
|
|
21
|
+
Core Database Operations:
|
|
22
|
+
add Add database changes to plans and create SQL files
|
|
23
|
+
deploy Deploy database changes and migrations
|
|
24
|
+
verify Verify database state and migrations
|
|
25
|
+
revert Revert database changes and migrations
|
|
26
|
+
|
|
27
|
+
Project Management:
|
|
28
|
+
init Initialize LaunchQL workspace or module
|
|
29
|
+
extension Manage module dependencies
|
|
30
|
+
plan Generate module deployment plans
|
|
31
|
+
package Package module for distribution
|
|
32
|
+
|
|
33
|
+
Development Tools:
|
|
34
|
+
server Start LaunchQL GraphQL server
|
|
35
|
+
explorer Launch GraphiQL explorer interface
|
|
36
|
+
export Export database migrations from existing databases
|
|
37
|
+
|
|
38
|
+
Database Administration:
|
|
39
|
+
kill Terminate database connections and optionally drop databases
|
|
40
|
+
install Install LaunchQL modules
|
|
41
|
+
tag Add tags to changes for versioning
|
|
42
|
+
|
|
43
|
+
Migration Tools:
|
|
44
|
+
migrate Migration management subcommands
|
|
45
|
+
init Initialize migration tracking
|
|
46
|
+
status Show migration status
|
|
47
|
+
list List all changes
|
|
48
|
+
deps Show change dependencies
|
|
49
|
+
|
|
50
|
+
Global Options:
|
|
51
|
+
-h, --help Display this help information
|
|
52
|
+
-v, --version Display version information
|
|
53
|
+
--cwd <directory> Working directory (default: current directory)
|
|
54
|
+
|
|
55
|
+
Individual Command Help:
|
|
56
|
+
lql <command> --help Display detailed help for specific command
|
|
57
|
+
lql <command> -h Display detailed help for specific command
|
|
58
|
+
|
|
59
|
+
Examples:
|
|
60
|
+
lql deploy --help Show deploy command options
|
|
61
|
+
lql server --port 8080 Start server on port 8080
|
|
62
|
+
lql init --workspace Initialize new workspace
|
|
63
|
+
`;
|
|
64
|
+
function displayUsage() {
|
|
65
|
+
console.log(exports.usageText);
|
|
66
|
+
}
|
package/utils/index.d.ts
ADDED
package/utils/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./argv"), exports);
|
|
18
|
+
__exportStar(require("./database"), exports);
|
|
19
|
+
__exportStar(require("./display"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Logger } from '@launchql/logger';
|
|
2
|
+
import { Inquirerer } from 'inquirerer';
|
|
3
|
+
import { ParsedArgs } from 'minimist';
|
|
4
|
+
/**
|
|
5
|
+
* Handle package selection for operations that need a specific package
|
|
6
|
+
* Returns the selected package name, or undefined if validation fails or no packages exist
|
|
7
|
+
*/
|
|
8
|
+
export declare function selectPackage(argv: Partial<ParsedArgs>, prompter: Inquirerer, cwd: string, operationName: string, log?: Logger): Promise<string | undefined>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectPackage = selectPackage;
|
|
4
|
+
const core_1 = require("@launchql/core");
|
|
5
|
+
const types_1 = require("@launchql/types");
|
|
6
|
+
/**
|
|
7
|
+
* Handle package selection for operations that need a specific package
|
|
8
|
+
* Returns the selected package name, or undefined if validation fails or no packages exist
|
|
9
|
+
*/
|
|
10
|
+
async function selectPackage(argv, prompter, cwd, operationName, log) {
|
|
11
|
+
const pkg = new core_1.LaunchQLPackage(cwd);
|
|
12
|
+
const modules = await pkg.getModules();
|
|
13
|
+
const moduleNames = modules.map(mod => mod.getModuleName());
|
|
14
|
+
// Check if any modules exist
|
|
15
|
+
if (!moduleNames.length) {
|
|
16
|
+
const errorMsg = 'No modules found in the specified directory.';
|
|
17
|
+
if (log) {
|
|
18
|
+
log.error(errorMsg);
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
prompter.close();
|
|
23
|
+
throw types_1.errors.NOT_FOUND({}, errorMsg);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// If a specific package was provided, validate it
|
|
27
|
+
if (argv.package) {
|
|
28
|
+
const packageName = argv.package;
|
|
29
|
+
if (log)
|
|
30
|
+
log.info(`Using specified package: ${packageName}`);
|
|
31
|
+
if (!moduleNames.includes(packageName)) {
|
|
32
|
+
const errorMsg = `Package '${packageName}' not found. Available packages: ${moduleNames.join(', ')}`;
|
|
33
|
+
if (log) {
|
|
34
|
+
log.error(errorMsg);
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw types_1.errors.NOT_FOUND({}, errorMsg);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return packageName;
|
|
42
|
+
}
|
|
43
|
+
// Interactive selection
|
|
44
|
+
const { package: selectedPackage } = await prompter.prompt(argv, [{
|
|
45
|
+
type: 'autocomplete',
|
|
46
|
+
name: 'package',
|
|
47
|
+
message: `Choose a package to ${operationName}`,
|
|
48
|
+
options: moduleNames,
|
|
49
|
+
required: true
|
|
50
|
+
}]);
|
|
51
|
+
if (log)
|
|
52
|
+
log.info(`Selected package: ${selectedPackage}`);
|
|
53
|
+
return selectedPackage;
|
|
54
|
+
}
|