Skip to content

Commit

Permalink
fix(learn): non notNull columns can be safely deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Gurtzick <magic@wizardtales.com>
  • Loading branch information
wzrdtales committed Jun 15, 2019
1 parent 6c7df83 commit b75403d
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions lib/learn.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class STD {
return this.createTable.apply(this, args);
}

removeColumn (t, c, o) {
removeColumn (t, c, o = {}) {
let alter = {};
this.checkColumn(t, c);

Expand Down Expand Up @@ -134,9 +134,7 @@ class STD {
);
}
throw new Error(
`There is no such column recreation strategy "${
o.columnStrategy
}!"`
`There is no such column recreation strategy "${o.columnStrategy}!"`
);
}
} else {
Expand All @@ -158,27 +156,33 @@ class STD {

this.modS[t] = {};

switch (o.columnStrategies) {
case 'delay':
this.modS[t][c] = this.schema[t][c];

o.passthrough = o.passthrough || {};
o.passthrough.column =
o.passthrough.column || `__dbmrn_${c}_${new Date().toString()}__`;

this.modC.push({
t: 1,
a: 'renameColumn',
c: [t, o.passthrough.column, c]
});

break;
case 'defaultValue':
this.modS[t][c] = this.schema[t][c];
this.modS[t][c].defaultValue = o.passthrough.defaultValue;
if (this.schema[t][c].notNull === true) {
switch (o.columnStrategies) {
case 'delay':
this.modS[t][c] = this.schema[t][c];

o.passthrough = o.passthrough || {};
o.passthrough.column =
o.passthrough.column || `__dbmrn_${c}_${new Date().toString()}__`;

this.modC.push({
t: 1,
a: 'renameColumn',
c: [t, o.passthrough.column, c]
});

break;
case 'defaultValue':
this.modS[t][c] = this.schema[t][c];
this.modS[t][c].defaultValue = o.passthrough.defaultValue;

this.modC.push({ t: 1, a: 'addColumn', c: [t, c, o] });
break;
}
} else {
this.modS[t][c] = this.schema[t][c];

this.modC.push({ t: 1, a: 'addColumn', c: [t, c, o] });
break;
this.modC.push({ t: 1, a: 'addColumn', c: [t, c, o] });
}

delete this.schema[t][c];
Expand Down

0 comments on commit b75403d

Please sign in to comment.