clickhouse-migrations 0.1.4 → 0.1.6

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 (3) hide show
  1. package/README.md +8 -11
  2. package/lib/migrate.js +18 -30
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -22,27 +22,24 @@ 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, in
26
- format https://clichouse
27
- --port=<number> Port
25
+ --host=<name> Clickhouse hostname
26
+ (ex. https://clickhouse:8123)
28
27
  --user=<name> Username
29
28
  --password=<password> Password
30
29
  --db=<name> Database name
31
30
  --migrations-home=<dir> Migrations' directory
32
31
 
33
32
  Environment variables
34
- instead options can be used environment variables
33
+ Instead of options can be used environment variables.
35
34
  CH_MIGRATIONS_HOST Clickhouse hostname (--host)
36
- CH_MIGRATIONS_PORT Port (--port)
37
35
  CH_MIGRATIONS_USER Username (--user)
38
36
  CH_MIGRATIONS_PASSWORD Password (--password)
39
37
  CH_MIGRATIONS_DB Database name (--db)
40
- CH_MIGRATIONS_HOME Migrations' directory
41
- (--migrations-home)
38
+ CH_MIGRATIONS_HOME Migrations' directory (--migrations-home)
42
39
 
43
40
  Examples
44
- clickhouse-migrations migrate --host=http://localhost
45
- --port=8123 --user=default --password=''
46
- --db=analytics --migrations-home=/app/clickhouse/migrations
41
+ clickhouse-migrations migrate --host=http://localhost:8123
42
+ --user=default --password='' --db=analytics
43
+ --migrations-home=/app/clickhouse/migrations
47
44
 
48
- ```
45
+ clickhouse-migrations migrate
package/lib/migrate.js CHANGED
@@ -61,35 +61,24 @@ 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, port, username, password, db_name) {
64
+ var connect = function (host, username, password, db_name) {
65
65
  var db_params = {
66
- url: host,
67
- port: parseInt(port),
68
- debug: false,
69
- basicAuth: {
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 (host, port, username, password, db_name) { return __awaiter(void 0, void 0, void 0, function () {
76
+ var create_db = function (host, username, password, db_name) { return __awaiter(void 0, void 0, void 0, function () {
88
77
  var client, 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);
81
+ client = connect(host, username, password);
93
82
  q = "CREATE DATABASE IF NOT EXISTS ".concat(db_name, " ENGINE = Atomic");
94
83
  _a.label = 1;
95
84
  case 1:
@@ -279,16 +268,16 @@ var apply_migrations = function (client, migrations, migrations_home) { return _
279
268
  }
280
269
  });
281
270
  }); };
282
- var migration = function (migrations_home, host, port, username, password, db_name) { return __awaiter(void 0, void 0, void 0, function () {
271
+ var migration = function (migrations_home, host, username, password, db_name) { return __awaiter(void 0, void 0, void 0, function () {
283
272
  var migrations, client;
284
273
  return __generator(this, function (_a) {
285
274
  switch (_a.label) {
286
275
  case 0:
287
276
  migrations = get_migrations(migrations_home);
288
- return [4 /*yield*/, create_db(host, port, username, password, db_name)];
277
+ return [4 /*yield*/, create_db(host, username, password, db_name)];
289
278
  case 1:
290
279
  _a.sent();
291
- client = connect(host, port, username, password, db_name);
280
+ client = connect(host, username, password, db_name);
292
281
  return [4 /*yield*/, init_migration_table(client)];
293
282
  case 2:
294
283
  _a.sent();
@@ -304,20 +293,19 @@ var migration = function (migrations_home, host, port, username, password, db_na
304
293
  }); };
305
294
  var migrate = function () {
306
295
  var program = new Command();
307
- program.name('clickhouse-migrations').description('ClickHouse migrations.').version('0.1.4');
296
+ program.name('clickhouse-migrations').description('ClickHouse migrations.').version('0.1.6');
308
297
  program
309
298
  .command('migrate')
310
- .description('apply migrations.')
311
- .requiredOption('--host <name>', 'clickhouse hostname in format http://clickhouse', process.env.CH_MIGRATIONS_HOST)
312
- .requiredOption('--port <number>', 'port', process.env.CH_MIGRATIONS_PORT)
313
- .requiredOption('--user <name>', 'username', process.env.CH_MIGRATIONS_USER)
314
- .requiredOption('--password <password>', 'password', process.env.CH_MIGRATIONS_PASSWORD)
315
- .requiredOption('--db <name>', 'database name', process.env.CH_MIGRATIONS_DB)
316
- .requiredOption('--migrations-home <dir>', 'migrations directory', process.env.CH_MIGRATIONS_HOME)
299
+ .description('Apply migrations.')
300
+ .requiredOption('--host <name>', 'Clickhouse hostname (ex: http://clickhouse:8123)', process.env.CH_MIGRATIONS_HOST)
301
+ .requiredOption('--user <name>', 'Username', process.env.CH_MIGRATIONS_USER)
302
+ .requiredOption('--password <password>', 'Password', process.env.CH_MIGRATIONS_PASSWORD)
303
+ .requiredOption('--db <name>', 'Database name', process.env.CH_MIGRATIONS_DB)
304
+ .requiredOption('--migrations-home <dir>', "Migrations' directory", process.env.CH_MIGRATIONS_HOME)
317
305
  .action(function (options) { return __awaiter(void 0, void 0, void 0, function () {
318
306
  return __generator(this, function (_a) {
319
307
  switch (_a.label) {
320
- case 0: return [4 /*yield*/, migration(options.migrationsHome, options.host, options.port, options.user, options.password, options.db)];
308
+ case 0: return [4 /*yield*/, migration(options.migrationsHome, options.host, options.user, options.password, options.db)];
321
309
  case 1:
322
310
  _a.sent();
323
311
  return [2 /*return*/];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clickhouse-migrations",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "CLI NodeJS ClickHouse Migrations",
5
5
  "bin": {
6
6
  "clickhouse-migrations": "lib/cli.js"