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.
Files changed (194) hide show
  1. package/dist/cjs/addon/buffer/index.cjs +1881 -0
  2. package/dist/cjs/addon/pg/index.cjs +4812 -0
  3. package/dist/cjs/addon/pg-cursor/index.cjs +1451 -0
  4. package/dist/cjs/addon/pg-format/index.cjs +2270 -0
  5. package/dist/cjs/cli/commands/add.cjs +430 -25
  6. package/dist/cjs/cli/commands/branch.cjs +131 -0
  7. package/dist/cjs/cli/commands/checkout.cjs +121 -0
  8. package/dist/cjs/cli/commands/cherry-pick.cjs +282 -0
  9. package/dist/cjs/cli/commands/commit.cjs +21 -29
  10. package/dist/cjs/cli/commands/diff.cjs +144 -69
  11. package/dist/cjs/cli/commands/export.cjs +70 -11
  12. package/dist/cjs/cli/commands/fetch.cjs +42 -18
  13. package/dist/cjs/cli/commands/generate.cjs +28 -54
  14. package/dist/cjs/cli/commands/history.cjs +19 -40
  15. package/dist/cjs/cli/commands/import.cjs +305 -41
  16. package/dist/cjs/cli/commands/init.cjs +69 -59
  17. package/dist/cjs/cli/commands/introspect.cjs +4 -8
  18. package/dist/cjs/cli/commands/log.cjs +84 -15
  19. package/dist/cjs/cli/commands/merge.cjs +207 -0
  20. package/dist/cjs/cli/commands/migrate.cjs +13 -26
  21. package/dist/cjs/cli/commands/pull.cjs +321 -95
  22. package/dist/cjs/cli/commands/push.cjs +228 -52
  23. package/dist/cjs/cli/commands/remote.cjs +17 -0
  24. package/dist/cjs/cli/commands/reset.cjs +148 -0
  25. package/dist/cjs/cli/commands/resolve.cjs +191 -0
  26. package/dist/cjs/cli/commands/rollback.cjs +17 -39
  27. package/dist/cjs/cli/commands/stash.cjs +152 -0
  28. package/dist/cjs/cli/commands/status.cjs +52 -9
  29. package/dist/cjs/cli/commands/sync.cjs +30 -50
  30. package/dist/cjs/cli/commands/tag.cjs +146 -0
  31. package/dist/cjs/cli/index.cjs +117 -10
  32. package/dist/cjs/cli/utils/change-tracker.cjs +107 -3
  33. package/dist/cjs/cli/utils/cli-utils.cjs +217 -0
  34. package/dist/cjs/cli/utils/commit-manager.cjs +3 -3
  35. package/dist/cjs/cli/utils/config-loader.cjs +34 -8
  36. package/dist/cjs/cli/utils/env-loader.cjs +3 -2
  37. package/dist/cjs/cli/utils/fast-introspect.cjs +110 -4
  38. package/dist/cjs/cli/utils/git-utils.cjs +42 -161
  39. package/dist/cjs/cli/utils/pool-manager.cjs +156 -0
  40. package/dist/cjs/cli/utils/project-root.cjs +107 -0
  41. package/dist/cjs/cli/utils/relqignore.cjs +297 -38
  42. package/dist/cjs/cli/utils/repo-manager.cjs +92 -3
  43. package/dist/cjs/cli/utils/schema-comparator.cjs +301 -11
  44. package/dist/cjs/cli/utils/schema-diff.cjs +202 -1
  45. package/dist/cjs/cli/utils/schema-hash.cjs +2 -1
  46. package/dist/cjs/cli/utils/schema-introspect.cjs +9 -5
  47. package/dist/cjs/cli/utils/snapshot-manager.cjs +1 -0
  48. package/dist/cjs/cli/utils/spinner.cjs +14 -106
  49. package/dist/cjs/cli/utils/sql-generator.cjs +2 -2
  50. package/dist/cjs/cli/utils/sql-parser.cjs +94 -7
  51. package/dist/cjs/cli/utils/type-generator.cjs +28 -16
  52. package/dist/cjs/condition/array-condition-builder.cjs +1 -1
  53. package/dist/cjs/condition/condition-collector.cjs +1 -1
  54. package/dist/cjs/condition/fulltext-condition-builder.cjs +1 -1
  55. package/dist/cjs/condition/geometric-condition-builder.cjs +1 -1
  56. package/dist/cjs/condition/jsonb-condition-builder.cjs +1 -1
  57. package/dist/cjs/condition/network-condition-builder.cjs +1 -1
  58. package/dist/cjs/condition/range-condition-builder.cjs +1 -1
  59. package/dist/cjs/copy/copy-builder.cjs +1 -1
  60. package/dist/cjs/core/query-builder.cjs +1 -1
  61. package/dist/cjs/core/relq-client.cjs +2 -2
  62. package/dist/cjs/count/count-builder.cjs +1 -1
  63. package/dist/cjs/cte/cte-builder.cjs +1 -1
  64. package/dist/cjs/delete/delete-builder.cjs +1 -1
  65. package/dist/cjs/function/create-function-builder.cjs +1 -1
  66. package/dist/cjs/functions/advanced-functions.cjs +1 -1
  67. package/dist/cjs/functions/case-builder.cjs +1 -1
  68. package/dist/cjs/functions/geometric-functions.cjs +1 -1
  69. package/dist/cjs/functions/network-functions.cjs +1 -1
  70. package/dist/cjs/functions/sql-functions.cjs +1 -1
  71. package/dist/cjs/indexing/create-index-builder.cjs +1 -1
  72. package/dist/cjs/indexing/drop-index-builder.cjs +1 -1
  73. package/dist/cjs/insert/conflict-builder.cjs +1 -1
  74. package/dist/cjs/insert/insert-builder.cjs +1 -1
  75. package/dist/cjs/maintenance/vacuum-builder.cjs +1 -1
  76. package/dist/cjs/pubsub/listen-notify-builder.cjs +1 -1
  77. package/dist/cjs/pubsub/listener-connection.cjs +2 -2
  78. package/dist/cjs/raw/raw-query-builder.cjs +1 -1
  79. package/dist/cjs/schema/schema-builder.cjs +1 -1
  80. package/dist/cjs/schema-definition/table-definition.cjs +1 -1
  81. package/dist/cjs/select/aggregate-builder.cjs +1 -1
  82. package/dist/cjs/select/select-builder.cjs +1 -1
  83. package/dist/cjs/sequence/sequence-builder.cjs +1 -1
  84. package/dist/cjs/table/alter-table-builder.cjs +1 -1
  85. package/dist/cjs/table/constraint-builder.cjs +1 -1
  86. package/dist/cjs/table/create-table-builder.cjs +1 -1
  87. package/dist/cjs/table/partition-builder.cjs +1 -1
  88. package/dist/cjs/table/truncate-builder.cjs +1 -1
  89. package/dist/cjs/transaction/transaction-builder.cjs +1 -1
  90. package/dist/cjs/trigger/create-trigger-builder.cjs +1 -1
  91. package/dist/cjs/update/array-update-builder.cjs +1 -1
  92. package/dist/cjs/update/update-builder.cjs +1 -1
  93. package/dist/cjs/utils/index.cjs +1 -1
  94. package/dist/cjs/view/create-view-builder.cjs +1 -1
  95. package/dist/cjs/window/window-builder.cjs +1 -1
  96. package/dist/config.d.ts +16 -25
  97. package/dist/esm/cli/commands/add.js +399 -27
  98. package/dist/esm/cli/commands/branch.js +95 -0
  99. package/dist/esm/cli/commands/checkout.js +85 -0
  100. package/dist/esm/cli/commands/cherry-pick.js +246 -0
  101. package/dist/esm/cli/commands/commit.js +22 -30
  102. package/dist/esm/cli/commands/diff.js +144 -69
  103. package/dist/esm/cli/commands/export.js +71 -12
  104. package/dist/esm/cli/commands/fetch.js +42 -18
  105. package/dist/esm/cli/commands/generate.js +28 -54
  106. package/dist/esm/cli/commands/history.js +11 -32
  107. package/dist/esm/cli/commands/import.js +306 -42
  108. package/dist/esm/cli/commands/init.js +65 -55
  109. package/dist/esm/cli/commands/introspect.js +4 -8
  110. package/dist/esm/cli/commands/log.js +78 -10
  111. package/dist/esm/cli/commands/merge.js +171 -0
  112. package/dist/esm/cli/commands/migrate.js +13 -26
  113. package/dist/esm/cli/commands/pull.js +313 -87
  114. package/dist/esm/cli/commands/push.js +223 -47
  115. package/dist/esm/cli/commands/remote.js +14 -0
  116. package/dist/esm/cli/commands/reset.js +112 -0
  117. package/dist/esm/cli/commands/resolve.js +155 -0
  118. package/dist/esm/cli/commands/rollback.js +17 -39
  119. package/dist/esm/cli/commands/stash.js +116 -0
  120. package/dist/esm/cli/commands/status.js +20 -10
  121. package/dist/esm/cli/commands/sync.js +30 -50
  122. package/dist/esm/cli/commands/tag.js +110 -0
  123. package/dist/esm/cli/index.js +118 -11
  124. package/dist/esm/cli/utils/change-tracker.js +107 -3
  125. package/dist/esm/cli/utils/cli-utils.js +169 -0
  126. package/dist/esm/cli/utils/commit-manager.js +3 -3
  127. package/dist/esm/cli/utils/config-loader.js +34 -8
  128. package/dist/esm/cli/utils/env-loader.js +3 -2
  129. package/dist/esm/cli/utils/fast-introspect.js +110 -4
  130. package/dist/esm/cli/utils/git-utils.js +2 -124
  131. package/dist/esm/cli/utils/pool-manager.js +114 -0
  132. package/dist/esm/cli/utils/project-root.js +69 -0
  133. package/dist/esm/cli/utils/relqignore.js +278 -37
  134. package/dist/esm/cli/utils/repo-manager.js +83 -3
  135. package/dist/esm/cli/utils/schema-comparator.js +301 -11
  136. package/dist/esm/cli/utils/schema-diff.js +202 -1
  137. package/dist/esm/cli/utils/schema-hash.js +2 -1
  138. package/dist/esm/cli/utils/schema-introspect.js +9 -5
  139. package/dist/esm/cli/utils/snapshot-manager.js +1 -0
  140. package/dist/esm/cli/utils/spinner.js +1 -101
  141. package/dist/esm/cli/utils/sql-generator.js +2 -2
  142. package/dist/esm/cli/utils/sql-parser.js +94 -7
  143. package/dist/esm/cli/utils/type-generator.js +28 -16
  144. package/dist/esm/condition/array-condition-builder.js +1 -1
  145. package/dist/esm/condition/condition-collector.js +1 -1
  146. package/dist/esm/condition/fulltext-condition-builder.js +1 -1
  147. package/dist/esm/condition/geometric-condition-builder.js +1 -1
  148. package/dist/esm/condition/jsonb-condition-builder.js +1 -1
  149. package/dist/esm/condition/network-condition-builder.js +1 -1
  150. package/dist/esm/condition/range-condition-builder.js +1 -1
  151. package/dist/esm/copy/copy-builder.js +1 -1
  152. package/dist/esm/core/query-builder.js +1 -1
  153. package/dist/esm/core/relq-client.js +2 -2
  154. package/dist/esm/count/count-builder.js +1 -1
  155. package/dist/esm/cte/cte-builder.js +1 -1
  156. package/dist/esm/delete/delete-builder.js +1 -1
  157. package/dist/esm/function/create-function-builder.js +1 -1
  158. package/dist/esm/functions/advanced-functions.js +1 -1
  159. package/dist/esm/functions/case-builder.js +1 -1
  160. package/dist/esm/functions/geometric-functions.js +1 -1
  161. package/dist/esm/functions/network-functions.js +1 -1
  162. package/dist/esm/functions/sql-functions.js +1 -1
  163. package/dist/esm/indexing/create-index-builder.js +1 -1
  164. package/dist/esm/indexing/drop-index-builder.js +1 -1
  165. package/dist/esm/insert/conflict-builder.js +1 -1
  166. package/dist/esm/insert/insert-builder.js +1 -1
  167. package/dist/esm/maintenance/vacuum-builder.js +1 -1
  168. package/dist/esm/pubsub/listen-notify-builder.js +1 -1
  169. package/dist/esm/pubsub/listener-connection.js +2 -2
  170. package/dist/esm/raw/raw-query-builder.js +1 -1
  171. package/dist/esm/schema/schema-builder.js +1 -1
  172. package/dist/esm/schema-definition/table-definition.js +1 -1
  173. package/dist/esm/select/aggregate-builder.js +1 -1
  174. package/dist/esm/select/select-builder.js +1 -1
  175. package/dist/esm/sequence/sequence-builder.js +1 -1
  176. package/dist/esm/table/alter-table-builder.js +1 -1
  177. package/dist/esm/table/constraint-builder.js +1 -1
  178. package/dist/esm/table/create-table-builder.js +1 -1
  179. package/dist/esm/table/partition-builder.js +1 -1
  180. package/dist/esm/table/truncate-builder.js +1 -1
  181. package/dist/esm/transaction/transaction-builder.js +1 -1
  182. package/dist/esm/trigger/create-trigger-builder.js +1 -1
  183. package/dist/esm/update/array-update-builder.js +1 -1
  184. package/dist/esm/update/update-builder.js +1 -1
  185. package/dist/esm/utils/index.js +1 -1
  186. package/dist/esm/view/create-view-builder.js +1 -1
  187. package/dist/esm/window/window-builder.js +1 -1
  188. package/dist/index.d.ts +25 -8
  189. package/dist/schema-builder.d.ts +16 -6
  190. package/package.json +1 -1
  191. /package/dist/{addons/buffer.js → esm/addon/buffer/index.js} +0 -0
  192. /package/dist/{addons/pg.js → esm/addon/pg/index.js} +0 -0
  193. /package/dist/{addons/pg-cursor.js → esm/addon/pg-cursor/index.js} +0 -0
  194. /package/dist/{addons/pg-format.js → esm/addon/pg-format/index.js} +0 -0
