doix-db 1.0.69 → 1.0.71
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 -1
- package/lib/DbLang.js +3 -1
- package/lib/migration/DbMigrationPlan.js +32 -2
- package/lib/model/DbRelation.js +14 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,4 +9,8 @@
|
|
|
9
9
|
* [DbMigrationPlan](https://github.com/do-/node-doix-db/wiki/DbMigrationPlan) — a `DbModel` based deployment automation tool;
|
|
10
10
|
* [DbLang](https://github.com/do-/node-doix-db/wiki/DbLang) — a set of SQL generating functions for miscellaneous application tasks.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Has backends for
|
|
13
|
+
* [PostgreSQL](https://github.com/do-/node-doix-db-postgresql),
|
|
14
|
+
* [ClickHouse](https://github.com/do-/node-doix-db-clickhouse).
|
|
15
|
+
|
|
16
|
+
More information is available at https://github.com/do-/node-doix-db/wiki
|
package/lib/DbLang.js
CHANGED
|
@@ -456,7 +456,9 @@ class DbLang {
|
|
|
456
456
|
|
|
457
457
|
genColumnDefault (column) {
|
|
458
458
|
|
|
459
|
-
const def = column.default;
|
|
459
|
+
const def = column.default;
|
|
460
|
+
|
|
461
|
+
if (def === 'NULL' || def.indexOf ('(') !== -1) return def
|
|
460
462
|
|
|
461
463
|
return this.quoteLiteral (def)
|
|
462
464
|
|
|
@@ -56,11 +56,41 @@ class DbMigrationPlan extends EventEmitter {
|
|
|
56
56
|
action, column)
|
|
57
57
|
)
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
{
|
|
60
|
+
|
|
61
|
+
const action = 'drop-column'
|
|
62
|
+
|
|
63
|
+
this.on (action, (relation, column) => add (
|
|
64
|
+
this.asIs.get (relation.name).toDo,
|
|
65
|
+
action, column)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
60
71
|
|
|
61
72
|
compareRelation (asIs, toBe) {
|
|
62
73
|
|
|
63
|
-
const {lang} = this, {columns} = toBe, existingColumns = asIs.columns
|
|
74
|
+
const {lang} = this, {columns, columnsToDrop} = toBe, existingColumns = asIs.columns
|
|
75
|
+
|
|
76
|
+
for (const name of columnsToDrop) {
|
|
77
|
+
|
|
78
|
+
if (name in existingColumns) {
|
|
79
|
+
|
|
80
|
+
this.emit ('drop-column', asIs, name)
|
|
81
|
+
|
|
82
|
+
delete existingColumns [name]
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
|
|
87
|
+
this.emit ('no-column-to-drop', asIs, name)
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
64
94
|
|
|
65
95
|
for (const [name, column] of Object.entries (columns)) {
|
|
66
96
|
|
package/lib/model/DbRelation.js
CHANGED
|
@@ -14,17 +14,25 @@ class DbRelation extends DbObject {
|
|
|
14
14
|
|
|
15
15
|
const {columns} = this; if (typeof columns !== 'object') throw Error (`columns must be specified as an object`)
|
|
16
16
|
|
|
17
|
+
this.columnsToDrop = []
|
|
18
|
+
|
|
17
19
|
for (const [name, src] of Object.entries (columns)) {
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
if (src === null) this.columnsToDrop.push (name); else {
|
|
22
|
+
|
|
23
|
+
const column = new DbColumn (src)
|
|
24
|
+
|
|
25
|
+
column.name = name
|
|
26
|
+
column.relation = this
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
columns [name] = column
|
|
29
|
+
|
|
30
|
+
}
|
|
25
31
|
|
|
26
32
|
}
|
|
27
|
-
|
|
33
|
+
|
|
34
|
+
for (const name of this.columnsToDrop) delete columns [name]
|
|
35
|
+
|
|
28
36
|
if (this.pk == null) {
|
|
29
37
|
|
|
30
38
|
this.pk = []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doix-db",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.71",
|
|
4
4
|
"description": "Shared database related code for doix",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/do-/node-doix-db#readme",
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"doix": "^1.0.
|
|
43
|
+
"doix": "^1.0.51"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"jest": "^29.6.1"
|