relq 1.0.1 → 1.0.3
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/dist/cjs/addon/buffer/index.cjs +1881 -0
- package/dist/cjs/addon/pg/index.cjs +4812 -0
- package/dist/cjs/addon/pg-cursor/index.cjs +1451 -0
- package/dist/cjs/addon/pg-format/index.cjs +2270 -0
- package/dist/cjs/cli/commands/add.cjs +430 -25
- package/dist/cjs/cli/commands/branch.cjs +131 -0
- package/dist/cjs/cli/commands/checkout.cjs +121 -0
- package/dist/cjs/cli/commands/cherry-pick.cjs +282 -0
- package/dist/cjs/cli/commands/commit.cjs +21 -29
- package/dist/cjs/cli/commands/diff.cjs +144 -69
- package/dist/cjs/cli/commands/export.cjs +70 -11
- package/dist/cjs/cli/commands/fetch.cjs +42 -18
- package/dist/cjs/cli/commands/generate.cjs +28 -54
- package/dist/cjs/cli/commands/history.cjs +19 -40
- package/dist/cjs/cli/commands/import.cjs +305 -41
- package/dist/cjs/cli/commands/init.cjs +69 -59
- package/dist/cjs/cli/commands/introspect.cjs +4 -8
- package/dist/cjs/cli/commands/log.cjs +84 -15
- package/dist/cjs/cli/commands/merge.cjs +207 -0
- package/dist/cjs/cli/commands/migrate.cjs +13 -26
- package/dist/cjs/cli/commands/pull.cjs +321 -95
- package/dist/cjs/cli/commands/push.cjs +228 -52
- package/dist/cjs/cli/commands/remote.cjs +17 -0
- package/dist/cjs/cli/commands/reset.cjs +148 -0
- package/dist/cjs/cli/commands/resolve.cjs +191 -0
- package/dist/cjs/cli/commands/rollback.cjs +17 -39
- package/dist/cjs/cli/commands/stash.cjs +152 -0
- package/dist/cjs/cli/commands/status.cjs +52 -9
- package/dist/cjs/cli/commands/sync.cjs +30 -50
- package/dist/cjs/cli/commands/tag.cjs +146 -0
- package/dist/cjs/cli/index.cjs +117 -10
- package/dist/cjs/cli/utils/change-tracker.cjs +107 -3
- package/dist/cjs/cli/utils/cli-utils.cjs +217 -0
- package/dist/cjs/cli/utils/commit-manager.cjs +3 -3
- package/dist/cjs/cli/utils/config-loader.cjs +34 -8
- package/dist/cjs/cli/utils/env-loader.cjs +3 -2
- package/dist/cjs/cli/utils/fast-introspect.cjs +110 -4
- package/dist/cjs/cli/utils/git-utils.cjs +42 -161
- package/dist/cjs/cli/utils/pool-manager.cjs +156 -0
- package/dist/cjs/cli/utils/project-root.cjs +107 -0
- package/dist/cjs/cli/utils/relqignore.cjs +297 -38
- package/dist/cjs/cli/utils/repo-manager.cjs +92 -3
- package/dist/cjs/cli/utils/schema-comparator.cjs +301 -11
- package/dist/cjs/cli/utils/schema-diff.cjs +202 -1
- package/dist/cjs/cli/utils/schema-hash.cjs +2 -1
- package/dist/cjs/cli/utils/schema-introspect.cjs +9 -5
- package/dist/cjs/cli/utils/snapshot-manager.cjs +1 -0
- package/dist/cjs/cli/utils/spinner.cjs +14 -106
- package/dist/cjs/cli/utils/sql-generator.cjs +2 -2
- package/dist/cjs/cli/utils/sql-parser.cjs +94 -7
- package/dist/cjs/cli/utils/type-generator.cjs +28 -16
- package/dist/cjs/condition/array-condition-builder.cjs +1 -1
- package/dist/cjs/condition/condition-collector.cjs +1 -1
- package/dist/cjs/condition/fulltext-condition-builder.cjs +1 -1
- package/dist/cjs/condition/geometric-condition-builder.cjs +1 -1
- package/dist/cjs/condition/jsonb-condition-builder.cjs +1 -1
- package/dist/cjs/condition/network-condition-builder.cjs +1 -1
- package/dist/cjs/condition/range-condition-builder.cjs +1 -1
- package/dist/cjs/copy/copy-builder.cjs +1 -1
- package/dist/cjs/core/query-builder.cjs +1 -1
- package/dist/cjs/core/relq-client.cjs +2 -2
- package/dist/cjs/count/count-builder.cjs +1 -1
- package/dist/cjs/cte/cte-builder.cjs +1 -1
- package/dist/cjs/delete/delete-builder.cjs +1 -1
- package/dist/cjs/function/create-function-builder.cjs +1 -1
- package/dist/cjs/functions/advanced-functions.cjs +1 -1
- package/dist/cjs/functions/case-builder.cjs +1 -1
- package/dist/cjs/functions/geometric-functions.cjs +1 -1
- package/dist/cjs/functions/network-functions.cjs +1 -1
- package/dist/cjs/functions/sql-functions.cjs +1 -1
- package/dist/cjs/indexing/create-index-builder.cjs +1 -1
- package/dist/cjs/indexing/drop-index-builder.cjs +1 -1
- package/dist/cjs/insert/conflict-builder.cjs +1 -1
- package/dist/cjs/insert/insert-builder.cjs +1 -1
- package/dist/cjs/maintenance/vacuum-builder.cjs +1 -1
- package/dist/cjs/pubsub/listen-notify-builder.cjs +1 -1
- package/dist/cjs/pubsub/listener-connection.cjs +2 -2
- package/dist/cjs/raw/raw-query-builder.cjs +1 -1
- package/dist/cjs/schema/schema-builder.cjs +1 -1
- package/dist/cjs/schema-definition/table-definition.cjs +1 -1
- package/dist/cjs/select/aggregate-builder.cjs +1 -1
- package/dist/cjs/select/select-builder.cjs +1 -1
- package/dist/cjs/sequence/sequence-builder.cjs +1 -1
- package/dist/cjs/table/alter-table-builder.cjs +1 -1
- package/dist/cjs/table/constraint-builder.cjs +1 -1
- package/dist/cjs/table/create-table-builder.cjs +1 -1
- package/dist/cjs/table/partition-builder.cjs +1 -1
- package/dist/cjs/table/truncate-builder.cjs +1 -1
- package/dist/cjs/transaction/transaction-builder.cjs +1 -1
- package/dist/cjs/trigger/create-trigger-builder.cjs +1 -1
- package/dist/cjs/update/array-update-builder.cjs +1 -1
- package/dist/cjs/update/update-builder.cjs +1 -1
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/cjs/view/create-view-builder.cjs +1 -1
- package/dist/cjs/window/window-builder.cjs +1 -1
- package/dist/config.d.ts +16 -25
- package/dist/esm/cli/commands/add.js +399 -27
- package/dist/esm/cli/commands/branch.js +95 -0
- package/dist/esm/cli/commands/checkout.js +85 -0
- package/dist/esm/cli/commands/cherry-pick.js +246 -0
- package/dist/esm/cli/commands/commit.js +22 -30
- package/dist/esm/cli/commands/diff.js +144 -69
- package/dist/esm/cli/commands/export.js +71 -12
- package/dist/esm/cli/commands/fetch.js +42 -18
- package/dist/esm/cli/commands/generate.js +28 -54
- package/dist/esm/cli/commands/history.js +11 -32
- package/dist/esm/cli/commands/import.js +306 -42
- package/dist/esm/cli/commands/init.js +65 -55
- package/dist/esm/cli/commands/introspect.js +4 -8
- package/dist/esm/cli/commands/log.js +78 -10
- package/dist/esm/cli/commands/merge.js +171 -0
- package/dist/esm/cli/commands/migrate.js +13 -26
- package/dist/esm/cli/commands/pull.js +313 -87
- package/dist/esm/cli/commands/push.js +223 -47
- package/dist/esm/cli/commands/remote.js +14 -0
- package/dist/esm/cli/commands/reset.js +112 -0
- package/dist/esm/cli/commands/resolve.js +155 -0
- package/dist/esm/cli/commands/rollback.js +17 -39
- package/dist/esm/cli/commands/stash.js +116 -0
- package/dist/esm/cli/commands/status.js +20 -10
- package/dist/esm/cli/commands/sync.js +30 -50
- package/dist/esm/cli/commands/tag.js +110 -0
- package/dist/esm/cli/index.js +118 -11
- package/dist/esm/cli/utils/change-tracker.js +107 -3
- package/dist/esm/cli/utils/cli-utils.js +169 -0
- package/dist/esm/cli/utils/commit-manager.js +3 -3
- package/dist/esm/cli/utils/config-loader.js +34 -8
- package/dist/esm/cli/utils/env-loader.js +3 -2
- package/dist/esm/cli/utils/fast-introspect.js +110 -4
- package/dist/esm/cli/utils/git-utils.js +2 -124
- package/dist/esm/cli/utils/pool-manager.js +114 -0
- package/dist/esm/cli/utils/project-root.js +69 -0
- package/dist/esm/cli/utils/relqignore.js +278 -37
- package/dist/esm/cli/utils/repo-manager.js +83 -3
- package/dist/esm/cli/utils/schema-comparator.js +301 -11
- package/dist/esm/cli/utils/schema-diff.js +202 -1
- package/dist/esm/cli/utils/schema-hash.js +2 -1
- package/dist/esm/cli/utils/schema-introspect.js +9 -5
- package/dist/esm/cli/utils/snapshot-manager.js +1 -0
- package/dist/esm/cli/utils/spinner.js +1 -101
- package/dist/esm/cli/utils/sql-generator.js +2 -2
- package/dist/esm/cli/utils/sql-parser.js +94 -7
- package/dist/esm/cli/utils/type-generator.js +28 -16
- package/dist/esm/condition/array-condition-builder.js +1 -1
- package/dist/esm/condition/condition-collector.js +1 -1
- package/dist/esm/condition/fulltext-condition-builder.js +1 -1
- package/dist/esm/condition/geometric-condition-builder.js +1 -1
- package/dist/esm/condition/jsonb-condition-builder.js +1 -1
- package/dist/esm/condition/network-condition-builder.js +1 -1
- package/dist/esm/condition/range-condition-builder.js +1 -1
- package/dist/esm/copy/copy-builder.js +1 -1
- package/dist/esm/core/query-builder.js +1 -1
- package/dist/esm/core/relq-client.js +2 -2
- package/dist/esm/count/count-builder.js +1 -1
- package/dist/esm/cte/cte-builder.js +1 -1
- package/dist/esm/delete/delete-builder.js +1 -1
- package/dist/esm/function/create-function-builder.js +1 -1
- package/dist/esm/functions/advanced-functions.js +1 -1
- package/dist/esm/functions/case-builder.js +1 -1
- package/dist/esm/functions/geometric-functions.js +1 -1
- package/dist/esm/functions/network-functions.js +1 -1
- package/dist/esm/functions/sql-functions.js +1 -1
- package/dist/esm/indexing/create-index-builder.js +1 -1
- package/dist/esm/indexing/drop-index-builder.js +1 -1
- package/dist/esm/insert/conflict-builder.js +1 -1
- package/dist/esm/insert/insert-builder.js +1 -1
- package/dist/esm/maintenance/vacuum-builder.js +1 -1
- package/dist/esm/pubsub/listen-notify-builder.js +1 -1
- package/dist/esm/pubsub/listener-connection.js +2 -2
- package/dist/esm/raw/raw-query-builder.js +1 -1
- package/dist/esm/schema/schema-builder.js +1 -1
- package/dist/esm/schema-definition/table-definition.js +1 -1
- package/dist/esm/select/aggregate-builder.js +1 -1
- package/dist/esm/select/select-builder.js +1 -1
- package/dist/esm/sequence/sequence-builder.js +1 -1
- package/dist/esm/table/alter-table-builder.js +1 -1
- package/dist/esm/table/constraint-builder.js +1 -1
- package/dist/esm/table/create-table-builder.js +1 -1
- package/dist/esm/table/partition-builder.js +1 -1
- package/dist/esm/table/truncate-builder.js +1 -1
- package/dist/esm/transaction/transaction-builder.js +1 -1
- package/dist/esm/trigger/create-trigger-builder.js +1 -1
- package/dist/esm/update/array-update-builder.js +1 -1
- package/dist/esm/update/update-builder.js +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/view/create-view-builder.js +1 -1
- package/dist/esm/window/window-builder.js +1 -1
- package/dist/index.d.ts +25 -8
- package/dist/schema-builder.d.ts +16 -6
- package/package.json +1 -1
- /package/dist/{addons/buffer.js → esm/addon/buffer/index.js} +0 -0
- /package/dist/{addons/pg.js → esm/addon/pg/index.js} +0 -0
- /package/dist/{addons/pg-cursor.js → esm/addon/pg-cursor/index.js} +0 -0
- /package/dist/{addons/pg-format.js → esm/addon/pg-format/index.js} +0 -0
|
@@ -2,83 +2,158 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.diffCommand = diffCommand;
|
|
4
4
|
const config_loader_1 = require("../utils/config-loader.cjs");
|
|
5
|
-
const
|
|
6
|
-
const snapshot_manager_1 = require("../utils/snapshot-manager.cjs");
|
|
7
|
-
const schema_diff_1 = require("../utils/schema-diff.cjs");
|
|
8
|
-
const schema_hash_1 = require("../utils/schema-hash.cjs");
|
|
9
|
-
const schema_diff_2 = require("../utils/schema-diff.cjs");
|
|
10
|
-
const migration_generator_1 = require("../utils/migration-generator.cjs");
|
|
5
|
+
const fast_introspect_1 = require("../utils/fast-introspect.cjs");
|
|
11
6
|
const env_loader_1 = require("../utils/env-loader.cjs");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
dim: '\x1b[2m',
|
|
16
|
-
red: '\x1b[31m',
|
|
17
|
-
green: '\x1b[32m',
|
|
18
|
-
yellow: '\x1b[33m',
|
|
19
|
-
blue: '\x1b[34m',
|
|
20
|
-
cyan: '\x1b[36m',
|
|
21
|
-
magenta: '\x1b[35m',
|
|
22
|
-
};
|
|
23
|
-
function filterDiff(diff, ignorePatterns) {
|
|
24
|
-
const patterns = ignorePatterns.map(p => {
|
|
25
|
-
const regexStr = p.replace(/\*/g, '.*').replace(/\?/g, '.');
|
|
26
|
-
return new RegExp(`^${regexStr}$`, 'i');
|
|
27
|
-
});
|
|
28
|
-
const matchesPattern = (name) => patterns.some(p => p.test(name));
|
|
29
|
-
const tables = diff.tables.filter(t => !matchesPattern(t.name));
|
|
30
|
-
const hasChanges = tables.length > 0 || diff.extensions.length > 0;
|
|
31
|
-
return {
|
|
32
|
-
...diff,
|
|
33
|
-
tables,
|
|
34
|
-
hasChanges,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
7
|
+
const cli_utils_1 = require("../utils/cli-utils.cjs");
|
|
8
|
+
const repo_manager_1 = require("../utils/repo-manager.cjs");
|
|
9
|
+
const change_tracker_1 = require("../utils/change-tracker.cjs");
|
|
37
10
|
async function diffCommand(context) {
|
|
38
|
-
const { config, flags } = context;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
11
|
+
const { config, args, flags, projectRoot } = context;
|
|
12
|
+
console.log('');
|
|
13
|
+
if (!(0, repo_manager_1.isInitialized)(projectRoot)) {
|
|
14
|
+
(0, cli_utils_1.fatal)('not a relq repository (or any parent directories): .relq', `Run ${cli_utils_1.colors.cyan('relq init')} to initialize.`);
|
|
42
15
|
}
|
|
43
|
-
(0, config_loader_1.requireValidConfig)(config);
|
|
44
|
-
const connection = config.connection;
|
|
45
|
-
const snapshotPath = config.sync?.snapshot || '.relq/snapshot.json';
|
|
46
|
-
const ignorePatterns = config.sync?.ignore || ['_relq_*'];
|
|
47
16
|
const showSQL = flags['sql'] === true;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
17
|
+
const staged = flags['staged'] === true;
|
|
18
|
+
const target = args[0];
|
|
19
|
+
if (staged) {
|
|
20
|
+
await showStagedDiff(projectRoot, showSQL);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (target === 'remote/live' || target === 'remote' || target === 'live' || target === 'origin') {
|
|
24
|
+
if (!config) {
|
|
25
|
+
(0, cli_utils_1.fatal)('No configuration found', `Run ${cli_utils_1.colors.cyan('relq init')} to create one.`);
|
|
57
26
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
27
|
+
await (0, config_loader_1.requireValidConfig)(config, { calledFrom: 'diff' });
|
|
28
|
+
await showOriginDiff(config, projectRoot, showSQL);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
await showUnstagedDiff(projectRoot, showSQL);
|
|
32
|
+
}
|
|
33
|
+
function getSymbol(change) {
|
|
34
|
+
if (change.type === 'CREATE')
|
|
35
|
+
return cli_utils_1.colors.green('+');
|
|
36
|
+
if (change.type === 'DROP')
|
|
37
|
+
return cli_utils_1.colors.red('-');
|
|
38
|
+
return cli_utils_1.colors.yellow('~');
|
|
39
|
+
}
|
|
40
|
+
async function showUnstagedDiff(projectRoot, showSQL) {
|
|
41
|
+
const unstaged = (0, repo_manager_1.getUnstagedChanges)(projectRoot);
|
|
42
|
+
if (unstaged.length === 0) {
|
|
43
|
+
console.log(`${cli_utils_1.colors.green('No unstaged changes.')}`);
|
|
44
|
+
console.log(`${cli_utils_1.colors.muted('Use')} ${cli_utils_1.colors.cyan('relq diff remote/live')} ${cli_utils_1.colors.muted('to compare with remote.')}`);
|
|
45
|
+
console.log('');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.log(`${cli_utils_1.colors.bold('Unstaged changes:')}`);
|
|
49
|
+
console.log('');
|
|
50
|
+
const sorted = (0, change_tracker_1.sortChangesByDependency)(unstaged);
|
|
51
|
+
for (const change of sorted) {
|
|
52
|
+
console.log(` ${getSymbol(change)} ${change.objectType.toLowerCase()}: ${(0, change_tracker_1.getChangeDisplayName)(change)}`);
|
|
53
|
+
}
|
|
54
|
+
if (showSQL) {
|
|
55
|
+
console.log('');
|
|
56
|
+
console.log(`${cli_utils_1.colors.bold('SQL:')}`);
|
|
57
|
+
for (const change of sorted) {
|
|
58
|
+
const sql = (0, change_tracker_1.generateChangeSQL)(change);
|
|
59
|
+
if (sql)
|
|
60
|
+
console.log(`${cli_utils_1.colors.cyan(sql)}`);
|
|
66
61
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
}
|
|
63
|
+
console.log('');
|
|
64
|
+
console.log(`${cli_utils_1.colors.muted('Use')} ${cli_utils_1.colors.cyan('relq add .')} ${cli_utils_1.colors.muted('to stage all.')}`);
|
|
65
|
+
console.log('');
|
|
66
|
+
}
|
|
67
|
+
async function showStagedDiff(projectRoot, showSQL) {
|
|
68
|
+
const staged = (0, repo_manager_1.getStagedChanges)(projectRoot);
|
|
69
|
+
if (staged.length === 0) {
|
|
70
|
+
console.log(`${cli_utils_1.colors.green('No staged changes.')}`);
|
|
71
|
+
console.log(`${cli_utils_1.colors.muted('Use')} ${cli_utils_1.colors.cyan('relq add .')} ${cli_utils_1.colors.muted('to stage changes.')}`);
|
|
72
|
+
console.log('');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
console.log(`${cli_utils_1.colors.bold('Staged changes:')}`);
|
|
76
|
+
console.log('');
|
|
77
|
+
const sorted = (0, change_tracker_1.sortChangesByDependency)(staged);
|
|
78
|
+
for (const change of sorted) {
|
|
79
|
+
console.log(` ${getSymbol(change)} ${change.objectType.toLowerCase()}: ${(0, change_tracker_1.getChangeDisplayName)(change)}`);
|
|
80
|
+
}
|
|
81
|
+
if (showSQL) {
|
|
82
|
+
console.log('');
|
|
83
|
+
console.log(`${cli_utils_1.colors.bold('SQL:')}`);
|
|
84
|
+
for (const change of sorted) {
|
|
85
|
+
const sql = (0, change_tracker_1.generateChangeSQL)(change);
|
|
86
|
+
if (sql)
|
|
87
|
+
console.log(`${cli_utils_1.colors.cyan(sql)}`);
|
|
76
88
|
}
|
|
89
|
+
}
|
|
90
|
+
console.log('');
|
|
91
|
+
console.log(`${cli_utils_1.colors.muted('Use')} ${cli_utils_1.colors.cyan('relq commit -m "message"')} ${cli_utils_1.colors.muted('to commit.')}`);
|
|
92
|
+
console.log('');
|
|
93
|
+
}
|
|
94
|
+
async function showOriginDiff(config, projectRoot, showSQL) {
|
|
95
|
+
const connection = config.connection;
|
|
96
|
+
const spinner = (0, cli_utils_1.createSpinner)();
|
|
97
|
+
const snapshot = (0, repo_manager_1.loadSnapshot)(projectRoot);
|
|
98
|
+
if (!snapshot) {
|
|
99
|
+
console.log(`${cli_utils_1.colors.yellow('No local snapshot.')}`);
|
|
100
|
+
console.log(`${cli_utils_1.colors.muted('Run')} ${cli_utils_1.colors.cyan('relq pull')} ${cli_utils_1.colors.muted('first.')}`);
|
|
101
|
+
console.log('');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
spinner.start(`Connecting to ${(0, env_loader_1.getConnectionDescription)(connection)}...`);
|
|
105
|
+
const remoteDb = await (0, fast_introspect_1.fastIntrospectDatabase)(connection, undefined, {
|
|
106
|
+
includeFunctions: config.includeFunctions ?? false,
|
|
107
|
+
includeTriggers: config.includeTriggers ?? false,
|
|
108
|
+
});
|
|
109
|
+
spinner.succeed(`Connected`);
|
|
110
|
+
const diffs = compareSchemas(snapshot, remoteDb);
|
|
111
|
+
if (diffs.length === 0) {
|
|
112
|
+
console.log('');
|
|
113
|
+
console.log('Local and remote are in sync.');
|
|
77
114
|
console.log('');
|
|
78
|
-
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
console.log('');
|
|
118
|
+
console.log(`${cli_utils_1.colors.bold('Differences:')}`);
|
|
119
|
+
console.log('');
|
|
120
|
+
for (const d of diffs.slice(0, 20)) {
|
|
121
|
+
const sym = d.type === 'added' ? cli_utils_1.colors.green('+') : d.type === 'removed' ? cli_utils_1.colors.red('-') : cli_utils_1.colors.yellow('~');
|
|
122
|
+
console.log(` ${sym} ${d.description}`);
|
|
79
123
|
}
|
|
80
|
-
|
|
81
|
-
console.
|
|
82
|
-
|
|
124
|
+
if (diffs.length > 20) {
|
|
125
|
+
console.log(` ${cli_utils_1.colors.muted(`... and ${diffs.length - 20} more`)}`);
|
|
126
|
+
}
|
|
127
|
+
console.log('');
|
|
128
|
+
console.log(`${cli_utils_1.colors.muted('Use')} ${cli_utils_1.colors.cyan('relq pull')} ${cli_utils_1.colors.muted('to sync local with remote.')}`);
|
|
129
|
+
console.log('');
|
|
130
|
+
}
|
|
131
|
+
function compareSchemas(local, remote) {
|
|
132
|
+
const diffs = [];
|
|
133
|
+
const localTableNames = local.tables.map(t => t.name);
|
|
134
|
+
const remoteTableNames = (remote.tables || []).map((t) => t.name);
|
|
135
|
+
for (const name of remoteTableNames) {
|
|
136
|
+
if (!localTableNames.includes(name)) {
|
|
137
|
+
diffs.push({ type: 'added', description: `table: ${name}` });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const name of localTableNames) {
|
|
141
|
+
if (!remoteTableNames.includes(name)) {
|
|
142
|
+
diffs.push({ type: 'removed', description: `table: ${name}` });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const localEnumNames = local.enums.map(e => e.name);
|
|
146
|
+
const remoteEnumNames = (remote.enums || []).map((e) => e.name);
|
|
147
|
+
for (const name of remoteEnumNames) {
|
|
148
|
+
if (!localEnumNames.includes(name)) {
|
|
149
|
+
diffs.push({ type: 'added', description: `enum: ${name}` });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
for (const name of localEnumNames) {
|
|
153
|
+
if (!remoteEnumNames.includes(name)) {
|
|
154
|
+
diffs.push({ type: 'removed', description: `enum: ${name}` });
|
|
155
|
+
}
|
|
83
156
|
}
|
|
157
|
+
return diffs;
|
|
84
158
|
}
|
|
159
|
+
exports.default = diffCommand;
|
|
@@ -41,10 +41,11 @@ const spinner_1 = require("../utils/spinner.cjs");
|
|
|
41
41
|
const repo_manager_1 = require("../utils/repo-manager.cjs");
|
|
42
42
|
const change_tracker_1 = require("../utils/change-tracker.cjs");
|
|
43
43
|
const sql_generator_1 = require("../utils/sql-generator.cjs");
|
|
44
|
+
const relqignore_1 = require("../utils/relqignore.cjs");
|
|
45
|
+
const config_1 = require("../../config/config.cjs");
|
|
44
46
|
async function exportCommand(context) {
|
|
45
47
|
const spinner = (0, spinner_1.createSpinner)();
|
|
46
|
-
const { args, flags } = context;
|
|
47
|
-
const projectRoot = process.cwd();
|
|
48
|
+
const { args, flags, projectRoot } = context;
|
|
48
49
|
const changesOnly = Boolean(flags['changes']);
|
|
49
50
|
const stagedOnly = Boolean(flags['staged']);
|
|
50
51
|
const fromDb = Boolean(flags['db']);
|
|
@@ -82,7 +83,18 @@ async function exportFromSnapshot(projectRoot, absoluteOutputPath, options) {
|
|
|
82
83
|
return;
|
|
83
84
|
}
|
|
84
85
|
spinner.succeed('Loaded snapshot');
|
|
85
|
-
const
|
|
86
|
+
const config = await (0, config_1.loadConfig)();
|
|
87
|
+
const ignorePatterns = (0, relqignore_1.loadRelqignore)(projectRoot);
|
|
88
|
+
const filteredSnapshot = filterNormalizedSchema(snapshot, ignorePatterns, {
|
|
89
|
+
includeFunctions: config.includeFunctions ?? options.includeFunctions ?? false,
|
|
90
|
+
includeTriggers: config.includeTriggers ?? options.includeTriggers ?? false,
|
|
91
|
+
includeViews: config.includeViews ?? false,
|
|
92
|
+
includeFDW: config.includeFDW ?? false,
|
|
93
|
+
});
|
|
94
|
+
const schema = normalizedToDbSchema(filteredSnapshot);
|
|
95
|
+
const ignoredCount = (snapshot.tables.length - filteredSnapshot.tables.length) +
|
|
96
|
+
(snapshot.enums.length - filteredSnapshot.enums.length) +
|
|
97
|
+
((snapshot.functions?.length || 0) - (filteredSnapshot.functions?.length || 0));
|
|
86
98
|
console.log('');
|
|
87
99
|
console.log(spinner_1.colors.cyan('Schema Summary:'));
|
|
88
100
|
console.log(` ${spinner_1.colors.green('•')} Tables: ${schema.tables.length}`);
|
|
@@ -91,11 +103,14 @@ async function exportFromSnapshot(projectRoot, absoluteOutputPath, options) {
|
|
|
91
103
|
console.log(` ${spinner_1.colors.green('•')} Composite Types: ${schema.compositeTypes.length}`);
|
|
92
104
|
console.log(` ${spinner_1.colors.green('•')} Sequences: ${schema.sequences?.length || 0}`);
|
|
93
105
|
console.log(` ${spinner_1.colors.green('•')} Extensions: ${schema.extensions.length}`);
|
|
94
|
-
if (
|
|
95
|
-
console.log(` ${spinner_1.colors.green('•')} Functions: ${
|
|
106
|
+
if (filteredSnapshot.functions?.length) {
|
|
107
|
+
console.log(` ${spinner_1.colors.green('•')} Functions: ${filteredSnapshot.functions.length}`);
|
|
108
|
+
}
|
|
109
|
+
if (filteredSnapshot.triggers?.length) {
|
|
110
|
+
console.log(` ${spinner_1.colors.green('•')} Triggers: ${filteredSnapshot.triggers.length}`);
|
|
96
111
|
}
|
|
97
|
-
if (
|
|
98
|
-
console.log(` ${spinner_1.colors.
|
|
112
|
+
if (ignoredCount > 0) {
|
|
113
|
+
console.log(` ${spinner_1.colors.muted(`${ignoredCount} object(s) filtered by .relqignore`)}`);
|
|
99
114
|
}
|
|
100
115
|
spinner.start('Generating SQL statements');
|
|
101
116
|
const sqlContent = generateFullSQL(schema, options);
|
|
@@ -107,7 +122,7 @@ async function exportFromSnapshot(projectRoot, absoluteOutputPath, options) {
|
|
|
107
122
|
fs.writeFileSync(absoluteOutputPath, sqlContent, 'utf-8');
|
|
108
123
|
spinner.succeed(`Written ${options.output} (${(sqlContent.length / 1024).toFixed(1)} KB)`);
|
|
109
124
|
console.log('');
|
|
110
|
-
console.log(
|
|
125
|
+
console.log('Export completed');
|
|
111
126
|
console.log(` Source: ${spinner_1.colors.muted('snapshot (local)')}`);
|
|
112
127
|
console.log(` Output: ${spinner_1.colors.muted(options.output || '')}`);
|
|
113
128
|
}
|
|
@@ -147,7 +162,7 @@ async function exportFromDatabase(context, absoluteOutputPath, options) {
|
|
|
147
162
|
fs.writeFileSync(absoluteOutputPath, sqlContent, 'utf-8');
|
|
148
163
|
spinner.succeed(`Written ${options.output} (${(sqlContent.length / 1024).toFixed(1)} KB)`);
|
|
149
164
|
console.log('');
|
|
150
|
-
console.log(
|
|
165
|
+
console.log('Export completed');
|
|
151
166
|
console.log(` Source: ${spinner_1.colors.muted('database (live)')}`);
|
|
152
167
|
console.log(` Output: ${spinner_1.colors.muted(options.output || '')}`);
|
|
153
168
|
}
|
|
@@ -233,6 +248,7 @@ function normalizedToDbSchema(normalized) {
|
|
|
233
248
|
cycle: s.cycle,
|
|
234
249
|
ownedBy: s.ownedBy || undefined,
|
|
235
250
|
})),
|
|
251
|
+
collations: [],
|
|
236
252
|
extensions: normalized.extensions.map(e => e.name),
|
|
237
253
|
functions: (normalized.functions || []).map(f => ({
|
|
238
254
|
name: f.name,
|
|
@@ -280,7 +296,7 @@ async function exportChanges(projectRoot, flags, args, stagedOnly) {
|
|
|
280
296
|
modeLabel = 'uncommitted';
|
|
281
297
|
}
|
|
282
298
|
if (changes.length === 0) {
|
|
283
|
-
|
|
299
|
+
(0, spinner_1.warning)(`No ${modeLabel} changes to export`);
|
|
284
300
|
console.log('');
|
|
285
301
|
if (stagedOnly) {
|
|
286
302
|
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq add .')} ${spinner_1.colors.muted('to stage changes.')}`);
|
|
@@ -309,7 +325,7 @@ async function exportChanges(projectRoot, flags, args, stagedOnly) {
|
|
|
309
325
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
310
326
|
}
|
|
311
327
|
fs.writeFileSync(absoluteOutputPath, sqlContent, 'utf-8');
|
|
312
|
-
console.log(
|
|
328
|
+
console.log(`Exported ${changes.length} ${modeLabel} change(s) to ${outputPath}`);
|
|
313
329
|
console.log(`${spinner_1.colors.muted(`${(sqlContent.length / 1024).toFixed(1)} KB`)}`);
|
|
314
330
|
console.log('');
|
|
315
331
|
}
|
|
@@ -330,4 +346,47 @@ function generateFullSQL(schema, options) {
|
|
|
330
346
|
headerComment: header,
|
|
331
347
|
});
|
|
332
348
|
}
|
|
349
|
+
function filterNormalizedSchema(schema, patterns, options) {
|
|
350
|
+
const filteredTables = schema.tables
|
|
351
|
+
.filter(table => !(0, relqignore_1.isTableIgnored)(table.name, patterns).ignored)
|
|
352
|
+
.map(table => ({
|
|
353
|
+
...table,
|
|
354
|
+
columns: table.columns.filter(col => !(0, relqignore_1.isColumnIgnored)(table.name, col.name, patterns).ignored),
|
|
355
|
+
indexes: table.indexes.filter(idx => !(0, relqignore_1.isIndexIgnored)(table.name, idx.name, patterns).ignored),
|
|
356
|
+
constraints: table.constraints?.filter(con => !(0, relqignore_1.isConstraintIgnored)(table.name, con.name, patterns).ignored) || [],
|
|
357
|
+
}));
|
|
358
|
+
const filteredEnums = schema.enums.filter(e => !(0, relqignore_1.isEnumIgnored)(e.name, patterns).ignored);
|
|
359
|
+
const filteredDomains = schema.domains.filter(d => !(0, relqignore_1.isDomainIgnored)(d.name, patterns).ignored);
|
|
360
|
+
const filteredCompositeTypes = schema.compositeTypes.filter(c => !(0, relqignore_1.isCompositeTypeIgnored)(c.name, patterns).ignored);
|
|
361
|
+
const filteredSequences = schema.sequences.filter(s => !(0, relqignore_1.isSequenceIgnored)(s.name, patterns).ignored);
|
|
362
|
+
const filteredFunctions = options.includeFunctions
|
|
363
|
+
? (schema.functions || []).filter(f => !(0, relqignore_1.isFunctionIgnored)(f.name, patterns).ignored)
|
|
364
|
+
: [];
|
|
365
|
+
const filteredTriggers = options.includeTriggers
|
|
366
|
+
? schema.triggers || []
|
|
367
|
+
: [];
|
|
368
|
+
const filteredViews = options.includeViews
|
|
369
|
+
? schema.views || []
|
|
370
|
+
: [];
|
|
371
|
+
const filteredMaterializedViews = options.includeViews
|
|
372
|
+
? schema.materializedViews || []
|
|
373
|
+
: [];
|
|
374
|
+
const filteredForeignTables = options.includeFDW
|
|
375
|
+
? schema.foreignTables || []
|
|
376
|
+
: [];
|
|
377
|
+
return {
|
|
378
|
+
extensions: schema.extensions,
|
|
379
|
+
enums: filteredEnums,
|
|
380
|
+
domains: filteredDomains,
|
|
381
|
+
compositeTypes: filteredCompositeTypes,
|
|
382
|
+
sequences: filteredSequences,
|
|
383
|
+
collations: schema.collations,
|
|
384
|
+
tables: filteredTables,
|
|
385
|
+
functions: filteredFunctions,
|
|
386
|
+
triggers: filteredTriggers,
|
|
387
|
+
views: filteredViews,
|
|
388
|
+
materializedViews: filteredMaterializedViews,
|
|
389
|
+
foreignTables: filteredForeignTables,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
333
392
|
exports.default = exportCommand;
|
|
@@ -3,33 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fetchCommand = fetchCommand;
|
|
4
4
|
const config_loader_1 = require("../utils/config-loader.cjs");
|
|
5
5
|
const env_loader_1 = require("../utils/env-loader.cjs");
|
|
6
|
-
const
|
|
6
|
+
const cli_utils_1 = require("../utils/cli-utils.cjs");
|
|
7
7
|
const repo_manager_1 = require("../utils/repo-manager.cjs");
|
|
8
8
|
async function fetchCommand(context) {
|
|
9
9
|
const { config, flags } = context;
|
|
10
10
|
if (!config) {
|
|
11
|
-
|
|
12
|
-
process.exit(1);
|
|
11
|
+
(0, cli_utils_1.fatal)('No configuration found', `run ${cli_utils_1.colors.cyan('relq init')} to create a configuration file`);
|
|
13
12
|
}
|
|
14
|
-
(0, config_loader_1.requireValidConfig)(config);
|
|
13
|
+
await (0, config_loader_1.requireValidConfig)(config, { calledFrom: 'fetch' });
|
|
15
14
|
const connection = config.connection;
|
|
16
|
-
const projectRoot =
|
|
15
|
+
const { projectRoot } = context;
|
|
17
16
|
console.log('');
|
|
18
17
|
if (!(0, repo_manager_1.isInitialized)(projectRoot)) {
|
|
19
|
-
|
|
20
|
-
console.log('');
|
|
21
|
-
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq init')} ${spinner_1.colors.muted('to initialize.')}`);
|
|
22
|
-
return;
|
|
18
|
+
(0, cli_utils_1.fatal)('not a relq repository (or any parent directories): .relq', "run 'relq init' to initialize");
|
|
23
19
|
}
|
|
24
|
-
const spinner = (0,
|
|
20
|
+
const spinner = (0, cli_utils_1.createSpinner)();
|
|
25
21
|
spinner.start(`Fetching from ${(0, env_loader_1.getConnectionDescription)(connection)}...`);
|
|
26
22
|
try {
|
|
27
23
|
await (0, repo_manager_1.ensureRemoteTable)(connection);
|
|
28
24
|
const remoteCommits = await (0, repo_manager_1.fetchRemoteCommits)(connection, 100);
|
|
29
25
|
if (remoteCommits.length === 0) {
|
|
30
26
|
spinner.succeed('No remote commits found');
|
|
31
|
-
|
|
32
|
-
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq push')} ${spinner_1.colors.muted('to push your commits.')}`);
|
|
27
|
+
(0, cli_utils_1.hint)("run 'relq push' to push your commits");
|
|
33
28
|
return;
|
|
34
29
|
}
|
|
35
30
|
let newCommits = 0;
|
|
@@ -44,16 +39,45 @@ async function fetchCommand(context) {
|
|
|
44
39
|
(0, repo_manager_1.setFetchHead)(latestRemote.hash, projectRoot);
|
|
45
40
|
spinner.succeed(`Fetched ${remoteCommits.length} commits (${newCommits} new)`);
|
|
46
41
|
const localHead = (0, repo_manager_1.getHead)(projectRoot);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
const localCommits = localHead ? getAllLocalCommitHashes(projectRoot) : new Set();
|
|
43
|
+
const remoteHashes = new Set(remoteCommits.map(c => c.hash));
|
|
44
|
+
const behind = remoteCommits.filter(c => !localCommits.has(c.hash)).length;
|
|
45
|
+
const ahead = [...localCommits].filter(h => !remoteHashes.has(h)).length;
|
|
46
|
+
console.log('');
|
|
47
|
+
if (behind > 0 && ahead > 0) {
|
|
48
|
+
console.log(`Your branch and 'origin/main' have diverged,`);
|
|
49
|
+
console.log(`and have ${ahead} and ${behind} different commits each, respectively.`);
|
|
50
|
+
}
|
|
51
|
+
else if (behind > 0) {
|
|
52
|
+
console.log(`Your branch is behind 'origin/main' by ${behind} commit(s).`);
|
|
53
|
+
(0, cli_utils_1.hint)("run 'relq pull' to update your local branch");
|
|
54
|
+
}
|
|
55
|
+
else if (ahead > 0) {
|
|
56
|
+
console.log(`Your branch is ahead of 'origin/main' by ${ahead} commit(s).`);
|
|
57
|
+
(0, cli_utils_1.hint)("run 'relq push' to publish your local commits");
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.log("Your branch is up to date with 'origin/main'.");
|
|
51
61
|
}
|
|
52
62
|
}
|
|
53
63
|
catch (error) {
|
|
54
64
|
spinner.fail('Fetch failed');
|
|
55
|
-
|
|
56
|
-
process.exit(1);
|
|
65
|
+
(0, cli_utils_1.fatal)('Fetch failed', error instanceof Error ? error.message : String(error));
|
|
57
66
|
}
|
|
58
67
|
console.log('');
|
|
59
68
|
}
|
|
69
|
+
function getAllLocalCommitHashes(projectRoot) {
|
|
70
|
+
const fs = require('fs');
|
|
71
|
+
const path = require('path');
|
|
72
|
+
const commitsDir = path.join(projectRoot, '.relq', 'commits');
|
|
73
|
+
const hashes = new Set();
|
|
74
|
+
if (fs.existsSync(commitsDir)) {
|
|
75
|
+
const files = fs.readdirSync(commitsDir);
|
|
76
|
+
for (const file of files) {
|
|
77
|
+
if (file.endsWith('.json')) {
|
|
78
|
+
hashes.add(file.replace('.json', ''));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return hashes;
|
|
83
|
+
}
|
|
@@ -44,32 +44,7 @@ const schema_diff_1 = require("../utils/schema-diff.cjs");
|
|
|
44
44
|
const schema_hash_1 = require("../utils/schema-hash.cjs");
|
|
45
45
|
const migration_generator_1 = require("../utils/migration-generator.cjs");
|
|
46
46
|
const env_loader_1 = require("../utils/env-loader.cjs");
|
|
47
|
-
const
|
|
48
|
-
reset: '\x1b[0m',
|
|
49
|
-
bold: '\x1b[1m',
|
|
50
|
-
dim: '\x1b[2m',
|
|
51
|
-
red: '\x1b[31m',
|
|
52
|
-
green: '\x1b[32m',
|
|
53
|
-
yellow: '\x1b[33m',
|
|
54
|
-
cyan: '\x1b[36m',
|
|
55
|
-
};
|
|
56
|
-
function askConfirm(question, defaultYes = false) {
|
|
57
|
-
const rl = readline.createInterface({
|
|
58
|
-
input: process.stdin,
|
|
59
|
-
output: process.stdout,
|
|
60
|
-
});
|
|
61
|
-
const suffix = defaultYes ? '[Y/n]' : '[y/N]';
|
|
62
|
-
return new Promise((resolve) => {
|
|
63
|
-
rl.question(`${question} ${suffix}: `, (answer) => {
|
|
64
|
-
rl.close();
|
|
65
|
-
const a = answer.trim().toLowerCase();
|
|
66
|
-
if (!a)
|
|
67
|
-
resolve(defaultYes);
|
|
68
|
-
else
|
|
69
|
-
resolve(a === 'y' || a === 'yes');
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}
|
|
47
|
+
const cli_utils_1 = require("../utils/cli-utils.cjs");
|
|
73
48
|
function askInput(question) {
|
|
74
49
|
const rl = readline.createInterface({
|
|
75
50
|
input: process.stdin,
|
|
@@ -85,10 +60,10 @@ function askInput(question) {
|
|
|
85
60
|
async function generateCommand(context) {
|
|
86
61
|
const { config, args, flags } = context;
|
|
87
62
|
if (!config) {
|
|
88
|
-
|
|
89
|
-
|
|
63
|
+
(0, cli_utils_1.fatal)('No configuration found', `run ${cli_utils_1.colors.cyan('relq init')} to create a configuration file`);
|
|
64
|
+
return;
|
|
90
65
|
}
|
|
91
|
-
(0, config_loader_1.requireValidConfig)(config);
|
|
66
|
+
await (0, config_loader_1.requireValidConfig)(config, { calledFrom: 'generate' });
|
|
92
67
|
const connection = config.connection;
|
|
93
68
|
const migrationsDir = config.migrations?.directory || './migrations';
|
|
94
69
|
const snapshotPath = config.sync?.snapshot || '.relq/snapshot.json';
|
|
@@ -111,10 +86,10 @@ async function generateCommand(context) {
|
|
|
111
86
|
migrationName = message.replace(/\s+/g, '_').toLowerCase();
|
|
112
87
|
}
|
|
113
88
|
if (!migrationName && !isEmpty) {
|
|
114
|
-
migrationName = await askInput(
|
|
89
|
+
migrationName = await askInput('Migration name: ');
|
|
115
90
|
if (!migrationName) {
|
|
116
|
-
|
|
117
|
-
|
|
91
|
+
(0, cli_utils_1.fatal)('Migration name is required');
|
|
92
|
+
return;
|
|
118
93
|
}
|
|
119
94
|
}
|
|
120
95
|
if (isEmpty) {
|
|
@@ -122,48 +97,48 @@ async function generateCommand(context) {
|
|
|
122
97
|
await createEmptyMigration(migrationsDir, migrationName, format, dryRun);
|
|
123
98
|
return;
|
|
124
99
|
}
|
|
125
|
-
console.log(
|
|
100
|
+
console.log('Generating migration...');
|
|
126
101
|
console.log(` Connection: ${(0, env_loader_1.getConnectionDescription)(connection)}`);
|
|
127
102
|
console.log('');
|
|
128
103
|
try {
|
|
129
104
|
const dbSchema = await (0, schema_introspect_1.introspectDatabase)(connection);
|
|
130
105
|
const snapshot = (0, snapshot_manager_1.loadSnapshot)(snapshotPath);
|
|
131
106
|
if (!snapshot) {
|
|
132
|
-
|
|
133
|
-
console.log(
|
|
107
|
+
(0, cli_utils_1.warning)('No snapshot found.');
|
|
108
|
+
console.log('Run "relq pull" first to create initial snapshot.');
|
|
134
109
|
return;
|
|
135
110
|
}
|
|
136
111
|
const localSchema = (0, snapshot_manager_1.snapshotToDatabaseSchema)(snapshot);
|
|
137
112
|
const diff = (0, schema_diff_1.diffSchemas)((0, schema_hash_1.normalizeSchema)(localSchema), (0, schema_hash_1.normalizeSchema)(dbSchema));
|
|
138
113
|
const filteredDiff = (0, schema_diff_1.filterDiff)(diff, ignorePatterns);
|
|
139
114
|
if (!filteredDiff.hasChanges) {
|
|
140
|
-
console.log(
|
|
115
|
+
console.log('No changes to generate.');
|
|
141
116
|
return;
|
|
142
117
|
}
|
|
143
118
|
const s = filteredDiff.summary;
|
|
144
|
-
console.log(
|
|
119
|
+
console.log('Changes to include:');
|
|
145
120
|
if (s.tablesAdded > 0)
|
|
146
|
-
console.log(`
|
|
121
|
+
console.log(` + ${s.tablesAdded} table(s)`);
|
|
147
122
|
if (s.tablesRemoved > 0)
|
|
148
|
-
console.log(`
|
|
123
|
+
console.log(` - ${s.tablesRemoved} table(s)`);
|
|
149
124
|
if (s.tablesModified > 0)
|
|
150
|
-
console.log(`
|
|
125
|
+
console.log(` ~ ${s.tablesModified} table(s) modified`);
|
|
151
126
|
if (s.columnsAdded > 0)
|
|
152
|
-
console.log(`
|
|
127
|
+
console.log(` + ${s.columnsAdded} column(s)`);
|
|
153
128
|
if (s.columnsRemoved > 0)
|
|
154
|
-
console.log(`
|
|
129
|
+
console.log(` - ${s.columnsRemoved} column(s)`);
|
|
155
130
|
if (s.columnsModified > 0)
|
|
156
|
-
console.log(`
|
|
131
|
+
console.log(` ~ ${s.columnsModified} column(s)`);
|
|
157
132
|
console.log('');
|
|
158
133
|
if ((0, schema_diff_1.hasDestructiveChanges)(filteredDiff)) {
|
|
159
134
|
const tables = (0, schema_diff_1.getDestructiveTables)(filteredDiff);
|
|
160
|
-
|
|
135
|
+
(0, cli_utils_1.warning)('Destructive changes:');
|
|
161
136
|
for (const t of tables) {
|
|
162
|
-
console.log(`
|
|
137
|
+
console.log(` - ${t}`);
|
|
163
138
|
}
|
|
164
139
|
console.log('');
|
|
165
140
|
if (!autoStage) {
|
|
166
|
-
const proceed = await
|
|
141
|
+
const proceed = await (0, cli_utils_1.confirm)('Include destructive changes?', false);
|
|
167
142
|
if (!proceed) {
|
|
168
143
|
console.log('Cancelled.');
|
|
169
144
|
return;
|
|
@@ -185,7 +160,7 @@ async function generateCommand(context) {
|
|
|
185
160
|
}
|
|
186
161
|
const filePath = path.join(migrationsDir, fileName);
|
|
187
162
|
if (dryRun) {
|
|
188
|
-
console.log(
|
|
163
|
+
console.log(`[dry-run] Would create: ${filePath}`);
|
|
189
164
|
console.log('');
|
|
190
165
|
console.log('--- Generated SQL ---');
|
|
191
166
|
console.log(migrationFile.content);
|
|
@@ -196,16 +171,15 @@ async function generateCommand(context) {
|
|
|
196
171
|
fs.mkdirSync(migrationsDir, { recursive: true });
|
|
197
172
|
}
|
|
198
173
|
fs.writeFileSync(filePath, migrationFile.content, 'utf-8');
|
|
199
|
-
console.log(
|
|
174
|
+
console.log(`Created: ${filePath}`);
|
|
200
175
|
(0, snapshot_manager_1.saveSnapshot)(dbSchema, snapshotPath, connection.database);
|
|
201
|
-
console.log(
|
|
176
|
+
console.log('Updated snapshot.');
|
|
202
177
|
}
|
|
203
178
|
console.log('');
|
|
204
|
-
console.log(
|
|
179
|
+
console.log('Run "relq push" to apply this migration.');
|
|
205
180
|
}
|
|
206
181
|
catch (error) {
|
|
207
|
-
|
|
208
|
-
process.exit(1);
|
|
182
|
+
(0, cli_utils_1.fatal)('Generation failed', error instanceof Error ? error.message : String(error));
|
|
209
183
|
}
|
|
210
184
|
}
|
|
211
185
|
async function createEmptyMigration(migrationsDir, name, format, dryRun) {
|
|
@@ -230,13 +204,13 @@ async function createEmptyMigration(migrationsDir, name, format, dryRun) {
|
|
|
230
204
|
|
|
231
205
|
`;
|
|
232
206
|
if (dryRun) {
|
|
233
|
-
console.log(
|
|
207
|
+
console.log(`[dry-run] Would create: ${filePath}`);
|
|
234
208
|
}
|
|
235
209
|
else {
|
|
236
210
|
if (!fs.existsSync(migrationsDir)) {
|
|
237
211
|
fs.mkdirSync(migrationsDir, { recursive: true });
|
|
238
212
|
}
|
|
239
213
|
fs.writeFileSync(filePath, content, 'utf-8');
|
|
240
|
-
console.log(
|
|
214
|
+
console.log(`Created empty migration: ${filePath}`);
|
|
241
215
|
}
|
|
242
216
|
}
|