relq 1.0.2 ā 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/cli/commands/add.cjs +403 -27
- package/dist/cjs/cli/commands/branch.cjs +13 -23
- package/dist/cjs/cli/commands/checkout.cjs +16 -29
- package/dist/cjs/cli/commands/cherry-pick.cjs +3 -4
- package/dist/cjs/cli/commands/commit.cjs +21 -29
- package/dist/cjs/cli/commands/diff.cjs +28 -32
- package/dist/cjs/cli/commands/export.cjs +7 -7
- package/dist/cjs/cli/commands/fetch.cjs +15 -21
- 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 +34 -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 +26 -32
- package/dist/cjs/cli/commands/merge.cjs +24 -41
- package/dist/cjs/cli/commands/migrate.cjs +12 -25
- package/dist/cjs/cli/commands/pull.cjs +216 -106
- package/dist/cjs/cli/commands/push.cjs +35 -75
- package/dist/cjs/cli/commands/remote.cjs +2 -1
- package/dist/cjs/cli/commands/reset.cjs +22 -43
- package/dist/cjs/cli/commands/resolve.cjs +12 -14
- package/dist/cjs/cli/commands/rollback.cjs +16 -38
- package/dist/cjs/cli/commands/stash.cjs +5 -7
- package/dist/cjs/cli/commands/status.cjs +5 -10
- package/dist/cjs/cli/commands/sync.cjs +30 -50
- package/dist/cjs/cli/commands/tag.cjs +3 -4
- package/dist/cjs/cli/index.cjs +72 -9
- 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/config-loader.cjs +34 -8
- package/dist/cjs/cli/utils/fast-introspect.cjs +109 -3
- 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 +56 -5
- package/dist/cjs/cli/utils/relqignore.cjs +1 -0
- package/dist/cjs/cli/utils/repo-manager.cjs +47 -0
- 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 +7 -3
- 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 +1 -1
- package/dist/cjs/cli/utils/type-generator.cjs +28 -16
- package/dist/config.d.ts +16 -25
- package/dist/esm/cli/commands/add.js +372 -29
- package/dist/esm/cli/commands/branch.js +14 -24
- package/dist/esm/cli/commands/checkout.js +16 -29
- package/dist/esm/cli/commands/cherry-pick.js +3 -4
- package/dist/esm/cli/commands/commit.js +22 -30
- package/dist/esm/cli/commands/diff.js +6 -10
- package/dist/esm/cli/commands/export.js +8 -8
- package/dist/esm/cli/commands/fetch.js +14 -20
- 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 +35 -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 +6 -12
- package/dist/esm/cli/commands/merge.js +20 -37
- package/dist/esm/cli/commands/migrate.js +12 -25
- package/dist/esm/cli/commands/pull.js +204 -94
- package/dist/esm/cli/commands/push.js +21 -61
- package/dist/esm/cli/commands/remote.js +2 -1
- package/dist/esm/cli/commands/reset.js +16 -37
- package/dist/esm/cli/commands/resolve.js +13 -15
- package/dist/esm/cli/commands/rollback.js +16 -38
- package/dist/esm/cli/commands/stash.js +6 -8
- package/dist/esm/cli/commands/status.js +6 -11
- package/dist/esm/cli/commands/sync.js +30 -50
- package/dist/esm/cli/commands/tag.js +3 -4
- package/dist/esm/cli/index.js +72 -9
- 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/config-loader.js +34 -8
- package/dist/esm/cli/utils/fast-introspect.js +109 -3
- 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 +55 -5
- package/dist/esm/cli/utils/relqignore.js +1 -0
- package/dist/esm/cli/utils/repo-manager.js +42 -0
- 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 +7 -3
- 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 +1 -1
- package/dist/esm/cli/utils/type-generator.js +28 -16
- package/dist/index.d.ts +25 -8
- package/dist/schema-builder.d.ts +16 -6
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.logCommand = logCommand;
|
|
4
4
|
exports.historyCommand = logCommand;
|
|
5
5
|
exports.showCommand = showCommand;
|
|
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
|
function formatDate(timestamp) {
|
|
9
9
|
const date = new Date(timestamp);
|
|
@@ -17,43 +17,38 @@ function formatDate(timestamp) {
|
|
|
17
17
|
return `${dayName} ${monthName} ${day} ${time} ${year}`;
|
|
18
18
|
}
|
|
19
19
|
async function logCommand(context) {
|
|
20
|
-
const { flags } = context;
|
|
21
|
-
const projectRoot = process.cwd();
|
|
20
|
+
const { flags, projectRoot } = context;
|
|
22
21
|
const limit = parseInt(flags['n']) || 10;
|
|
23
22
|
const oneline = flags['oneline'] === true;
|
|
24
23
|
console.log('');
|
|
25
24
|
if (!(0, repo_manager_1.isInitialized)(projectRoot)) {
|
|
26
|
-
|
|
27
|
-
console.log('');
|
|
28
|
-
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq init')} ${spinner_1.colors.muted('to initialize.')}`);
|
|
29
|
-
return;
|
|
25
|
+
(0, cli_utils_1.fatal)('not a relq repository (or any parent directories): .relq', "run 'relq init' to initialize");
|
|
30
26
|
}
|
|
31
27
|
const head = (0, repo_manager_1.getHead)(projectRoot);
|
|
32
28
|
const commits = (0, repo_manager_1.getCommitHistory)(limit, projectRoot);
|
|
33
29
|
if (commits.length === 0) {
|
|
34
|
-
console.log(
|
|
35
|
-
|
|
36
|
-
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq commit -m "message"')} ${spinner_1.colors.muted('to create first commit.')}`);
|
|
30
|
+
console.log('No commits yet.');
|
|
31
|
+
(0, cli_utils_1.hint)("run 'relq commit -m <message>' to create first commit");
|
|
37
32
|
console.log('');
|
|
38
33
|
return;
|
|
39
34
|
}
|
|
40
35
|
for (const commit of commits) {
|
|
41
36
|
const isHead = commit.hash === head;
|
|
42
37
|
if (oneline) {
|
|
43
|
-
const headMarker = isHead ? `${
|
|
44
|
-
console.log(`${
|
|
38
|
+
const headMarker = isHead ? `${cli_utils_1.colors.cyan('(HEAD)')} ` : '';
|
|
39
|
+
console.log(`${cli_utils_1.colors.yellow((0, repo_manager_1.shortHash)(commit.hash))} ${headMarker}${commit.message}`);
|
|
45
40
|
}
|
|
46
41
|
else {
|
|
47
|
-
console.log(`${
|
|
42
|
+
console.log(`${cli_utils_1.colors.yellow(`commit ${commit.hash}`)}`);
|
|
48
43
|
if (isHead) {
|
|
49
|
-
console.log(`${
|
|
44
|
+
console.log(`${cli_utils_1.colors.cyan('(HEAD)')}`);
|
|
50
45
|
}
|
|
51
46
|
console.log(`Author: ${commit.author}`);
|
|
52
47
|
console.log(`Date: ${formatDate(commit.timestamp)}`);
|
|
53
48
|
console.log('');
|
|
54
49
|
console.log(` ${commit.message}`);
|
|
55
50
|
console.log('');
|
|
56
|
-
console.log(` ${
|
|
51
|
+
console.log(` ${cli_utils_1.colors.muted(`${commit.stats.tables} tables, ${commit.stats.columns} columns`)}`);
|
|
57
52
|
console.log('');
|
|
58
53
|
}
|
|
59
54
|
}
|
|
@@ -62,18 +57,17 @@ async function logCommand(context) {
|
|
|
62
57
|
}
|
|
63
58
|
}
|
|
64
59
|
async function showCommand(context) {
|
|
65
|
-
const { args } = context;
|
|
66
|
-
const projectRoot = process.cwd();
|
|
60
|
+
const { args, projectRoot } = context;
|
|
67
61
|
const target = args[0];
|
|
68
62
|
console.log('');
|
|
69
63
|
if (!(0, repo_manager_1.isInitialized)(projectRoot)) {
|
|
70
|
-
console.log(`${
|
|
64
|
+
console.log(`${cli_utils_1.colors.red('fatal:')} not a relq repository`);
|
|
71
65
|
return;
|
|
72
66
|
}
|
|
73
67
|
if (!target) {
|
|
74
|
-
console.log(`${
|
|
68
|
+
console.log(`${cli_utils_1.colors.red('error:')} Please specify a commit or tag`);
|
|
75
69
|
console.log('');
|
|
76
|
-
console.log(`Usage: ${
|
|
70
|
+
console.log(`Usage: ${cli_utils_1.colors.cyan('relq show <commit|tag>')}`);
|
|
77
71
|
console.log('');
|
|
78
72
|
return;
|
|
79
73
|
}
|
|
@@ -82,56 +76,56 @@ async function showCommand(context) {
|
|
|
82
76
|
const { resolveRef, loadCommit } = require("../utils/repo-manager.cjs");
|
|
83
77
|
const hash = resolveRef(target, projectRoot);
|
|
84
78
|
if (!hash) {
|
|
85
|
-
console.log(`${
|
|
79
|
+
console.log(`${cli_utils_1.colors.red('error:')} Commit or tag not found: ${target}`);
|
|
86
80
|
console.log('');
|
|
87
81
|
console.log('Available commits:');
|
|
88
82
|
const commitsDir = path.join(projectRoot, '.relq', 'commits');
|
|
89
83
|
if (fs.existsSync(commitsDir)) {
|
|
90
84
|
const files = fs.readdirSync(commitsDir);
|
|
91
85
|
for (const f of files.slice(0, 5)) {
|
|
92
|
-
console.log(` ${
|
|
86
|
+
console.log(` ${cli_utils_1.colors.yellow((0, repo_manager_1.shortHash)(f.replace('.json', '')))}`);
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
89
|
return;
|
|
96
90
|
}
|
|
97
91
|
const commitPath = path.join(projectRoot, '.relq', 'commits', `${hash}.json`);
|
|
98
92
|
if (!fs.existsSync(commitPath)) {
|
|
99
|
-
console.log(`${
|
|
93
|
+
console.log(`${cli_utils_1.colors.red('error:')} Commit not found: ${hash}`);
|
|
100
94
|
return;
|
|
101
95
|
}
|
|
102
96
|
const commitData = JSON.parse(fs.readFileSync(commitPath, 'utf-8'));
|
|
103
|
-
console.log(`${
|
|
97
|
+
console.log(`${cli_utils_1.colors.yellow(`commit ${commitData.hash}`)}`);
|
|
104
98
|
console.log(`Author: ${commitData.author}`);
|
|
105
99
|
console.log(`Date: ${formatDate(commitData.timestamp)}`);
|
|
106
100
|
console.log('');
|
|
107
101
|
console.log(` ${commitData.message}`);
|
|
108
102
|
console.log('');
|
|
109
103
|
if (commitData.stats) {
|
|
110
|
-
console.log(`${
|
|
104
|
+
console.log(`${cli_utils_1.colors.bold('Stats:')}`);
|
|
111
105
|
console.log(` Tables: ${commitData.stats.tables}`);
|
|
112
106
|
console.log(` Columns: ${commitData.stats.columns}`);
|
|
113
107
|
console.log(` Indexes: ${commitData.stats.indexes || 0}`);
|
|
114
108
|
console.log('');
|
|
115
109
|
}
|
|
116
110
|
if (commitData.changes && commitData.changes.length > 0) {
|
|
117
|
-
console.log(`${
|
|
111
|
+
console.log(`${cli_utils_1.colors.bold('Changes:')}`);
|
|
118
112
|
for (const change of commitData.changes.slice(0, 20)) {
|
|
119
113
|
const symbol = change.action === 'CREATE'
|
|
120
|
-
?
|
|
114
|
+
? cli_utils_1.colors.green('+')
|
|
121
115
|
: change.action === 'DROP'
|
|
122
|
-
?
|
|
123
|
-
:
|
|
116
|
+
? cli_utils_1.colors.red('-')
|
|
117
|
+
: cli_utils_1.colors.yellow('~');
|
|
124
118
|
console.log(` ${symbol} ${change.objectType.toLowerCase()}: ${change.name}`);
|
|
125
119
|
}
|
|
126
120
|
if (commitData.changes.length > 20) {
|
|
127
|
-
console.log(` ${
|
|
121
|
+
console.log(` ${cli_utils_1.colors.muted(`... and ${commitData.changes.length - 20} more`)}`);
|
|
128
122
|
}
|
|
129
123
|
console.log('');
|
|
130
124
|
}
|
|
131
125
|
if (commitData.sql && commitData.sql.trim()) {
|
|
132
|
-
console.log(`${
|
|
126
|
+
console.log(`${cli_utils_1.colors.bold('SQL:')}`);
|
|
133
127
|
console.log('');
|
|
134
|
-
console.log(`${
|
|
128
|
+
console.log(`${cli_utils_1.colors.cyan(commitData.sql)}`);
|
|
135
129
|
console.log('');
|
|
136
130
|
}
|
|
137
131
|
}
|
|
@@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.mergeCommand = mergeCommand;
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
|
-
const
|
|
39
|
+
const cli_utils_1 = require("../utils/cli-utils.cjs");
|
|
40
40
|
const repo_manager_1 = require("../utils/repo-manager.cjs");
|
|
41
41
|
function loadBranchState(projectRoot) {
|
|
42
42
|
const branchPath = path.join(projectRoot, '.relq', 'branches.json');
|
|
@@ -51,12 +51,10 @@ function saveBranchState(state, projectRoot) {
|
|
|
51
51
|
fs.writeFileSync(branchPath, JSON.stringify(state, null, 2));
|
|
52
52
|
}
|
|
53
53
|
async function mergeCommand(context) {
|
|
54
|
-
const { config, args, flags } = context;
|
|
55
|
-
const projectRoot = process.cwd();
|
|
54
|
+
const { config, args, flags, projectRoot } = context;
|
|
56
55
|
console.log('');
|
|
57
56
|
if (!(0, repo_manager_1.isInitialized)(projectRoot)) {
|
|
58
|
-
|
|
59
|
-
return;
|
|
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.`);
|
|
60
58
|
}
|
|
61
59
|
const branchName = args[0];
|
|
62
60
|
const abort = flags['abort'] === true;
|
|
@@ -64,47 +62,36 @@ async function mergeCommand(context) {
|
|
|
64
62
|
if (abort) {
|
|
65
63
|
if (fs.existsSync(mergeStatePath)) {
|
|
66
64
|
fs.unlinkSync(mergeStatePath);
|
|
67
|
-
console.log(
|
|
65
|
+
console.log('Merge aborted');
|
|
66
|
+
console.log('');
|
|
67
|
+
return;
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
|
-
|
|
70
|
+
(0, cli_utils_1.fatal)('There is no merge to abort (MERGE_STATE missing)');
|
|
71
71
|
}
|
|
72
|
-
console.log('');
|
|
73
|
-
return;
|
|
74
72
|
}
|
|
75
73
|
if (fs.existsSync(mergeStatePath)) {
|
|
76
74
|
const mergeState = JSON.parse(fs.readFileSync(mergeStatePath, 'utf-8'));
|
|
77
|
-
|
|
78
|
-
console.log('');
|
|
79
|
-
console.log(`${spinner_1.colors.muted('Use')} ${spinner_1.colors.cyan('relq resolve')} ${spinner_1.colors.muted('to resolve conflicts')}`);
|
|
80
|
-
console.log(`${spinner_1.colors.muted('Or')} ${spinner_1.colors.cyan('relq merge --abort')} ${spinner_1.colors.muted('to cancel')}`);
|
|
81
|
-
console.log('');
|
|
82
|
-
return;
|
|
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`);
|
|
83
76
|
}
|
|
84
77
|
if (!branchName) {
|
|
85
|
-
|
|
86
|
-
console.log('');
|
|
87
|
-
console.log(`Usage: ${spinner_1.colors.cyan('relq merge <branch>')}`);
|
|
88
|
-
console.log('');
|
|
89
|
-
return;
|
|
78
|
+
(0, cli_utils_1.fatal)('Please specify a branch to merge', `Usage: ${cli_utils_1.colors.cyan('relq merge <branch>')}`);
|
|
90
79
|
}
|
|
91
80
|
const state = loadBranchState(projectRoot);
|
|
92
81
|
if (!state.branches[branchName]) {
|
|
93
|
-
|
|
94
|
-
return;
|
|
82
|
+
(0, cli_utils_1.fatal)(`Branch not found: ${branchName}`, `Use ${cli_utils_1.colors.cyan('relq branch')} to list available branches.`);
|
|
95
83
|
}
|
|
96
84
|
if (branchName === state.current) {
|
|
97
|
-
|
|
98
|
-
return;
|
|
85
|
+
(0, cli_utils_1.fatal)('Cannot merge branch into itself');
|
|
99
86
|
}
|
|
100
|
-
const spinner = (0,
|
|
87
|
+
const spinner = (0, cli_utils_1.createSpinner)();
|
|
101
88
|
spinner.start(`Merging '${branchName}' into '${state.current}'...`);
|
|
102
89
|
try {
|
|
103
90
|
const currentHash = (0, repo_manager_1.getHead)(projectRoot);
|
|
104
91
|
const incomingHash = state.branches[branchName];
|
|
105
92
|
if (!currentHash || !incomingHash) {
|
|
106
|
-
spinner.
|
|
107
|
-
|
|
93
|
+
spinner.stop();
|
|
94
|
+
(0, cli_utils_1.fatal)('No commits to merge', `Run ${cli_utils_1.colors.cyan('relq pull')} first.`);
|
|
108
95
|
}
|
|
109
96
|
if (currentHash === incomingHash) {
|
|
110
97
|
spinner.succeed('Already up to date');
|
|
@@ -114,14 +101,14 @@ async function mergeCommand(context) {
|
|
|
114
101
|
const currentCommit = (0, repo_manager_1.loadCommit)(currentHash, projectRoot);
|
|
115
102
|
const incomingCommit = (0, repo_manager_1.loadCommit)(incomingHash, projectRoot);
|
|
116
103
|
if (!currentCommit || !incomingCommit) {
|
|
117
|
-
spinner.
|
|
118
|
-
|
|
104
|
+
spinner.stop();
|
|
105
|
+
(0, cli_utils_1.fatal)('Cannot load commit data - repository may be corrupt');
|
|
119
106
|
}
|
|
120
107
|
const currentSnapshot = (0, repo_manager_1.loadSnapshot)(projectRoot) || currentCommit.schema;
|
|
121
108
|
const incomingSnapshot = incomingCommit.schema;
|
|
122
109
|
if (!currentSnapshot || !incomingSnapshot) {
|
|
123
|
-
spinner.
|
|
124
|
-
|
|
110
|
+
spinner.stop();
|
|
111
|
+
(0, cli_utils_1.fatal)('No snapshot data - repository may be corrupt');
|
|
125
112
|
}
|
|
126
113
|
const conflicts = detectMergeConflicts(currentSnapshot, incomingSnapshot);
|
|
127
114
|
if (conflicts.length > 0) {
|
|
@@ -137,16 +124,12 @@ async function mergeCommand(context) {
|
|
|
137
124
|
console.log('');
|
|
138
125
|
for (const c of conflicts.slice(0, 5)) {
|
|
139
126
|
const name = c.parentName ? `${c.parentName}.${c.objectName}` : c.objectName;
|
|
140
|
-
console.log(` ${
|
|
127
|
+
console.log(` ${cli_utils_1.colors.red('conflict:')} ${c.objectType.toLowerCase()} ${name}`);
|
|
141
128
|
}
|
|
142
129
|
if (conflicts.length > 5) {
|
|
143
|
-
console.log(` ${
|
|
130
|
+
console.log(` ${cli_utils_1.colors.muted(`... and ${conflicts.length - 5} more`)}`);
|
|
144
131
|
}
|
|
145
|
-
|
|
146
|
-
console.log(`${spinner_1.colors.muted('Use')} ${spinner_1.colors.cyan('relq resolve --all-theirs')} ${spinner_1.colors.muted('to accept incoming')}`);
|
|
147
|
-
console.log(`${spinner_1.colors.muted('Or')} ${spinner_1.colors.cyan('relq merge --abort')} ${spinner_1.colors.muted('to cancel')}`);
|
|
148
|
-
console.log('');
|
|
149
|
-
return;
|
|
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`);
|
|
150
133
|
}
|
|
151
134
|
const mergedSnapshot = mergeSnapshots(currentSnapshot, incomingSnapshot);
|
|
152
135
|
(0, repo_manager_1.saveSnapshot)(mergedSnapshot, projectRoot);
|
|
@@ -154,12 +137,12 @@ async function mergeCommand(context) {
|
|
|
154
137
|
const message = `Merge branch '${branchName}' into ${state.current}`;
|
|
155
138
|
const commit = (0, repo_manager_1.createCommit)(mergedSnapshot, author, message, projectRoot);
|
|
156
139
|
spinner.succeed(`Merged '${branchName}' into '${state.current}'`);
|
|
157
|
-
console.log(` ${
|
|
140
|
+
console.log(` ${cli_utils_1.colors.yellow((0, repo_manager_1.shortHash)(commit.hash))} ${message}`);
|
|
158
141
|
console.log('');
|
|
159
142
|
}
|
|
160
|
-
catch (
|
|
143
|
+
catch (err) {
|
|
161
144
|
spinner.fail('Merge failed');
|
|
162
|
-
|
|
145
|
+
(0, cli_utils_1.fatal)(err instanceof Error ? err.message : String(err));
|
|
163
146
|
}
|
|
164
147
|
}
|
|
165
148
|
function detectMergeConflicts(current, incoming) {
|
|
@@ -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,31 +47,19 @@ 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
|
-
|
|
66
|
-
|
|
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('
|
|
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 {
|
|
@@ -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('
|
|
96
|
+
console.log('No pending migrations.');
|
|
109
97
|
return;
|
|
110
98
|
}
|
|
111
|
-
console.log(
|
|
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
|
|
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
|
-
|
|
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(
|
|
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(`\
|
|
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
|
-
|
|
165
|
-
process.exit(1);
|
|
152
|
+
(0, cli_utils_1.fatal)('Migration failed', error instanceof Error ? error.message : String(error));
|
|
166
153
|
}
|
|
167
154
|
}
|