@@ -0,0 +1,207 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.mergeCommand = mergeCommand;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const cli_utils_1 = require("../utils/cli-utils.cjs");
40
+ const repo_manager_1 = require("../utils/repo-manager.cjs");
41
+ function loadBranchState(projectRoot) {
42
+ const branchPath = path.join(projectRoot, '.relq', 'branches.json');
43
+ if (fs.existsSync(branchPath)) {
44
+ return JSON.parse(fs.readFileSync(branchPath, 'utf-8'));
45
+ }
46
+ const head = require("../utils/repo-manager.cjs").getHead(projectRoot);
47
+ return { current: 'main', branches: { main: head || '' } };
48
+ }
49
+ function saveBranchState(state, projectRoot) {
50
+ const branchPath = path.join(projectRoot, '.relq', 'branches.json');
51
+ fs.writeFileSync(branchPath, JSON.stringify(state, null, 2));
52
+ }
53
+ async function mergeCommand(context) {
54
+ const { config, args, flags, projectRoot } = context;
55
+ console.log('');
56
+ if (!(0, repo_manager_1.isInitialized)(projectRoot)) {
57
+ (0, cli_utils_1.fatal)('not a relq repository (or any parent directories): .relq', `Run ${cli_utils_1.colors.cyan('relq init')} to initialize.`);
58
+ }
59
+ const branchName = args[0];
60
+ const abort = flags['abort'] === true;
61
+ const mergeStatePath = path.join(projectRoot, '.relq', 'MERGE_STATE');
62
+ if (abort) {
63
+ if (fs.existsSync(mergeStatePath)) {
64
+ fs.unlinkSync(mergeStatePath);
65
+ console.log('Merge aborted');
66
+ console.log('');
67
+ return;
68
+ }
69
+ else {
70
+ (0, cli_utils_1.fatal)('There is no merge to abort (MERGE_STATE missing)');
71
+ }
72
+ }
73
+ if (fs.existsSync(mergeStatePath)) {
74
+ const mergeState = JSON.parse(fs.readFileSync(mergeStatePath, 'utf-8'));
75
+ (0, cli_utils_1.fatal)(`Merge in progress from '${mergeState.fromBranch}'`, `Use ${cli_utils_1.colors.cyan('relq resolve')} to resolve conflicts\nOr ${cli_utils_1.colors.cyan('relq merge --abort')} to cancel`);
76
+ }
77
+ if (!branchName) {
78
+ (0, cli_utils_1.fatal)('Please specify a branch to merge', `Usage: ${cli_utils_1.colors.cyan('relq merge <branch>')}`);
79
+ }
80
+ const state = loadBranchState(projectRoot);
81
+ if (!state.branches[branchName]) {
82
+ (0, cli_utils_1.fatal)(`Branch not found: ${branchName}`, `Use ${cli_utils_1.colors.cyan('relq branch')} to list available branches.`);
83
+ }
84
+ if (branchName === state.current) {
85
+ (0, cli_utils_1.fatal)('Cannot merge branch into itself');
86
+ }
87
+ const spinner = (0, cli_utils_1.createSpinner)();
88
+ spinner.start(`Merging '${branchName}' into '${state.current}'...`);
89
+ try {
90
+ const currentHash = (0, repo_manager_1.getHead)(projectRoot);
91
+ const incomingHash = state.branches[branchName];
92
+ if (!currentHash || !incomingHash) {
93
+ spinner.stop();
94
+ (0, cli_utils_1.fatal)('No commits to merge', `Run ${cli_utils_1.colors.cyan('relq pull')} first.`);
95
+ }
96
+ if (currentHash === incomingHash) {
97
+ spinner.succeed('Already up to date');
98
+ console.log('');
99
+ return;
100
+ }
101
+ const currentCommit = (0, repo_manager_1.loadCommit)(currentHash, projectRoot);
102
+ const incomingCommit = (0, repo_manager_1.loadCommit)(incomingHash, projectRoot);
103
+ if (!currentCommit || !incomingCommit) {
104
+ spinner.stop();
105
+ (0, cli_utils_1.fatal)('Cannot load commit data - repository may be corrupt');
106
+ }
107
+ const currentSnapshot = (0, repo_manager_1.loadSnapshot)(projectRoot) || currentCommit.schema;
108
+ const incomingSnapshot = incomingCommit.schema;
109
+ if (!currentSnapshot || !incomingSnapshot) {
110
+ spinner.stop();
111
+ (0, cli_utils_1.fatal)('No snapshot data - repository may be corrupt');
112
+ }
113
+ const conflicts = detectMergeConflicts(currentSnapshot, incomingSnapshot);
114
+ if (conflicts.length > 0) {
115
+ const mergeState = {
116
+ fromBranch: branchName,
117
+ toBranch: state.current,
118
+ conflicts,
119
+ incomingSnapshot,
120
+ createdAt: new Date().toISOString(),
121
+ };
122
+ fs.writeFileSync(mergeStatePath, JSON.stringify(mergeState, null, 2));
123
+ spinner.fail(`${conflicts.length} conflict(s) detected`);
124
+ console.log('');
125
+ for (const c of conflicts.slice(0, 5)) {
126
+ const name = c.parentName ? `${c.parentName}.${c.objectName}` : c.objectName;
127
+ console.log(` ${cli_utils_1.colors.red('conflict:')} ${c.objectType.toLowerCase()} ${name}`);
128
+ }
129
+ if (conflicts.length > 5) {
130
+ console.log(` ${cli_utils_1.colors.muted(`... and ${conflicts.length - 5} more`)}`);
131
+ }
132
+ (0, cli_utils_1.fatal)(`Automatic merge failed; fix conflicts and then commit`, `Use ${cli_utils_1.colors.cyan('relq resolve --all-theirs')} to accept incoming\nOr ${cli_utils_1.colors.cyan('relq merge --abort')} to cancel`);
133
+ }
134
+ const mergedSnapshot = mergeSnapshots(currentSnapshot, incomingSnapshot);
135
+ (0, repo_manager_1.saveSnapshot)(mergedSnapshot, projectRoot);
136
+ const author = config?.author || 'Relq CLI';
137
+ const message = `Merge branch '${branchName}' into ${state.current}`;
138
+ const commit = (0, repo_manager_1.createCommit)(mergedSnapshot, author, message, projectRoot);
139
+ spinner.succeed(`Merged '${branchName}' into '${state.current}'`);
140
+ console.log(` ${cli_utils_1.colors.yellow((0, repo_manager_1.shortHash)(commit.hash))} ${message}`);
141
+ console.log('');
142
+ }
143
+ catch (err) {
144
+ spinner.fail('Merge failed');
145
+ (0, cli_utils_1.fatal)(err instanceof Error ? err.message : String(err));
146
+ }
147
+ }
148
+ function detectMergeConflicts(current, incoming) {
149
+ const conflicts = [];
150
+ for (const currentTable of current.tables) {
151
+ const incomingTable = incoming.tables.find(t => t.name === currentTable.name);
152
+ if (!incomingTable)
153
+ continue;
154
+ for (const currentCol of currentTable.columns) {
155
+ const incomingCol = incomingTable.columns.find(c => c.name === currentCol.name);
156
+ if (!incomingCol)
157
+ continue;
158
+ if (currentCol.type !== incomingCol.type) {
159
+ conflicts.push({
160
+ objectType: 'COLUMN',
161
+ objectName: currentCol.name,
162
+ parentName: currentTable.name,
163
+ currentValue: currentCol.type,
164
+ incomingValue: incomingCol.type,
165
+ description: `Type differs: ${currentCol.type} vs ${incomingCol.type}`,
166
+ });
167
+ }
168
+ }
169
+ }
170
+ for (const currentEnum of current.enums) {
171
+ const incomingEnum = incoming.enums.find(e => e.name === currentEnum.name);
172
+ if (!incomingEnum)
173
+ continue;
174
+ const currentVals = JSON.stringify(currentEnum.values.sort());
175
+ const incomingVals = JSON.stringify(incomingEnum.values.sort());
176
+ if (currentVals !== incomingVals) {
177
+ conflicts.push({
178
+ objectType: 'ENUM',
179
+ objectName: currentEnum.name,
180
+ currentValue: currentEnum.values,
181
+ incomingValue: incomingEnum.values,
182
+ description: 'Values differ',
183
+ });
184
+ }
185
+ }
186
+ return conflicts;
187
+ }
188
+ function mergeSnapshots(current, incoming) {
189
+ const result = JSON.parse(JSON.stringify(current));
190
+ for (const table of incoming.tables) {
191
+ if (!result.tables.find(t => t.name === table.name)) {
192
+ result.tables.push(table);
193
+ }
194
+ }
195
+ for (const e of incoming.enums) {
196
+ if (!result.enums.find(x => x.name === e.name)) {
197
+ result.enums.push(e);
198
+ }
199
+ }
200
+ for (const d of incoming.domains) {
201
+ if (!result.domains.find(x => x.name === d.name)) {
202
+ result.domains.push(d);
203
+ }
204
+ }
205
+ return result;
206
+ }
207
+ exports.default = mergeCommand;
@@ -36,9 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.migrateCommand = migrateCommand;
37
37
  const fs = __importStar(require("fs"));
