@constructive-io/cli 0.0.3 → 5.1.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 (130) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +346 -153
  3. package/commands/{analyze.d.ts → codegen.d.ts} +2 -2
  4. package/commands/codegen.js +131 -0
  5. package/commands/explorer.js +94 -0
  6. package/commands/get-graphql-schema.js +73 -0
  7. package/commands/server.js +187 -0
  8. package/commands.d.ts +0 -1
  9. package/commands.js +42 -61
  10. package/esm/commands/codegen.js +126 -0
  11. package/esm/commands/explorer.js +92 -0
  12. package/esm/commands/get-graphql-schema.js +71 -0
  13. package/esm/commands/server.js +185 -0
  14. package/esm/commands.js +41 -59
  15. package/esm/index.js +16 -36
  16. package/esm/utils/display.js +26 -23
  17. package/esm/utils/index.js +3 -6
  18. package/index.d.ts +0 -22
  19. package/index.js +16 -72
  20. package/package.json +50 -25
  21. package/utils/display.d.ts +1 -1
  22. package/utils/display.js +26 -23
  23. package/utils/index.d.ts +3 -6
  24. package/utils/index.js +7 -20
  25. package/commands/add.d.ts +0 -7
  26. package/commands/add.js +0 -86
  27. package/commands/admin-users/add.d.ts +0 -4
  28. package/commands/admin-users/add.js +0 -89
  29. package/commands/admin-users/bootstrap.d.ts +0 -4
  30. package/commands/admin-users/bootstrap.js +0 -50
  31. package/commands/admin-users/remove.d.ts +0 -4
  32. package/commands/admin-users/remove.js +0 -82
  33. package/commands/admin-users.d.ts +0 -4
  34. package/commands/admin-users.js +0 -68
  35. package/commands/analyze.js +0 -21
  36. package/commands/clear.d.ts +0 -3
  37. package/commands/clear.js +0 -59
  38. package/commands/deploy.d.ts +0 -4
  39. package/commands/deploy.js +0 -146
  40. package/commands/docker.d.ts +0 -3
  41. package/commands/docker.js +0 -194
  42. package/commands/env.d.ts +0 -4
  43. package/commands/env.js +0 -124
  44. package/commands/export.js +0 -129
  45. package/commands/extension.js +0 -48
  46. package/commands/init/index.d.ts +0 -7
  47. package/commands/init/index.js +0 -47
  48. package/commands/init/module.d.ts +0 -4
  49. package/commands/init/module.js +0 -71
  50. package/commands/init/workspace.d.ts +0 -4
  51. package/commands/init/workspace.js +0 -52
  52. package/commands/install.d.ts +0 -4
  53. package/commands/install.js +0 -37
  54. package/commands/kill.js +0 -107
  55. package/commands/migrate/deps.d.ts +0 -4
  56. package/commands/migrate/deps.js +0 -186
  57. package/commands/migrate/init.d.ts +0 -4
  58. package/commands/migrate/init.js +0 -65
  59. package/commands/migrate/list.d.ts +0 -4
  60. package/commands/migrate/list.js +0 -85
  61. package/commands/migrate/status.d.ts +0 -4
  62. package/commands/migrate/status.js +0 -94
  63. package/commands/migrate.d.ts +0 -4
  64. package/commands/migrate.js +0 -69
  65. package/commands/package.d.ts +0 -3
  66. package/commands/package.js +0 -65
  67. package/commands/plan.d.ts +0 -3
  68. package/commands/plan.js +0 -62
  69. package/commands/remove.d.ts +0 -3
  70. package/commands/remove.js +0 -42
  71. package/commands/rename.d.ts +0 -4
  72. package/commands/rename.js +0 -35
  73. package/commands/revert.d.ts +0 -3
  74. package/commands/revert.js +0 -107
  75. package/commands/tag.d.ts +0 -6
  76. package/commands/tag.js +0 -168
  77. package/commands/verify.d.ts +0 -3
  78. package/commands/verify.js +0 -85
  79. package/dist/README.md +0 -412
  80. package/dist/package.json +0 -64
  81. package/esm/commands/add.js +0 -51
  82. package/esm/commands/admin-users/add.js +0 -87
  83. package/esm/commands/admin-users/bootstrap.js +0 -48
  84. package/esm/commands/admin-users/remove.js +0 -80
  85. package/esm/commands/admin-users.js +0 -63
  86. package/esm/commands/analyze.js +0 -16
  87. package/esm/commands/clear.js +0 -54
  88. package/esm/commands/deploy.js +0 -144
  89. package/esm/commands/docker.js +0 -192
  90. package/esm/commands/env.js +0 -122
  91. package/esm/commands/export.js +0 -127
  92. package/esm/commands/extension.js +0 -46
  93. package/esm/commands/init/index.js +0 -42
  94. package/esm/commands/init/module.js +0 -68
  95. package/esm/commands/init/workspace.js +0 -46
  96. package/esm/commands/install.js +0 -35
  97. package/esm/commands/kill.js +0 -105
  98. package/esm/commands/migrate/deps.js +0 -184
  99. package/esm/commands/migrate/init.js +0 -63
  100. package/esm/commands/migrate/list.js +0 -83
  101. package/esm/commands/migrate/status.js +0 -92
  102. package/esm/commands/migrate.js +0 -64
  103. package/esm/commands/package.js +0 -63
  104. package/esm/commands/plan.js +0 -60
  105. package/esm/commands/remove.js +0 -40
  106. package/esm/commands/rename.js +0 -30
  107. package/esm/commands/revert.js +0 -105
  108. package/esm/commands/tag.js +0 -133
  109. package/esm/commands/verify.js +0 -83
  110. package/esm/package.js +0 -26
  111. package/esm/utils/argv.js +0 -92
  112. package/esm/utils/cli-error.js +0 -48
  113. package/esm/utils/database.js +0 -78
  114. package/esm/utils/deployed-changes.js +0 -68
  115. package/esm/utils/module-utils.js +0 -51
  116. package/package.d.ts +0 -1
  117. package/package.js +0 -29
  118. package/utils/argv.d.ts +0 -46
  119. package/utils/argv.js +0 -100
  120. package/utils/cli-error.d.ts +0 -8
  121. package/utils/cli-error.js +0 -52
  122. package/utils/database.d.ts +0 -21
  123. package/utils/database.js +0 -83
  124. package/utils/deployed-changes.d.ts +0 -4
  125. package/utils/deployed-changes.js +0 -72
  126. package/utils/module-utils.d.ts +0 -8
  127. package/utils/module-utils.js +0 -54
  128. /package/commands/{export.d.ts → explorer.d.ts} +0 -0
  129. /package/commands/{extension.d.ts → get-graphql-schema.d.ts} +0 -0
  130. /package/commands/{kill.d.ts → server.d.ts} +0 -0
