doix-db 1.0.6 → 1.0.8

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.
@@ -7,12 +7,14 @@ const OBJECT_ACTIONS = [
7
7
  'alter',
8
8
  'migrate',
9
9
  'recreate',
10
+ 'comment',
10
11
  ]
11
12
 
12
13
  const COLUMN_ACTIONS = [
13
14
  'add-column',
14
15
  'alter-column',
15
16
  'migrate-column',
17
+ 'comment-column',
16
18
  ]
17
19
 
18
20
  const add = (toDo, action, object) => {
@@ -40,24 +42,22 @@ class DbMigrationPlan extends EventEmitter {
40
42
 
41
43
  this.toDo = new Map
42
44
 
43
- for (const action of OBJECT_ACTIONS)
44
-
45
- this.on (action, object => add (
46
- this.toDo,
47
- action, object))
45
+ for (const action of OBJECT_ACTIONS) this.on (action, object => add (
46
+ this.toDo,
47
+ action, object)
48
+ )
48
49
 
49
- for (const action of COLUMN_ACTIONS)
50
-
51
- this.on (action, column => add (
52
- this.asIs.get (column.relation.name).toDo,
53
- action, column))
50
+ for (const action of COLUMN_ACTIONS) this.on (action, column => add (
51
+ this.asIs.get (column.relation.name).toDo,
52
+ action, column)
53
+ )
54
54
 
55
55
  }
56
56
 
57
57
  compareRelation (asIs, toBe) {
58
58
 
59
59
  const {lang} = this, {columns} = toBe, existingColumns = asIs.columns
60
-
60
+
61
61
  for (const [name, column] of Object.entries (columns)) {
62
62
 
63
63
  if (name in existingColumns) {
@@ -68,12 +68,20 @@ class DbMigrationPlan extends EventEmitter {
68
68
 
69
69
  const action = lang.getRequiredColumnMutation (existingColumn, column)
70
70
 
71
- if (action !== null) this.emit (action, column)
71
+ if (action === null) continue
72
+
73
+ this.emit (action, column)
74
+
75
+ if (action === 'alter-column' && existingColumn.comment == column.comment) continue
76
+
77
+ this.emit ('comment-column', column)
72
78
 
73
79
  }
74
80
  else {
75
81
 
76
82
  this.emit ('add-column', column)
83
+
84
+ this.emit ('comment-column', column)
77
85
 
78
86
  }
79
87
 
@@ -83,6 +91,8 @@ class DbMigrationPlan extends EventEmitter {
83
91
 
84
92
  compareObject (asIs, toBe) {
85
93
 
94
+ if (asIs.comment != toBe.comment) this.emit ('comment', toBe)
95
+
86
96
  if (asIs.constructor === toBe.constructor && toBe instanceof DbRelation)
87
97
 
88
98
  this.compareRelation (asIs, toBe)
@@ -108,6 +118,8 @@ class DbMigrationPlan extends EventEmitter {
108
118
  this.compareObject (asIs.get (name), object)
109
119
 
110
120
  if (action !== null) this.emit (action, object)
121
+
122
+ if (action === 'create') this.emit ('comment', object)
111
123
 
112
124
  }
113
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doix-db",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Shared database related code for doix",
5
5
  "main": "index.js",
6
6
  "files": [