clickhouse-migrations 0.1.13 → 0.2.2

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 CHANGED
@@ -31,6 +31,9 @@ If the database provided in the `--db` option (or in `CH_MIGRATIONS_DB`) doesn't
31
31
  --db=<name> Database name
32
32
  --migrations-home=<dir> Migrations' directory
33
33
 
34
+ Optional options
35
+ --timeout=<value> Client request timeout (milliseconds, default value 30000)
36
+
34
37
  Environment variables
35
38
  Instead of options can be used environment variables.
36
39
  CH_MIGRATIONS_HOST Clickhouse hostname (--host)
@@ -38,13 +41,16 @@ If the database provided in the `--db` option (or in `CH_MIGRATIONS_DB`) doesn't
38
41
  CH_MIGRATIONS_PASSWORD Password (--password)
39
42
  CH_MIGRATIONS_DB Database name (--db)
40
43
  CH_MIGRATIONS_HOME Migrations' directory (--migrations-home)
44
+ CH_MIGRATIONS_TIMEOUT Client request timeout (--timeout)
41
45
 
42
46
  CLI examples
43
47
  clickhouse-migrations migrate --host=http://localhost:8123
44
48
  --user=default --password='' --db=analytics
45
49
  --migrations-home=/app/clickhouse/migrations
46
50
 
