clickhouse-migrations 0.1.5 → 0.1.7
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/README.md +5 -6
- package/lib/migrate.js +14 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,8 +22,8 @@ For migrations' content should be used correct SQL ClickHouse queries. A few que
|
|
|
22
22
|
$ clickhouse-migrations migrate <options>
|
|
23
23
|
|
|
24
24
|
Required options
|
|
25
|
-
--host=<name> Clickhouse hostname
|
|
26
|
-
|
|
25
|
+
--host=<name> Clickhouse hostname
|
|
26
|
+
(ex. https://clickhouse:8123)
|
|
27
27
|
--user=<name> Username
|
|
28
28
|
--password=<password> Password
|
|
29
29
|
--db=<name> Database name
|
|
@@ -32,15 +32,14 @@ For migrations' content should be used correct SQL ClickHouse queries. A few que
|
|
|
32
32
|
Environment variables
|
|
33
33
|
Instead of options can be used environment variables.
|
|
34
34
|
CH_MIGRATIONS_HOST Clickhouse hostname (--host)
|
|
35
|
-
CH_MIGRATIONS_PORT Port (--port)
|
|
36
35
|
CH_MIGRATIONS_USER Username (--user)
|
|
37
36
|
CH_MIGRATIONS_PASSWORD Password (--password)
|
|
38
37
|
CH_MIGRATIONS_DB Database name (--db)
|
|
39
38
|
CH_MIGRATIONS_HOME Migrations' directory (--migrations-home)
|
|
40
39
|
|
|
41
40
|
Examples
|
|
42
|
-
clickhouse-migrations migrate --host=http://localhost
|
|
43
|
-
--
|
|
44
|
-
--
|
|
41
|
+
clickhouse-migrations migrate --host=http://localhost:8123
|
|
42
|
+
--user=default --password='' --db=analytics
|
|
43
|
+
--migrations-home=/app/clickhouse/migrations
|
|
45
44
|
|
|
46
45
|
clickhouse-migrations migrate
|
package/lib/migrate.js
CHANGED
|
@@ -61,35 +61,23 @@ var log = function (type, message, error) {
|
|
|
61
61
|
console.error('\x1b[36m', "clickhouse-migrations :", '\x1b[31m', "Error: ".concat(message), error ? "\n\n ".concat(error) : '');
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
-
var connect = function (host,
|
|
64
|
+
var connect = function (host, username, password, db_name) {
|
|
65
65
|
var db_params = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
username: username,
|
|
71
|
-
password: password,
|
|
72
|
-
},
|
|
73
|
-
isUseGzip: false,
|
|
74
|
-
format: 'json',
|
|
75
|
-
raw: false,
|
|
76
|
-
config: {
|
|
77
|
-
session_timeout: 60,
|
|
78
|
-
output_format_json_quote_64bit_integers: 0,
|
|
79
|
-
enable_http_compression: 0,
|
|
80
|
-
},
|
|
66
|
+
host: host,
|
|
67
|
+
username: username,
|
|
68
|
+
password: password,
|
|
69
|
+
application: 'clickhouse-migrations',
|
|
81
70
|
};
|
|
82
71
|
if (db_name) {
|
|
83
72
|
db_params.database = db_name;
|
|
84
73
|
}
|
|
85
74
|
return new createClient(db_params);
|
|
86
75
|
};
|
|
87
|
-
var create_db = function (
|
|
88
|
-
var
|
|
76
|
+
var create_db = function (client, db_name) { return __awaiter(void 0, void 0, void 0, function () {
|
|
77
|
+
var q, e_1;
|
|
89
78
|
return __generator(this, function (_a) {
|
|
90
79
|
switch (_a.label) {
|
|
91
80
|
case 0:
|
|
92
|
-
client = connect(host, port, username, password);
|
|
93
81
|
q = "CREATE DATABASE IF NOT EXISTS ".concat(db_name, " ENGINE = Atomic");
|
|
94
82
|
_a.label = 1;
|
|
95
83
|
case 1:
|
|
@@ -105,10 +93,7 @@ var create_db = function (host, port, username, password, db_name) { return __aw
|
|
|
105
93
|
log('error', "can't create the database ".concat(db_name, "."), e_1.message);
|
|
106
94
|
process.exit(1);
|
|
107
95
|
return [3 /*break*/, 4];
|
|
108
|
-
case 4: return [
|
|
109
|
-
case 5:
|
|
110
|
-
_a.sent();
|
|
111
|
-
return [2 /*return*/];
|
|
96
|
+
case 4: return [2 /*return*/];
|
|
112
97
|
}
|
|
113
98
|
});
|
|
114
99
|
}); };
|
|
@@ -279,16 +264,16 @@ var apply_migrations = function (client, migrations, migrations_home) { return _
|
|
|
279
264
|
}
|
|
280
265
|
});
|
|
281
266
|
}); };
|
|
282
|
-
var migration = function (migrations_home, host,
|
|
267
|
+
var migration = function (migrations_home, host, username, password, db_name) { return __awaiter(void 0, void 0, void 0, function () {
|
|
283
268
|
var migrations, client;
|
|
284
269
|
return __generator(this, function (_a) {
|
|
285
270
|
switch (_a.label) {
|
|
286
271
|
case 0:
|
|
287
272
|
migrations = get_migrations(migrations_home);
|
|
288
|
-
|
|
273
|
+
client = connect(host, username, password, db_name);
|
|
274
|
+
return [4 /*yield*/, create_db(client, db_name)];
|
|
289
275
|
case 1:
|
|
290
276
|
_a.sent();
|
|
291
|
-
client = connect(host, port, username, password, db_name);
|
|
292
277
|
return [4 /*yield*/, init_migration_table(client)];
|
|
293
278
|
case 2:
|
|
294
279
|
_a.sent();
|
|
@@ -304,12 +289,11 @@ var migration = function (migrations_home, host, port, username, password, db_na
|
|
|
304
289
|
}); };
|
|
305
290
|
var migrate = function () {
|
|
306
291
|
var program = new Command();
|
|
307
|
-
program.name('clickhouse-migrations').description('ClickHouse migrations.').version('0.1.
|
|
292
|
+
program.name('clickhouse-migrations').description('ClickHouse migrations.').version('0.1.7');
|
|
308
293
|
program
|
|
309
294
|
.command('migrate')
|
|
310
295
|
.description('Apply migrations.')
|
|
311
|
-
.requiredOption('--host <name>', 'Clickhouse hostname (ex
|
|
312
|
-
.requiredOption('--port <number>', 'Port', process.env.CH_MIGRATIONS_PORT)
|
|
296
|
+
.requiredOption('--host <name>', 'Clickhouse hostname (ex: http://clickhouse:8123)', process.env.CH_MIGRATIONS_HOST)
|
|
313
297
|
.requiredOption('--user <name>', 'Username', process.env.CH_MIGRATIONS_USER)
|
|
314
298
|
.requiredOption('--password <password>', 'Password', process.env.CH_MIGRATIONS_PASSWORD)
|
|
315
299
|
.requiredOption('--db <name>', 'Database name', process.env.CH_MIGRATIONS_DB)
|
|
@@ -317,7 +301,7 @@ var migrate = function () {
|
|
|
317
301
|
.action(function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
318
302
|
return __generator(this, function (_a) {
|
|
319
303
|
switch (_a.label) {
|
|
320
|
-
case 0: return [4 /*yield*/, migration(options.migrationsHome, options.host, options.
|
|
304
|
+
case 0: return [4 /*yield*/, migration(options.migrationsHome, options.host, options.user, options.password, options.db)];
|
|
321
305
|
case 1:
|
|
322
306
|
_a.sent();
|
|
323
307
|
return [2 /*return*/];
|