doix-db 1.0.68 → 1.0.70

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
@@ -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
- * More information is available at https://github.com/do-/node-doix-db/wiki
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
@@ -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
 
@@ -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
- const column = new DbColumn (src)
20
-
21
- column.name = name
22
- column.relation = this
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
- columns [name] = column
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 = []
@@ -30,17 +30,18 @@ class DbTable extends DbRelation {
30
30
 
31
31
  for (let i = 0; i < length; i ++) {
32
32
 
33
- const o = triggers [i]
33
+ const o = triggers [i]; if (o.sql !== null) {
34
34
 
35
- o.table = this
36
-
37
- if (!o.name) o.name = lang.getTriggerName (this, i)
38
-
39
- const trigger = new DbTrigger (o)
35
+ o.table = this
40
36
 
41
- trigger.setLang (lang)
37
+ if (!o.name) o.name = lang.getTriggerName (this, i)
38
+
39
+ const trigger = new DbTrigger (o)
40
+
41
+ trigger.setLang (lang)
42
42
 
43
- triggers [i] = trigger
43
+ triggers [i] = trigger
44
+ }
44
45
 
45
46
  }
46
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doix-db",
3
- "version": "1.0.68",
3
+ "version": "1.0.70",
4
4
  "description": "Shared database related code for doix",
5
5
  "main": "index.js",
6
6
  "files": [