38
38
  const path = __importStar(require("path"));
39
- const readline = __importStar(require("readline"));
40
39
  const config_loader_1 = require("../utils/config-loader.cjs");
41
40
  const env_loader_1 = require("../utils/env-loader.cjs");
41
+ const cli_utils_1 = require("../utils/cli-utils.cjs");
42
42
  function parseMigration(content) {
43
43
  const upMatch = content.match(/--\s*UP\s*\n([\s\S]*?)(?=--\s*DOWN|$)/i);
44
44
  const downMatch = content.match(/--\s*DOWN\s*\n([\s\S]*?)$/i);
@@ -47,35 +47,23 @@ function parseMigration(content) {
47
47
  down: downMatch?.[1]?.trim() || '',
48
48
  };
49
49
  }
50
- function askConfirm(question) {
51
- const rl = readline.createInterface({
52
- input: process.stdin,
53
- output: process.stdout,
54
- });
55
- return new Promise((resolve) => {
56
- rl.question(`${question} [y/N]: `, (answer) => {
57
- rl.close();
58
- resolve(answer.trim().toLowerCase() === 'y');
59
- });
60
- });
61
- }
62
50
  async function migrateCommand(context) {
63
51
  const { config, flags } = context;
64
52
  if (!config) {
65
- console.error('Error: No configuration found.');
66
- process.exit(1);
53
+ (0, cli_utils_1.fatal)('No configuration found', `run ${cli_utils_1.colors.cyan('relq init')} to create a configuration file`);
54
+ return;
67
55
  }
68
- (0, config_loader_1.requireValidConfig)(config);
56
+ await (0, config_loader_1.requireValidConfig)(config, { calledFrom: 'migrate' });
69
57
  const dryRun = flags['dry-run'] === true;
70
58
  const force = flags['force'] === true;
71
59
  const connection = config.connection;
72
60
  const migrationsDir = config.migrations?.directory || './migrations';
73
61
  const tableName = config.migrations?.tableName || '_relq_migrations';
74
- console.log('šŸ”„ Running migrations...');
62
+ console.log('Running migrations...');
75
63
  console.log(` Connection: ${(0, env_loader_1.getConnectionDescription)(connection)}`);
76
64
  console.log(` Migrations: ${migrationsDir}\n`);
77
65
  try {
78
- const { Pool } = await Promise.resolve().then(() => __importStar(require("../../../addons/pg.js")));
66
+ const { Pool } = await Promise.resolve().then(() => __importStar(require("../../addon/pg/index.cjs")));
79
67
  const pool = new Pool({
80
68
  host: connection.host,
81
69
  port: connection.port || 5432,
@@ -105,16 +93,16 @@ async function migrateCommand(context) {
105
93
  .sort();
106
94
  const pending = migrationFiles.filter(f => !appliedMigrations.has(f));
107
95
  if (pending.length === 0) {
108
- console.log('āœ… No pending migrations.');
96
+ console.log('No pending migrations.');
109
97
  return;
110
98
  }
111
- console.log(`šŸ“‹ Pending migrations (${pending.length}):`);
99
+ console.log(`Pending migrations (${pending.length}):`);
112
100
  for (const file of pending) {
113
101
  console.log(` • ${file}`);
114
102
  }
115
103
  console.log('');
116
104
  if (!force && !dryRun) {
117
- if (!await askConfirm('Apply these migrations?')) {
105
+ if (!await (0, cli_utils_1.confirm)('Apply these migrations?', false)) {
118
106
  console.log('Cancelled.');
119
107
  return;
120
108
  }
@@ -124,7 +112,7 @@ async function migrateCommand(context) {
124
112
  const content = fs.readFileSync(filePath, 'utf-8');
125
113
  const { up } = parseMigration(content);
126
114
  if (!up) {
127
- console.log(`āš ļø Skipping ${file} (no UP section)`);
115
+ (0, cli_utils_1.warning)(`Skipping ${file} (no UP section)`);
128
116
  continue;
129
117
  }
130
118
  if (dryRun) {
@@ -141,7 +129,7 @@ async function migrateCommand(context) {
141
129
  await client.query(up);
142
130
  await client.query(`INSERT INTO "${tableName}" (name) VALUES ($1)`, [file]);
143
131
  await client.query('COMMIT');
144
- console.log(` āœ… Applied`);
132
+ console.log(' Applied');
145
133
  }
146
134
  catch (error) {
147
135
  await client.query('ROLLBACK');
@@ -153,7 +141,7 @@ async function migrateCommand(context) {
153
141
  }
154
142
  }
155
143
  if (!dryRun) {
156
- console.log(`\nāœ… Applied ${pending.length} migration(s).`);
144
+ console.log(`\nApplied ${pending.length} migration(s).`);
157
145
  }
158
146
  }
159
147
  finally {
@@ -161,7 +149,6 @@ async function migrateCommand(context) {
161
149
  }
162
150
  }
163
151
  catch (error) {
164
- console.error('Error:', error instanceof Error ? error.message : error);
165
- process.exit(1);
152
+ (0, cli_utils_1.fatal)('Migration failed', error instanceof Error ? error.message : String(error));
166
153
  }
167
154
  }