relq 1.0.53 → 1.0.54
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.
|
@@ -1,6 +1,41 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.syncCommand = syncCommand;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
4
39
|
const config_loader_1 = require("../utils/config-loader.cjs");
|
|
5
40
|
const env_loader_1 = require("../utils/env-loader.cjs");
|
|
6
41
|
const cli_utils_1 = require("../utils/cli-utils.cjs");
|
|
@@ -38,18 +73,97 @@ async function syncCommand(context) {
|
|
|
38
73
|
}
|
|
39
74
|
console.log(`Pushing ${toPush.length} local commit(s)...`);
|
|
40
75
|
console.log('');
|
|
76
|
+
const commitsToProcess = [...toPush].reverse();
|
|
77
|
+
spinner.start('Applying schema changes...');
|
|
78
|
+
const pg = await Promise.resolve().then(() => __importStar(require("../../addon/pg/index.cjs")));
|
|
79
|
+
const client = new pg.Client({
|
|
80
|
+
host: connection.host,
|
|
81
|
+
port: connection.port,
|
|
82
|
+
database: connection.database,
|
|
83
|
+
user: connection.user,
|
|
84
|
+
password: connection.password,
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
await client.connect();
|
|
88
|
+
await client.query('BEGIN');
|
|
89
|
+
let sqlExecuted = 0;
|
|
90
|
+
let statementsRun = 0;
|
|
91
|
+
for (const commit of commitsToProcess) {
|
|
92
|
+
const commitPath = path.join(projectRoot, '.relq', 'commits', `${commit.hash}.json`);
|
|
93
|
+
if (fs.existsSync(commitPath)) {
|
|
94
|
+
const enhancedCommit = JSON.parse(fs.readFileSync(commitPath, 'utf-8'));
|
|
95
|
+
if (enhancedCommit.sql && enhancedCommit.sql.trim()) {
|
|
96
|
+
const statements = enhancedCommit.sql
|
|
97
|
+
.split(';')
|
|
98
|
+
.map(s => s.trim())
|
|
99
|
+
.filter(s => s.length > 0);
|
|
100
|
+
for (const stmt of statements) {
|
|
101
|
+
try {
|
|
102
|
+
await client.query(stmt);
|
|
103
|
+
statementsRun++;
|
|
104
|
+
}
|
|
105
|
+
catch (stmtError) {
|
|
106
|
+
const err = new Error(stmtError.message);
|
|
107
|
+
err.failedStatement = stmt;
|
|
108
|
+
err.commitHash = commit.hash;
|
|
109
|
+
err.commitMessage = commit.message;
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
sqlExecuted++;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
await client.query('COMMIT');
|
|
118
|
+
if (statementsRun > 0) {
|
|
119
|
+
spinner.succeed(`Applied ${statementsRun} statement(s) from ${sqlExecuted} commit(s)`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
spinner.succeed('No SQL changes to apply');
|
|
123
|
+
}
|
|
124
|
+
for (const commit of commitsToProcess) {
|
|
125
|
+
await (0, repo_manager_1.markCommitAsApplied)(connection, commit.hash);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
try {
|
|
130
|
+
await client.query('ROLLBACK');
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
}
|
|
134
|
+
const dbError = error?.message || String(error);
|
|
135
|
+
let errorMsg = `${cli_utils_1.colors.red('SQL Error:')} ${dbError}\n`;
|
|
136
|
+
if (error.failedStatement) {
|
|
137
|
+
errorMsg += `\n${cli_utils_1.colors.yellow('Failed Statement:')}\n`;
|
|
138
|
+
errorMsg += ` ${error.failedStatement}\n`;
|
|
139
|
+
}
|
|
140
|
+
if (error.commitHash) {
|
|
141
|
+
errorMsg += `\n${cli_utils_1.colors.yellow('In Commit:')} ${(0, repo_manager_1.shortHash)(error.commitHash)}`;
|
|
142
|
+
if (error.commitMessage) {
|
|
143
|
+
errorMsg += ` - ${error.commitMessage}`;
|
|
144
|
+
}
|
|
145
|
+
errorMsg += `\n`;
|
|
146
|
+
}
|
|
147
|
+
errorMsg += `\n${cli_utils_1.colors.muted('All changes rolled back. No commits pushed.')}\n`;
|
|
148
|
+
spinner.fail('SQL execution failed');
|
|
149
|
+
throw new Error(errorMsg);
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
await client.end();
|
|
153
|
+
}
|
|
41
154
|
spinner.start(`Pushing ${toPush.length} commit(s)...`);
|
|
42
|
-
for (const commit of
|
|
43
|
-
await (0, repo_manager_1.pushCommit)(connection, commit);
|
|
155
|
+
for (const commit of commitsToProcess) {
|
|
156
|
+
await (0, repo_manager_1.pushCommit)(connection, commit, projectRoot);
|
|
157
|
+
(0, repo_manager_1.markCommitAsPushed)(commit.hash, connection, projectRoot);
|
|
44
158
|
}
|
|
45
|
-
spinner.succeed(`Pushed ${toPush.length} commit(s)`);
|
|
159
|
+
spinner.succeed(`Pushed ${toPush.length} commit(s) to ${(0, repo_manager_1.getConnectionLabel)(connection)}`);
|
|
46
160
|
console.log('');
|
|
47
161
|
console.log('Pushed commits:');
|
|
48
|
-
for (const commit of
|
|
162
|
+
for (const commit of commitsToProcess.slice(0, 5)) {
|
|
49
163
|
console.log(` ${cli_utils_1.colors.yellow((0, repo_manager_1.shortHash)(commit.hash))} ${commit.message}`);
|
|
50
164
|
}
|
|
51
|
-
if (
|
|
52
|
-
console.log(` ${cli_utils_1.colors.muted(`... and ${
|
|
165
|
+
if (commitsToProcess.length > 5) {
|
|
166
|
+
console.log(` ${cli_utils_1.colors.muted(`... and ${commitsToProcess.length - 5} more`)}`);
|
|
53
167
|
}
|
|
54
168
|
console.log('');
|
|
55
169
|
(0, cli_utils_1.success)(`Sync complete - pushed ${toPush.length} commit(s)`);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
1
3
|
import { requireValidConfig } from "../utils/config-loader.js";
|
|
2
4
|
import { getConnectionDescription } from "../utils/env-loader.js";
|
|
3
5
|
import { colors, createSpinner, fatal, success } from "../utils/cli-utils.js";
|
|
4
|
-
import { isInitialized, initRepository, shortHash, fetchRemoteCommits, pushCommit, ensureRemoteTable, getAllCommits, } from "../utils/repo-manager.js";
|
|
6
|
+
import { isInitialized, initRepository, shortHash, fetchRemoteCommits, pushCommit, ensureRemoteTable, getAllCommits, markCommitAsApplied, markCommitAsPushed, getConnectionLabel, } from "../utils/repo-manager.js";
|
|
5
7
|
import { pullCommand } from "./pull.js";
|
|
6
8
|
export async function syncCommand(context) {
|
|
7
9
|
const { config, flags } = context;
|
|
@@ -35,18 +37,97 @@ export async function syncCommand(context) {
|
|
|
35
37
|
}
|
|
36
38
|
console.log(`Pushing ${toPush.length} local commit(s)...`);
|
|
37
39
|
console.log('');
|
|
40
|
+
const commitsToProcess = [...toPush].reverse();
|
|
41
|
+
spinner.start('Applying schema changes...');
|
|
42
|
+
const pg = await import("../../addon/pg/index.js");
|
|
43
|
+
const client = new pg.Client({
|
|
44
|
+
host: connection.host,
|
|
45
|
+
port: connection.port,
|
|
46
|
+
database: connection.database,
|
|
47
|
+
user: connection.user,
|
|
48
|
+
password: connection.password,
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
await client.connect();
|
|
52
|
+
await client.query('BEGIN');
|
|
53
|
+
let sqlExecuted = 0;
|
|
54
|
+
let statementsRun = 0;
|
|
55
|
+
for (const commit of commitsToProcess) {
|
|
56
|
+
const commitPath = path.join(projectRoot, '.relq', 'commits', `${commit.hash}.json`);
|
|
57
|
+
if (fs.existsSync(commitPath)) {
|
|
58
|
+
const enhancedCommit = JSON.parse(fs.readFileSync(commitPath, 'utf-8'));
|
|
59
|
+
if (enhancedCommit.sql && enhancedCommit.sql.trim()) {
|
|
60
|
+
const statements = enhancedCommit.sql
|
|
61
|
+
.split(';')
|
|
62
|
+
.map(s => s.trim())
|
|
63
|
+
.filter(s => s.length > 0);
|
|
64
|
+
for (const stmt of statements) {
|
|
65
|
+
try {
|
|
66
|
+
await client.query(stmt);
|
|
67
|
+
statementsRun++;
|
|
68
|
+
}
|
|
69
|
+
catch (stmtError) {
|
|
70
|
+
const err = new Error(stmtError.message);
|
|
71
|
+
err.failedStatement = stmt;
|
|
72
|
+
err.commitHash = commit.hash;
|
|
73
|
+
err.commitMessage = commit.message;
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
sqlExecuted++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
await client.query('COMMIT');
|
|
82
|
+
if (statementsRun > 0) {
|
|
83
|
+
spinner.succeed(`Applied ${statementsRun} statement(s) from ${sqlExecuted} commit(s)`);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
spinner.succeed('No SQL changes to apply');
|
|
87
|
+
}
|
|
88
|
+
for (const commit of commitsToProcess) {
|
|
89
|
+
await markCommitAsApplied(connection, commit.hash);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
try {
|
|
94
|
+
await client.query('ROLLBACK');
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
}
|
|
98
|
+
const dbError = error?.message || String(error);
|
|
99
|
+
let errorMsg = `${colors.red('SQL Error:')} ${dbError}\n`;
|
|
100
|
+
if (error.failedStatement) {
|
|
101
|
+
errorMsg += `\n${colors.yellow('Failed Statement:')}\n`;
|
|
102
|
+
errorMsg += ` ${error.failedStatement}\n`;
|
|
103
|
+
}
|
|
104
|
+
if (error.commitHash) {
|
|
105
|
+
errorMsg += `\n${colors.yellow('In Commit:')} ${shortHash(error.commitHash)}`;
|
|
106
|
+
if (error.commitMessage) {
|
|
107
|
+
errorMsg += ` - ${error.commitMessage}`;
|
|
108
|
+
}
|
|
109
|
+
errorMsg += `\n`;
|
|
110
|
+
}
|
|
111
|
+
errorMsg += `\n${colors.muted('All changes rolled back. No commits pushed.')}\n`;
|
|
112
|
+
spinner.fail('SQL execution failed');
|
|
113
|
+
throw new Error(errorMsg);
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
await client.end();
|
|
117
|
+
}
|
|
38
118
|
spinner.start(`Pushing ${toPush.length} commit(s)...`);
|
|
39
|
-
for (const commit of
|
|
40
|
-
await pushCommit(connection, commit);
|
|
119
|
+
for (const commit of commitsToProcess) {
|
|
120
|
+
await pushCommit(connection, commit, projectRoot);
|
|
121
|
+
markCommitAsPushed(commit.hash, connection, projectRoot);
|
|
41
122
|
}
|
|
42
|
-
spinner.succeed(`Pushed ${toPush.length} commit(s)`);
|
|
123
|
+
spinner.succeed(`Pushed ${toPush.length} commit(s) to ${getConnectionLabel(connection)}`);
|
|
43
124
|
console.log('');
|
|
44
125
|
console.log('Pushed commits:');
|
|
45
|
-
for (const commit of
|
|
126
|
+
for (const commit of commitsToProcess.slice(0, 5)) {
|
|
46
127
|
console.log(` ${colors.yellow(shortHash(commit.hash))} ${commit.message}`);
|
|
47
128
|
}
|
|
48
|
-
if (
|
|
49
|
-
console.log(` ${colors.muted(`... and ${
|
|
129
|
+
if (commitsToProcess.length > 5) {
|
|
130
|
+
console.log(` ${colors.muted(`... and ${commitsToProcess.length - 5} more`)}`);
|
|
50
131
|
}
|
|
51
132
|
console.log('');
|
|
52
133
|
success(`Sync complete - pushed ${toPush.length} commit(s)`);
|
package/dist/schema-builder.d.ts
CHANGED
|
@@ -977,11 +977,11 @@ export declare const serial8: (columnName?: string) => ColumnBuilder<bigint, Col
|
|
|
977
977
|
export declare const decimal: (columnNameOrOpts?: string | number | {
|
|
978
978
|
precision?: number;
|
|
979
979
|
scale?: number;
|
|
980
|
-
}, scale?: number) => ColumnBuilder<string>;
|
|
980
|
+
}, scale?: number) => ColumnBuilder<string | number>;
|
|
981
981
|
export declare const numeric: (columnNameOrOpts?: string | number | {
|
|
982
982
|
precision?: number;
|
|
983
983
|
scale?: number;
|
|
984
|
-
}, scale?: number) => ColumnBuilder<string>;
|
|
984
|
+
}, scale?: number) => ColumnBuilder<string | number>;
|
|
985
985
|
export declare const real: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
|
|
986
986
|
export declare const float4: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
|
|
987
987
|
export declare const doublePrecision: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
|