clickhouse-migrations 0.1.8 → 0.1.9
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/lib/cli.js +2 -2
- package/lib/migrate.js +22 -12
- package/package.json +12 -10
package/lib/cli.js
CHANGED
package/lib/migrate.js
CHANGED
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -35,12 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
38
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
42
|
exports.migrate = void 0;
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var
|
|
43
|
+
var client_1 = require("@clickhouse/client");
|
|
44
|
+
var commander_1 = require("commander");
|
|
45
|
+
var fs_1 = __importDefault(require("fs"));
|
|
46
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
44
47
|
// Extract SQL queries from migrations.
|
|
45
48
|
var sql_queries = function (content) {
|
|
46
49
|
var queries = content
|
|
@@ -71,7 +74,7 @@ var connect = function (host, username, password, db_name) {
|
|
|
71
74
|
if (db_name) {
|
|
72
75
|
db_params.database = db_name;
|
|
73
76
|
}
|
|
74
|
-
return
|
|
77
|
+
return (0, client_1.createClient)(db_params);
|
|
75
78
|
};
|
|
76
79
|
var create_db = function (host, username, password, db_name) { return __awaiter(void 0, void 0, void 0, function () {
|
|
77
80
|
var client, q, e_1;
|
|
@@ -85,6 +88,9 @@ var create_db = function (host, username, password, db_name) { return __awaiter(
|
|
|
85
88
|
_a.trys.push([1, 3, , 4]);
|
|
86
89
|
return [4 /*yield*/, client.exec({
|
|
87
90
|
query: q,
|
|
91
|
+
clickhouse_settings: {
|
|
92
|
+
wait_end_of_query: 1,
|
|
93
|
+
},
|
|
88
94
|
})];
|
|
89
95
|
case 2:
|
|
90
96
|
_a.sent();
|
|
@@ -112,6 +118,9 @@ var init_migration_table = function (client) { return __awaiter(void 0, void 0,
|
|
|
112
118
|
_a.trys.push([1, 3, , 4]);
|
|
113
119
|
return [4 /*yield*/, client.exec({
|
|
114
120
|
query: q,
|
|
121
|
+
clickhouse_settings: {
|
|
122
|
+
wait_end_of_query: 1,
|
|
123
|
+
},
|
|
115
124
|
})];
|
|
116
125
|
case 2:
|
|
117
126
|
_a.sent();
|
|
@@ -128,7 +137,7 @@ var init_migration_table = function (client) { return __awaiter(void 0, void 0,
|
|
|
128
137
|
var get_migrations = function (migrations_home) {
|
|
129
138
|
var files;
|
|
130
139
|
try {
|
|
131
|
-
files =
|
|
140
|
+
files = fs_1.default.readdirSync(migrations_home);
|
|
132
141
|
}
|
|
133
142
|
catch (e) {
|
|
134
143
|
log('error', "no migration directory ".concat(migrations_home, ". Please create it."));
|
|
@@ -177,9 +186,10 @@ var apply_migrations = function (client, migrations, migrations_home) { return _
|
|
|
177
186
|
process.exit(1);
|
|
178
187
|
return [3 /*break*/, 5];
|
|
179
188
|
case 5:
|
|
180
|
-
migrations_applied =
|
|
189
|
+
migrations_applied = [];
|
|
181
190
|
migration_query_result.forEach(function (row) {
|
|
182
191
|
migrations_applied[row.version] = {
|
|
192
|
+
version: row.version,
|
|
183
193
|
checksum: row.checksum,
|
|
184
194
|
migration_name: row.migration_name,
|
|
185
195
|
};
|
|
@@ -199,8 +209,8 @@ var apply_migrations = function (client, migrations, migrations_home) { return _
|
|
|
199
209
|
case 6:
|
|
200
210
|
if (!(_i < migrations_1.length)) return [3 /*break*/, 17];
|
|
201
211
|
migration_1 = migrations_1[_i];
|
|
202
|
-
content =
|
|
203
|
-
checksum =
|
|
212
|
+
content = fs_1.default.readFileSync(migrations_home + '/' + migration_1.file).toString();
|
|
213
|
+
checksum = crypto_1.default.createHash('md5').update(content).digest('hex');
|
|
204
214
|
if (migrations_applied[migration_1.version]) {
|
|
205
215
|
// Check if migration file was not changed after apply.
|
|
206
216
|
if (migrations_applied[migration_1.version].checksum !== checksum) {
|
|
@@ -292,8 +302,8 @@ var migration = function (migrations_home, host, username, password, db_name) {
|
|
|
292
302
|
});
|
|
293
303
|
}); };
|
|
294
304
|
var migrate = function () {
|
|
295
|
-
var program = new Command();
|
|
296
|
-
program.name('clickhouse-migrations').description('ClickHouse migrations.').version('0.1.
|
|
305
|
+
var program = new commander_1.Command();
|
|
306
|
+
program.name('clickhouse-migrations').description('ClickHouse migrations.').version('0.1.9');
|
|
297
307
|
program
|
|
298
308
|
.command('migrate')
|
|
299
309
|
.description('Apply migrations.')
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clickhouse-migrations",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "CLI NodeJS ClickHouse Migrations",
|
|
5
5
|
"bin": {
|
|
6
6
|
"clickhouse-migrations": "lib/cli.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "tsc",
|
|
9
|
+
"build": "rm lib/*; tsc",
|
|
10
10
|
"test": "jest --config jestconfig.json",
|
|
11
11
|
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
12
|
-
"lint": "eslint ./src
|
|
12
|
+
"lint": "eslint ./src --ext .ts",
|
|
13
13
|
"prepare": "npm run build",
|
|
14
14
|
"prepublishOnly": "npm test && npm run lint",
|
|
15
15
|
"preversion": "npm run lint",
|
|
@@ -20,19 +20,21 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"repository": "VVVi/clickhouse-migrations",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@clickhouse/client": "^0.0.
|
|
23
|
+
"@clickhouse/client": "^0.0.10",
|
|
24
24
|
"commander": "^9.4.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/jest": "^29.2.
|
|
27
|
+
"@types/jest": "^29.2.3",
|
|
28
28
|
"@types/node": "^18.11.9",
|
|
29
|
-
"@typescript-eslint/parser": "^5.
|
|
30
|
-
"eslint": "^
|
|
29
|
+
"@typescript-eslint/parser": "^5.44.0",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
|
31
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
32
|
+
"eslint": "^8.28.0",
|
|
31
33
|
"eslint-config-prettier": "^8.5.0",
|
|
32
|
-
"jest": "^29.
|
|
33
|
-
"prettier": "^2.
|
|
34
|
+
"jest": "^29.3.1",
|
|
35
|
+
"prettier": "^2.8.0",
|
|
34
36
|
"ts-jest": "^29.0.3",
|
|
35
|
-
"typescript": "^4.
|
|
37
|
+
"typescript": "^4.9.3"
|
|
36
38
|
},
|
|
37
39
|
"files": [
|
|
38
40
|
"lib/**/*"
|