47
- clickhouse-migrations migrate
51
+ clickhouse-migrations migrate
52
+
53
+ clickhouse-migrations migrate --timeout=60000
48
54
  ```
49
55
 
50
56
  Migration file example:
package/lib/migrate.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const migration: (migrations_home: string, host: string, username: string, password: string, db_name: string) => Promise<void>;
1
+ declare const migration: (migrations_home: string, host: string, username: string, password: string, db_name: string, timeout?: string) => Promise<void>;
2
2
  declare const migrate: () => void;
3
3
  export { migrate, migration };
package/lib/migrate.js CHANGED
@@ -54,9 +54,9 @@ var log = function (type, message, error) {
54
54
  console.error('\x1b[36m', "clickhouse-migrations :", '\x1b[31m', "Error: ".concat(message), error ? "\n\n ".concat(error) : '');
55
55
  }
56
56
  };
57
- var connect = function (host, username, password, db_name) {
57
+ var connect = function (url, username, password, db_name, timeout) {
58
58
  var db_params = {
59
- host: host,
59
+ url: url,
60
60
  username: username,
61
61
  password: password,
62
62
  application: 'clickhouse-migrations',
@@ -64,6 +64,9 @@ var connect = function (host, username, password, db_name) {
64
64
  if (db_name) {
65
65
  db_params.database = db_name;
66
66
  }
67
+ if (timeout) {
68
+ db_params.request_timeout = Number(timeout);
69
+ }
67
70
  return (0, client_1.createClient)(db_params);
68
71
  };
69
72
  var create_db = function (host, username, password, db_name) { return __awaiter(void 0, void 0, void 0, function () {
@@ -72,7 +75,7 @@ var create_db = function (host, username, password, db_name) { return __awaiter(
72
75
  switch (_a.label) {
73
76
  case 0:
74
77
  client = connect(host, username, password);
75
- q = "CREATE DATABASE IF NOT EXISTS ".concat(db_name, " ENGINE = Atomic");
78
+ q = "CREATE DATABASE IF NOT EXISTS \"".concat(db_name, "\" ENGINE = Atomic");
76
79
  _a.label = 1;
77
80
  case 1:
78
81
  _a.trys.push([1, 3, , 4]);
@@ -102,7 +105,7 @@ var init_migration_table = function (client) { return __awaiter(void 0, void 0,
102
105
  return __generator(this, function (_a) {
103
106
  switch (_a.label) {
104
107
  case 0:
105
- q = "CREATE TABLE IF NOT EXISTS _migrations (\n uid UUID DEFAULT generateUUIDv4(), \n version UInt32,\n checksum String, \n migration_name String, \n applied_at DateTime DEFAULT now()\n ) \n ENGINE = MergeTree \n ORDER BY tuple(applied_at)";
108
+ q = "CREATE TABLE IF NOT EXISTS _migrations (\n uid UUID DEFAULT generateUUIDv4(),\n version UInt32,\n checksum String,\n migration_name String,\n applied_at DateTime DEFAULT now()\n )\n ENGINE = MergeTree\n ORDER BY tuple(applied_at)";
106
109
  _a.label = 1;
107
110
  case 1:
108
111
  _a.trys.push([1, 3, , 4]);
@@ -274,7 +277,7 @@ var apply_migrations = function (client, migrations, migrations_home) { return _
274
277
  }
275
278
  });
276
279
  }); };
277
- var migration = function (migrations_home, host, username, password, db_name) { return __awaiter(void 0, void 0, void 0, function () {
280
+ var migration = function (migrations_home, host, username, password, db_name, timeout) { return __awaiter(void 0, void 0, void 0, function () {
278
281
  var migrations, client;
279
282
  return __generator(this, function (_a) {
280
283
  switch (_a.label) {
@@ -283,7 +286,7 @@ var migration = function (migrations_home, host, username, password, db_name) {
283
286
  return [4 /*yield*/, create_db(host, username, password, db_name)];
284
287
  case 1:
285
288
  _a.sent();
286
- client = connect(host, username, password, db_name);
289
+ client = connect(host, username, password, db_name, timeout);
287
290
  return [4 /*yield*/, init_migration_table(client)];
288
291
  case 2:
289
292
  _a.sent();
@@ -309,10 +312,11 @@ var migrate = function () {
309
312
  .requiredOption('--password <password>', 'Password', process.env.CH_MIGRATIONS_PASSWORD)
310
313
  .requiredOption('--db <name>', 'Database name', process.env.CH_MIGRATIONS_DB)
311
314
  .requiredOption('--migrations-home <dir>', "Migrations' directory", process.env.CH_MIGRATIONS_HOME)
315
+ .option('--timeout <value>', 'Client request timeout (milliseconds, default value 30000)', process.env.CH_MIGRATIONS_TIMEOUT)
312
316
  .action(function (options) { return __awaiter(void 0, void 0, void 0, function () {
313
317
  return __generator(this, function (_a) {
314
318
  switch (_a.label) {
315
- case 0: return [4 /*yield*/, migration(options.migrationsHome, options.host, options.user, options.password, options.db)];
319
+ case 0: return [4 /*yield*/, migration(options.migrationsHome, options.host, options.user, options.password, options.db, options.timeout)];
316
320
  case 1:
317
321
  _a.sent();
318
322
  return [2 /*return*/];
package/package.json CHANGED
@@ -1,10 +1,19 @@
1
1
  {
2
2
  "name": "clickhouse-migrations",
3
- "version": "0.1.13",
3
+ "version": "0.2.2",
4
4
  "description": "ClickHouse Migrations",
5
5
  "bin": {
6
6
  "clickhouse-migrations": "lib/cli.js"
7
7
  },
8
+ "main": "lib/migrate.js",
9
+ "types": "lib/migrate.d.ts",
10
+ "engines": {
11
+ "node": ">=16"
12
+ },
13
+ "private": false,
14
+ "license": "MIT",
15
+ "author": "VVVi",
16
+ "repository": "VVVi/clickhouse-migrations",
8
17
  "scripts": {
9
18
  "build": "rm lib/*; tsc",
10
19
  "test": "jest --config jestconfig.json",
@@ -16,25 +25,22 @@
16
25
  "version": "npm run format && git add -A src",
17
26
  "postversion": "git push && git push --tags"
18
27
  },
19
- "author": "",
20
- "license": "MIT",
21
- "repository": "VVVi/clickhouse-migrations",
22
28
  "dependencies": {
23
- "@clickhouse/client": "^0.0.14",
24
- "commander": "^10.0.0"
29
+ "@clickhouse/client": "^1.5.0",
30
+ "commander": "^12.1.0"
25
31
  },
26
32
  "devDependencies": {
27
- "@types/jest": "^29.5.0",
28
- "@types/node": "^18.15.11",
29
- "@typescript-eslint/parser": "^5.57.0",
30
- "@typescript-eslint/eslint-plugin": "^5.57.0",
31
- "eslint-plugin-prettier": "^4.2.1",
32
- "eslint": "^8.37.0",
33
- "eslint-config-prettier": "^8.8.0",
34
- "jest": "^29.5.0",
35
- "prettier": "^2.8.7",
36
- "ts-jest": "^29.0.5",
37
- "typescript": "^4.9.5"
33
+ "@types/jest": "^29.5.12",
34
+ "@types/node": "^22.5.4",
35
+ "@typescript-eslint/eslint-plugin": "^8.4.0",
36
+ "@typescript-eslint/parser": "^8.4.0",
37
+ "eslint": "^8.57.0",
38
+ "eslint-config-prettier": "^9.1.0",
39
+ "eslint-plugin-prettier": "^5.2.1",
40
+ "jest": "^29.7.0",
41
+ "prettier": "^3.3.3",
42
+ "ts-jest": "^29.2.5",
43
+ "typescript": "^5.5.4"
38
44
  },
39
45
  "files": [
40
46
  "lib/**/*"