@@ -1,52 +0,0 @@
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.default = runWorkspaceSetup;
7
- const core_1 = require("@launchql/core");
8
- const logger_1 = require("@launchql/logger");
9
- // @ts-ignore - TypeScript module resolution issue with @launchql/templatizer
10
- const templatizer_1 = require("@launchql/templatizer");
11
- const fs_1 = require("fs");
12
- const path_1 = __importDefault(require("path"));
13
- const log = new logger_1.Logger('workspace-init');
14
- async function runWorkspaceSetup(argv, prompter) {
15
- const workspaceQuestions = [
16
- {
17
- name: 'name',
18
- message: 'Enter workspace name',
19
- required: true,
20
- type: 'text',
21
- }
22
- ];
23
- const answers = await prompter.prompt(argv, workspaceQuestions);
24
- const { cwd } = argv;
25
- const targetPath = path_1.default.join(cwd, (0, core_1.sluggify)(answers.name));
26
- (0, fs_1.mkdirSync)(targetPath, { recursive: true });
27
- log.success(`Created workspace directory: ${targetPath}`);
28
- // Determine template source
29
- let templates = templatizer_1.workspaceTemplate;
30
- if (argv.repo) {
31
- const source = {
32
- type: 'github',
33
- path: argv.repo,
34
- branch: argv.fromBranch
35
- };
36
- log.info(`Loading templates from GitHub repository: ${argv.repo}`);
37
- const compiledTemplates = (0, templatizer_1.loadTemplates)(source, 'workspace');
38
- templates = compiledTemplates.map((t) => t.render);
39
- }
40
- else if (argv.templatePath) {
41
- const source = {
42
- type: 'local',
43
- path: argv.templatePath
44
- };
45
- log.info(`Loading templates from local path: ${argv.templatePath}`);
46
- const compiledTemplates = (0, templatizer_1.loadTemplates)(source, 'workspace');
47
- templates = compiledTemplates.map((t) => t.render);
48
- }
49
- (0, templatizer_1.writeRenderedTemplates)(templates, targetPath, { ...argv, ...answers });
50
- log.success('Workspace templates rendered.');
51
- return { ...argv, ...answers, cwd: targetPath };
52
- }
@@ -1,4 +0,0 @@
1
- import { CLIOptions, Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- declare const _default: (argv: Partial<ParsedArgs>, prompter: Inquirerer, _options: CLIOptions) => Promise<void>;
4
- export default _default;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@launchql/core");
4
- const installUsageText = `
5
- Install Command:
6
-
7
- constructive install <package>...
8
-
9
- Install database modules into current module.
10
-
11
- Arguments:
12
- package One or more package names to install
13
-
14
- Options:
15
- --help, -h Show this help message
16
- --cwd <directory> Working directory (default: current directory)
17
-
18
- Examples:
19
- constructive install @pgpm/base32 Install single package
20
- constructive install @pgpm/base32 @pgpm/utils Install multiple packages
21
- `;
22
- exports.default = async (argv, prompter, _options) => {
23
- // Show usage if explicitly requested
24
- if (argv.help || argv.h) {
25
- console.log(installUsageText);
26
- process.exit(0);
27
- }
28
- const { cwd = process.cwd() } = argv;
29
- const project = new core_1.LaunchQLPackage(cwd);
30
- if (!project.isInModule()) {
31
- throw new Error('You must run this command inside a LaunchQL module.');
32
- }
33
- if (argv._.length === 0) {
34
- throw new Error('You must provide a package name to install, e.g. `@pgpm/base32`');
35
- }
36
- await project.installModules(...argv._);
37
- };
package/commands/kill.js DELETED
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const logger_1 = require("@launchql/logger");
4
- const pg_cache_1 = require("pg-cache");
5
- const log = new logger_1.Logger('db-kill');
6
- const killUsageText = `
7
- Kill Command:
8
-
9
- constructive kill [OPTIONS]
10
-
11
- Terminate database connections and optionally drop databases.
12
-
13
- Options:
14
- --help, -h Show this help message
15
- --drop Drop databases after killing connections (default: true)
16
- --no-drop Only kill connections, don't drop databases
17
- --pattern <pattern> Pattern to match database names (supports SQL LIKE syntax)
18
- --cwd <directory> Working directory (default: current directory)
19
-
20
- Examples:
21
- constructive kill Kill connections and drop selected databases (interactive)
22
- constructive kill --no-drop Only kill connections, preserve databases (interactive)
23
- constructive kill --pattern test_% Kill connections to databases matching 'test_%' pattern
24
- constructive kill --pattern %dev --no-drop Kill connections to databases ending with 'dev' but don't drop
25
- `;
26
- exports.default = async (argv, prompter, _options) => {
27
- // Show usage if explicitly requested
28
- if (argv.help || argv.h) {
29
- console.log(killUsageText);
30
- process.exit(0);
31
- }
32
- const db = await (0, pg_cache_1.getPgPool)({
33
- database: 'postgres'
34
- });
35
- let selectedDbNames;
36
- if (argv.pattern) {
37
- // Pattern mode: automatically find databases matching the pattern
38
- const databasesResult = await db.query(`
39
- SELECT datname FROM pg_catalog.pg_database
40
- WHERE datistemplate = FALSE AND datname NOT IN ('postgres')
41
- AND datname !~ '^pg_' AND datname LIKE $1;
42
- `, [argv.pattern]);
43
- if (!databasesResult.rows.length) {
44
- log.info(`ℹ️ No databases found matching pattern "${argv.pattern}". Exiting.`);
45
- return;
46
- }
47
- selectedDbNames = databasesResult.rows.map(row => row.datname);
48
- log.info(`🎯 Found ${selectedDbNames.length} database(s) matching pattern "${argv.pattern}": ${selectedDbNames.join(', ')}`);
49
- }
50
- else {
51
- // Interactive mode: prompt user to select databases
52
- const databasesResult = await db.query(`
53
- SELECT datname FROM pg_catalog.pg_database
54
- WHERE datistemplate = FALSE AND datname NOT IN ('postgres')
55
- AND datname !~ '^pg_';
56
- `);
57
- if (!databasesResult.rows.length) {
58
- log.info('ℹ️ No databases found to process. Exiting.');
59
- return;
60
- }
61
- let databases;
62
- ({ databases } = await prompter.prompt(argv, [
63
- {
64
- type: 'checkbox',
65
- name: 'databases',
66
- message: 'Select database(s) to terminate connections and optionally drop',
67
- options: databasesResult.rows.map(row => row.datname),
68
- required: true
69
- }
70
- ]));
71
- selectedDbNames = databases.filter(d => d.selected).map(d => d.value);
72
- }
73
- const actionText = argv.drop === false ? 'kill connections to' : 'kill connections and DROP';
74
- const patternText = argv.pattern ? ` (matched by pattern "${argv.pattern}")` : '';
75
- const { yes } = await prompter.prompt(argv, [
76
- {
77
- type: 'confirm',
78
- name: 'yes',
79
- message: `Are you sure you want to ${actionText}: ${selectedDbNames.join(', ')}${patternText}?`,
80
- default: false
81
- }
82
- ]);
83
- if (!yes) {
84
- log.info('❌ Aborted. No actions were taken.');
85
- return;
86
- }
87
- for (const dbname of selectedDbNames) {
88
- const killResult = await db.query(`
89
- SELECT pg_terminate_backend(pid)
90
- FROM pg_stat_activity
91
- WHERE datname = $1 AND pid <> pg_backend_pid();
92
- `, [dbname]);
93
- log.warn(`💀 Terminated ${killResult.rowCount} connection(s) to "${dbname}".`);
94
- if (argv.drop === false) {
95
- log.info(`⚠️ Skipping DROP for "${dbname}" due to --no-drop flag.`);
96
- continue;
97
- }
98
- try {
99
- await db.query(`DROP DATABASE "${dbname}";`);
100
- log.success(`🗑️ Dropped database "${dbname}" successfully.`);
101
- }
102
- catch (err) {
103
- log.error(`❌ Failed to drop "${dbname}": ${err.message}`);
104
- }
105
- }
106
- log.success('✅ Done processing databases.');
107
- };
@@ -1,4 +0,0 @@
1
- import { CLIOptions, Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- declare const _default: (argv: Partial<ParsedArgs>, prompter: Inquirerer, options: CLIOptions) => Promise<void>;
4
- export default _default;
@@ -1,186 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@launchql/core");
4
- const core_2 = require("@launchql/core");
5
- const logger_1 = require("@launchql/logger");
6
- const fs_1 = require("fs");
7
- const path_1 = require("path");
8
- const pg_env_1 = require("pg-env");
9
- const database_1 = require("../../utils/database");
10
- const log = new logger_1.Logger('migrate-deps');
11
- exports.default = async (argv, prompter, options) => {
12
- const cwd = argv.cwd || process.cwd();
13
- const planPath = (0, path_1.join)(cwd, 'pgpm.plan');
14
- if (!(0, fs_1.existsSync)(planPath)) {
15
- log.error(`No pgpm.plan found in ${cwd}`);
16
- process.exit(1);
17
- }
18
- // Get specific change to analyze
19
- let changeName = argv._?.[0] || argv.change;
20
- const planResult = (0, core_2.parsePlanFile)(planPath);
21
- if (!planResult.data || planResult.errors.length > 0) {
22
- log.error('Failed to parse plan file:', planResult.errors);
23
- process.exit(1);
24
- }
25
- const plan = planResult.data;
26
- const allChanges = plan.changes;
27
- // If no change specified, prompt
28
- if (!changeName && !argv.all) {
29
- const answer = await prompter.prompt(argv, [
30
- {
31
- type: 'autocomplete',
32
- name: 'change',
33
- message: 'Which change do you want to analyze?',
34
- options: allChanges.map(c => ({
35
- name: c.name,
36
- value: c.name,
37
- description: c.dependencies.length > 0 ? `Depends on: ${c.dependencies.join(', ')}` : 'No dependencies'
38
- }))
39
- }
40
- ]);
41
- changeName = answer.change;
42
- }
43
- try {
44
- if (argv.all) {
45
- // Show dependency graph for all changes
46
- console.log('\n🔗 Dependency Graph\n');
47
- console.log(`Package: ${plan.package}`);
48
- console.log(`Total Changes: ${allChanges.length}\n`);
49
- // Build dependency tree
50
- const dependencyTree = buildDependencyTree(allChanges);
51
- // Show changes with no dependencies first (roots)
52
- const roots = allChanges.filter(c => c.dependencies.length === 0);
53
- console.log('📌 Root Changes (no dependencies):\n');
54
- roots.forEach(change => {
55
- console.log(` • ${change.name}`);
56
- showDependents(change.name, dependencyTree, ' ');
57
- });
58
- // Show orphaned changes (have dependencies but aren't depended on)
59
- const orphans = allChanges.filter(c => c.dependencies.length > 0 &&
60
- !allChanges.some(other => other.dependencies.includes(c.name)));
61
- if (orphans.length > 0) {
62
- console.log('\n🔸 Leaf Changes (not depended on by others):\n');
63
- orphans.forEach(change => {
64
- console.log(` • ${change.name} → [${change.dependencies.join(', ')}]`);
65
- });
66
- }
67
- }
68
- else {
69
- // Show dependencies for specific change
70
- const change = allChanges.find(c => c.name === changeName);
71
- if (!change) {
72
- log.error(`Change '${changeName}' not found in plan file`);
73
- process.exit(1);
74
- }
75
- console.log(`\n🔍 Dependency Analysis: ${changeName}\n`);
76
- // Direct dependencies
77
- if (change.dependencies.length > 0) {
78
- console.log('📥 Direct Dependencies:');
79
- change.dependencies.forEach(dep => {
80
- console.log(` • ${dep}`);
81
- });
82
- }
83
- else {
84
- console.log('📥 Direct Dependencies: None');
85
- }
86
- // All dependencies (recursive)
87
- const allDeps = getAllDependencies(change.name, allChanges);
88
- if (allDeps.size > 0) {
89
- console.log(`\n📦 All Dependencies (${allDeps.size} total):`);
90
- Array.from(allDeps).forEach(dep => {
91
- console.log(` • ${dep}`);
92
- });
93
- }
94
- // Dependents (what depends on this)
95
- const dependents = allChanges.filter(c => c.dependencies.includes(changeName));
96
- if (dependents.length > 0) {
97
- console.log(`\n📤 Depended on by (${dependents.length} changes):`);
98
- dependents.forEach(dep => {
99
- console.log(` • ${dep.name}`);
100
- });
101
- }
102
- else {
103
- console.log('\n📤 Depended on by: None');
104
- }
105
- // Check deployment status if connected to database
106
- const pgEnv = (0, pg_env_1.getPgEnvOptions)();
107
- const targetDatabase = await (0, database_1.getTargetDatabase)(argv, prompter, {
108
- message: 'Select database to check deployment status'
109
- });
110
- const client = new core_1.LaunchQLMigrate({
111
- host: pgEnv.host,
112
- port: pgEnv.port,
113
- user: pgEnv.user,
114
- password: pgEnv.password,
115
- database: pgEnv.database
116
- });
117
- try {
118
- const deployedChanges = await client.getDeployedChanges(targetDatabase, plan.package);
119
- const deployedMap = new Map(deployedChanges.map(c => [c.change_name, c]));
120
- console.log('\n📊 Deployment Status:');
121
- // Check if this change is deployed
122
- const isDeployed = deployedMap.has(changeName);
123
- console.log(` This change: ${isDeployed ? '✅ Deployed' : '⏳ Not deployed'}`);
124
- // Check dependencies
125
- const undeployedDeps = Array.from(allDeps).filter(dep => !deployedMap.has(dep));
126
- if (undeployedDeps.length > 0) {
127
- console.log(` ⚠️ Undeployed dependencies: ${undeployedDeps.join(', ')}`);
128
- }
129
- else if (allDeps.size > 0) {
130
- console.log(' ✅ All dependencies deployed');
131
- }
132
- // Check dependents
133
- const deployedDependents = dependents.filter(d => deployedMap.has(d.name));
134
- if (deployedDependents.length > 0) {
135
- console.log(` ⚠️ Deployed dependents: ${deployedDependents.map(d => d.name).join(', ')}`);
136
- }
137
- }
138
- catch (dbError) {
139
- // Database connection optional for dependency analysis
140
- log.debug('Could not connect to database for deployment status');
141
- }
142
- }
143
- }
144
- catch (error) {
145
- log.error('Failed to analyze dependencies:', error);
146
- process.exit(1);
147
- }
148
- };
149
- function buildDependencyTree(changes) {
150
- const tree = new Map();
151
- changes.forEach(change => {
152
- change.dependencies.forEach((dep) => {
153
- if (!tree.has(dep)) {
154
- tree.set(dep, []);
155
- }
156
- tree.get(dep).push(change.name);
157
- });
158
- });
159
- return tree;
160
- }
161
- function showDependents(changeName, tree, indent) {
162
- const dependents = tree.get(changeName) || [];
163
- dependents.forEach(dep => {
164
- console.log(`${indent}└─ ${dep}`);
165
- showDependents(dep, tree, indent + ' ');
166
- });
167
- }
168
- function getAllDependencies(changeName, changes) {
169
- const deps = new Set();
170
- const change = changes.find(c => c.name === changeName);
171
- if (!change)
172
- return deps;
173
- function addDeps(change) {
174
- change.dependencies.forEach((dep) => {
175
- if (!deps.has(dep)) {
176
- deps.add(dep);
177
- const depChange = changes.find(c => c.name === dep);
178
- if (depChange) {
179
- addDeps(depChange);
180
- }
181
- }
182
- });
183
- }
184
- addDeps(change);
185
- return deps;
186
- }
@@ -1,4 +0,0 @@
1
- import { CLIOptions, Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- declare const _default: (argv: Partial<ParsedArgs>, prompter: Inquirerer, _options: CLIOptions) => Promise<Partial<ParsedArgs>>;
4
- export default _default;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@launchql/core");
4
- const logger_1 = require("@launchql/logger");
5
- const pg_env_1 = require("pg-env");
6
- const database_1 = require("../../utils/database");
7
- const log = new logger_1.Logger('migrate-init');
8
- exports.default = async (argv, prompter, _options) => {
9
- const pgEnv = (0, pg_env_1.getPgEnvOptions)();
10
- // Get target database
11
- const database = await (0, database_1.getTargetDatabase)(argv, prompter, {
12
- message: 'Select database to initialize migration tracking'
13
- });
14
- const questions = [
15
- {
16
- name: 'yes',
17
- type: 'confirm',
18
- message: `Initialize constructive migration schema in database "${database}"?`,
19
- required: true
20
- }
21
- ];
22
- const { yes } = await prompter.prompt(argv, questions);
23
- if (!yes) {
24
- log.info('Operation cancelled.');
25
- return;
26
- }
27
- log.info(`Initializing migration schema in database ${database}...`);
28
- const config = {
29
- host: pgEnv.host,
30
- port: pgEnv.port,
31
- user: pgEnv.user,
32
- password: pgEnv.password,
33
- database
34
- };
35
- const client = new core_1.LaunchQLMigrate(config);
36
- try {
37
- await client.initialize();
38
- log.success('Migration schema initialized successfully.');
39
- // Check if there's an existing Sqitch deployment to import
40
- const hasSquitch = await client.hasSqitchTables();
41
- if (hasSquitch) {
42
- const { importSquitch } = await prompter.prompt(argv, [
43
- {
44
- name: 'importSquitch',
45
- type: 'confirm',
46
- message: 'Existing Sqitch deployment detected. Import it?',
47
- required: true
48
- }
49
- ]);
50
- if (importSquitch) {
51
- log.info('Importing Sqitch deployment history...');
52
- await client.importFromSqitch();
53
- log.success('Sqitch deployment imported successfully.');
54
- }
55
- }
56
- }
57
- catch (error) {
58
- log.error(`Failed to initialize migration schema: ${error instanceof Error ? error.message : error}`);
59
- throw error;
60
- }
61
- finally {
62
- await client.close();
63
- }
64
- return argv;
65
- };
@@ -1,4 +0,0 @@
1
- import { CLIOptions, Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- declare const _default: (argv: Partial<ParsedArgs>, prompter: Inquirerer, options: CLIOptions) => Promise<void>;
4
- export default _default;
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@launchql/core");
4
- const core_2 = require("@launchql/core");
5
- const logger_1 = require("@launchql/logger");
6
- const fs_1 = require("fs");
7
- const path_1 = require("path");
8
- const pg_env_1 = require("pg-env");
9
- const database_1 = require("../../utils/database");
10
- const log = new logger_1.Logger('migrate-list');
11
- exports.default = async (argv, prompter, options) => {
12
- const cwd = argv.cwd || process.cwd();
13
- const planPath = (0, path_1.join)(cwd, 'pgpm.plan');
14
- if (!(0, fs_1.existsSync)(planPath)) {
15
- log.error(`No pgpm.plan found in ${cwd}`);
16
- process.exit(1);
17
- }
18
- // Get database configuration
19
- const pgEnv = (0, pg_env_1.getPgEnvOptions)();
20
- const targetDatabase = await (0, database_1.getTargetDatabase)(argv, prompter, {
21
- message: 'Select database to list migrations'
22
- });
23
- const client = new core_1.LaunchQLMigrate({
24
- host: pgEnv.host,
25
- port: pgEnv.port,
26
- user: pgEnv.user,
27
- password: pgEnv.password,
28
- database: pgEnv.database
29
- });
30
- try {
31
- // Get all changes from plan file
32
- const planResult = (0, core_2.parsePlanFile)(planPath);
33
- if (!planResult.data || planResult.errors.length > 0) {
34
- log.error('Failed to parse plan file:', planResult.errors);
35
- process.exit(1);
36
- }
37
- const plan = planResult.data;
38
- const allChanges = plan.changes;
39
- // Get deployed changes from database
40
- const deployedChanges = await client.getDeployedChanges(targetDatabase, plan.package);
41
- console.log('\n📋 All Changes\n');
42
- console.log(`Package: ${plan.package}`);
43
- console.log(`Total Changes: ${allChanges.length}`);
44
- console.log(`Deployed: ${deployedChanges.length}`);
45
- console.log(`Pending: ${allChanges.length - deployedChanges.length}\n`);
46
- // Create a map for quick lookup
47
- const deployedMap = new Map(deployedChanges.map(c => [c.change_name, c]));
48
- // List all changes with their status
49
- const showAll = argv.all || allChanges.length <= 20;
50
- const changesToShow = showAll ? allChanges : allChanges.slice(0, 20);
51
- console.log('Status Change Name Dependencies');
52
- console.log('------ ----------------------------- --------------------------------');
53
- changesToShow.forEach(change => {
54
- const deployed = deployedMap.get(change.name);
55
- const status = deployed ? '✅' : '⏳';
56
- const deps = change.dependencies.length > 0 ? change.dependencies.join(', ') : '-';
57
- const depsDisplay = deps.length > 30 ? deps.substring(0, 27) + '...' : deps;
58
- console.log(`${status} ${change.name.padEnd(30)} ${depsDisplay}`);
59
- });
60
- if (!showAll && allChanges.length > 20) {
61
- console.log(`\n... and ${allChanges.length - 20} more changes. Use --all to see all changes.`);
62
- }
63
- // Show summary by status
64
- if (argv.summary !== false) {
65
- console.log('\n📊 Summary by Status:\n');
66
- const pending = allChanges.filter(c => !deployedMap.has(c.name));
67
- const deployed = allChanges.filter(c => deployedMap.has(c.name));
68
- console.log(`✅ Deployed: ${deployed.length}`);
69
- console.log(`⏳ Pending: ${pending.length}`);
70
- // Show deployment timeline
71
- if (deployedChanges.length > 0) {
72
- const sortedDeployed = [...deployedChanges].sort((a, b) => new Date(a.deployed_at).getTime() - new Date(b.deployed_at).getTime());
73
- const firstDeploy = new Date(sortedDeployed[0].deployed_at);
74
- const lastDeploy = new Date(sortedDeployed[sortedDeployed.length - 1].deployed_at);
75
- console.log(`\n📅 Deployment Timeline:`);
76
- console.log(` First: ${firstDeploy.toLocaleString()}`);
77
- console.log(` Last: ${lastDeploy.toLocaleString()}`);
78
- }
79
- }
80
- }
81
- catch (error) {
82
- log.error('Failed to list changes:', error);
83
- process.exit(1);
84
- }
85
- };
@@ -1,4 +0,0 @@
1
- import { CLIOptions, Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- declare const _default: (argv: Partial<ParsedArgs>, prompter: Inquirerer, options: CLIOptions) => Promise<void>;
4
- export default _default;
@@ -1,94 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@launchql/core");
4
- const core_2 = require("@launchql/core");
5
- const logger_1 = require("@launchql/logger");
6
- const fs_1 = require("fs");
7
- const path_1 = require("path");
8
- const pg_env_1 = require("pg-env");
9
- const database_1 = require("../../utils/database");
10
- const log = new logger_1.Logger('migrate-status');
11
- exports.default = async (argv, prompter, options) => {
12
- const cwd = argv.cwd || process.cwd();
13
- const planPath = (0, path_1.join)(cwd, 'pgpm.plan');
14
- if (!(0, fs_1.existsSync)(planPath)) {
15
- log.error(`No pgpm.plan found in ${cwd}`);
16
- process.exit(1);
17
- }
18
- // Get database configuration
19
- const pgEnv = (0, pg_env_1.getPgEnvOptions)();
20
- const targetDatabase = await (0, database_1.getTargetDatabase)(argv, prompter, {
21
- message: 'Select database to check migration status'
22
- });
23
- const client = new core_1.LaunchQLMigrate({
24
- host: pgEnv.host,
25
- port: pgEnv.port,
26
- user: pgEnv.user,
27
- password: pgEnv.password,
28
- database: pgEnv.database
29
- });
30
- try {
31
- // Parse plan file to get package name
32
- const planResult = (0, core_2.parsePlanFile)(planPath);
33
- if (!planResult.data || planResult.errors.length > 0) {
34
- log.error('Failed to parse plan file:', planResult.errors);
35
- process.exit(1);
36
- }
37
- const plan = planResult.data;
38
- // Switch to target database
39
- const targetClient = new core_1.LaunchQLMigrate({
40
- host: pgEnv.host,
41
- port: pgEnv.port,
42
- user: pgEnv.user,
43
- password: pgEnv.password,
44
- database: targetDatabase
45
- });
46
- const statusResults = await targetClient.status(plan.package);
47
- console.log('\n📊 Migration Status\n');
48
- console.log(`Database: ${targetDatabase}`);
49
- if (statusResults.length > 0) {
50
- const status = statusResults[0];
51
- console.log(`Package: ${status.package}`);
52
- console.log(`Total Deployed: ${status.totalDeployed}`);
53
- if (status.lastChange) {
54
- console.log(`Last Change: ${status.lastChange}`);
55
- console.log(`Last Deployed: ${status.lastDeployed.toLocaleString()}`);
56
- }
57
- else {
58
- console.log('No changes deployed yet');
59
- }
60
- }
61
- else {
62
- console.log(`Package: ${plan.package}`);
63
- console.log('No deployment history found');
64
- }
65
- // Show recent changes
66
- const recentChanges = await targetClient.getRecentChanges(targetDatabase, 5);
67
- if (recentChanges.length > 0) {
68
- console.log('\n📋 Recent Changes:\n');
69
- recentChanges.forEach((change) => {
70
- const status = change.deployed_at ? '✅' : '⏳';
71
- const date = change.deployed_at ? new Date(change.deployed_at).toLocaleString() : 'Not deployed';
72
- console.log(`${status} ${change.change_name.padEnd(30)} ${date}`);
73
- });
74
- }
75
- // Show pending changes
76
- const pendingChanges = await targetClient.getPendingChanges(planPath, targetDatabase);
77
- if (pendingChanges.length > 0) {
78
- console.log(`\n⏳ Pending Changes: ${pendingChanges.length}\n`);
79
- pendingChanges.slice(0, 5).forEach((change) => {
80
- console.log(` - ${change}`);
81
- });
82
- if (pendingChanges.length > 5) {
83
- console.log(` ... and ${pendingChanges.length - 5} more`);
84
- }
85
- }
86
- else {
87
- console.log('\n✅ All changes deployed');
88
- }
89
- }
90
- catch (error) {
91
- log.error('Failed to get migration status:', error);
92
- process.exit(1);
93
- }
94
- };
@@ -1,4 +0,0 @@
1
- import { CLIOptions, Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- declare const _default: (argv: Partial<ParsedArgs>, prompter: Inquirerer, options: CLIOptions) => Promise<void>;
4
- export default _default;