clickhouse-migrations 0.1.10 → 0.1.12
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 +14 -10
- package/lib/migrate.js +1 -1
- package/lib/sql-parse.js +21 -4
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -11,11 +11,13 @@ npm install --global clickhouse-migrations
|
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
-
Create a directory, where migrations will be stored. It will be used as the value for the `--migrations-home` option.
|
|
14
|
+
Create a directory, where migrations will be stored. It will be used as the value for the `--migrations-home` option (or for environment variable `CH_MIGRATIONS_HOME`).
|
|
15
15
|
|
|
16
|
-
In the directory, create
|
|
16
|
+
In the directory, create migration files, which should be named like this: `1_some_text.sql`, `2_other_text.sql`, `10_more_test.sql`. What's important here is that the migration version number should come first, followed by an underscore (`_`), and then any text can follow. The version number should increase for every next migration. Please note that once a migration file has been applied to the database, it cannot be modified or removed.
|
|
17
17
|
|
|
18
|
-
For migrations' content should be used correct SQL ClickHouse queries.
|
|
18
|
+
For migrations' content should be used correct SQL ClickHouse queries. Multiple queries can be used in a single migration file, and each query should be terminated with a semicolon (;). The queries could be idempotent - for example: `CREATE TABLE IF NOT EXISTS table ...;` Clickhouse settings, that can be included at the query level, can be added like `SET allow_experimental_object_type = 1;`. For adding comments should be used `--`, `# `, `#!`.
|
|
19
|
+
|
|
20
|
+
If the database provided in the `--db` option (or in `CH_MIGRATIONS_DB`) doesn't exist, it will be created automatically.
|
|
19
21
|
|
|
20
22
|
```
|
|
21
23
|
Usage
|
|
@@ -43,13 +45,15 @@ For migrations' content should be used correct SQL ClickHouse queries. A few que
|
|
|
43
45
|
--migrations-home=/app/clickhouse/migrations
|
|
44
46
|
|
|
45
47
|
clickhouse-migrations migrate
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Migration file example:
|
|
51
|
+
```
|
|
52
|
+
-- an example of migration file 1_init.sql
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
SET allow_experimental_object_type = 1;
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
CREATE TABLE IF NOT EXISTS events (
|
|
57
|
+
event JSON
|
|
58
|
+
);
|
|
55
59
|
```
|
package/lib/migrate.js
CHANGED
|
@@ -300,7 +300,7 @@ var migration = function (migrations_home, host, username, password, db_name) {
|
|
|
300
300
|
exports.migration = migration;
|
|
301
301
|
var migrate = function () {
|
|
302
302
|
var program = new commander_1.Command();
|
|
303
|
-
program.name('clickhouse-migrations').description('ClickHouse migrations.').version('0.1.
|
|
303
|
+
program.name('clickhouse-migrations').description('ClickHouse migrations.').version('0.1.12');
|
|
304
304
|
program
|
|
305
305
|
.command('migrate')
|
|
306
306
|
.description('Apply migrations.')
|
package/lib/sql-parse.js
CHANGED
|
@@ -4,7 +4,8 @@ exports.sql_sets = exports.sql_queries = void 0;
|
|
|
4
4
|
// Extract sql queries from migrations.
|
|
5
5
|
var sql_queries = function (content) {
|
|
6
6
|
var queries = content
|
|
7
|
-
.replace(
|
|
7
|
+
.replace(/(--|#!|#\s).*(\n|\r\n|\r|$)/gm, '\n')
|
|
8
|
+
.replace(/^\s*(SET\s).*(\n|\r\n|\r|$)/gm, '')
|
|
8
9
|
.replace(/(\n|\r\n|\r)/gm, ' ')
|
|
9
10
|
.replace(/\s+/g, ' ')
|
|
10
11
|
.split(';')
|
|
@@ -17,15 +18,31 @@ exports.sql_queries = sql_queries;
|
|
|
17
18
|
var sql_sets = function (content) {
|
|
18
19
|
var sets = {};
|
|
19
20
|
var sets_arr = content
|
|
20
|
-
.replace(
|
|
21
|
-
.replace(
|
|
21
|
+
.replace(/(--|#!|#\s).*(\n|\r\n|\r|$)/gm, '\n')
|
|
22
|
+
.replace(/^\s*(?!SET\s).*(\n|\r\n|\r|$)/gm, '')
|
|
23
|
+
.replace(/^\s*(SET\s)/gm, '')
|
|
22
24
|
.replace(/(\n|\r\n|\r)/gm, ' ')
|
|
23
25
|
.replace(/\s+/g, '')
|
|
24
26
|
.split(';');
|
|
25
27
|
sets_arr.forEach(function (set_full) {
|
|
26
28
|
var set = set_full.split('=');
|
|
27
|
-
|
|
29
|
+
if (set[0]) {
|
|
30
|
+
sets[set[0]] = set[1];
|
|
31
|
+
}
|
|
28
32
|
});
|
|
29
33
|
return sets;
|
|
30
34
|
};
|
|
31
35
|
exports.sql_sets = sql_sets;
|
|
36
|
+
// -- any
|
|
37
|
+
// SET allow_experimental_object_type = 1; --set option
|
|
38
|
+
// SET allow_experimental_object_new = 1;
|
|
39
|
+
// SELECT * FROM events
|
|
40
|
+
// sdfsfdsd
|
|
41
|
+
// -- asssss
|
|
42
|
+
// --asdf
|
|
43
|
+
// sdfsdf
|
|
44
|
+
// sdfsfs
|
|
45
|
+
// SET a=1
|
|
46
|
+
// asdf
|
|
47
|
+
// SET f=22
|
|
48
|
+
// sdf
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clickhouse-migrations",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "ClickHouse Migrations",
|
|
5
5
|
"bin": {
|
|
6
6
|
"clickhouse-migrations": "lib/cli.js"
|
|
@@ -20,19 +20,19 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"repository": "VVVi/clickhouse-migrations",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@clickhouse/client": "^0.0.
|
|
23
|
+
"@clickhouse/client": "^0.0.14",
|
|
24
24
|
"commander": "^10.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/jest": "^29.
|
|
28
|
-
"@types/node": "^18.15.
|
|
29
|
-
"@typescript-eslint/parser": "^5.
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
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
31
|
"eslint-plugin-prettier": "^4.2.1",
|
|
32
|
-
"eslint": "^8.
|
|
33
|
-
"eslint-config-prettier": "^8.
|
|
32
|
+
"eslint": "^8.37.0",
|
|
33
|
+
"eslint-config-prettier": "^8.8.0",
|
|
34
34
|
"jest": "^29.5.0",
|
|
35
|
-
"prettier": "^2.8.
|
|
35
|
+
"prettier": "^2.8.7",
|
|
36
36
|
"ts-jest": "^29.0.5",
|
|
37
37
|
"typescript": "^4.9.5"
|
|
38
38
|
},
|