db-migrate 1.0.0-beta.37 → 1.0.0-beta.38
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.
|
@@ -61,6 +61,21 @@ const recoveryMode = (file, interrupted) => {
|
|
|
61
61
|
* Revert the steps executed by an interrupted run. A step started but not
|
|
62
62
|
* done did not change the database, so its reverse operation is dropped.
|
|
63
63
|
*/
|
|
64
|
+
/**
|
|
65
|
+
* Keep the reverse operations of the steps executed on the database. The
|
|
66
|
+
* failed step only changed the database, if its main statement went through
|
|
67
|
+
* before failing, signaled by the driver (e.g. a foreign key of createTable
|
|
68
|
+
* failed after the table was created).
|
|
69
|
+
*/
|
|
70
|
+
const executedSteps = (internals, failed, signaled) => {
|
|
71
|
+
const done = internals.migrationDone;
|
|
72
|
+
|
|
73
|
+
internals.modSchema.s = internals.modSchema.s.filter(
|
|
74
|
+
entry =>
|
|
75
|
+
entry.n <= done || (signaled && failed > done && entry.n === failed)
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
64
79
|
const recoverByRollback = async (context, driver, file, interrupted) => {
|
|
65
80
|
const internals = context.internals;
|
|
66
81
|
const pdriver = context._pdriver;
|
|
@@ -129,6 +144,8 @@ const execUnit = {
|
|
|
129
144
|
}
|
|
130
145
|
}
|
|
131
146
|
|
|
147
|
+
context.internals.migrationDone = chain.recovery ? chain.recovery.done : 0;
|
|
148
|
+
|
|
132
149
|
// startMigration - needs secondary instance since we can not afford to
|
|
133
150
|
// loose state and the transaction start will include these for roll back
|
|
134
151
|
// we will disable them probably at all from DDL when the driver does not
|
|
@@ -140,10 +157,13 @@ const execUnit = {
|
|
|
140
157
|
dbm: context.internals.safeOptions.dbmigrate
|
|
141
158
|
});
|
|
142
159
|
} catch (err) {
|
|
143
|
-
context.internals.rollback = true;
|
|
144
|
-
|
|
145
160
|
// transfer last state
|
|
146
161
|
chain.transferInt();
|
|
162
|
+
executedSteps(
|
|
163
|
+
context.internals,
|
|
164
|
+
chain.op,
|
|
165
|
+
chain.udriver._counter.previousSignal() === true
|
|
166
|
+
);
|
|
147
167
|
|
|
148
168
|
log.error(
|
|
149
169
|
'An error occured. No alternative failure strategy defined. Rolling back!',
|
package/lib/learn.js
CHANGED
|
@@ -175,7 +175,8 @@ class STD {
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
// keep the columns removed before from the same table
|
|
179
|
+
if (!this.modS[t]) this.modS[t] = {};
|
|
179
180
|
|
|
180
181
|
if (columns[c].notNull === true && !this.unlearn) {
|
|
181
182
|
switch (o.columnStrategy) {
|
|
@@ -300,7 +301,7 @@ class STD {
|
|
|
300
301
|
|
|
301
302
|
alter.i[t] = {};
|
|
302
303
|
alter.i[t][i] = this.indizies[t][i];
|
|
303
|
-
this.modI[t] = {};
|
|
304
|
+
if (!this.modI[t]) this.modI[t] = {};
|
|
304
305
|
this.modI[t][i] = this.indizies[t][i];
|
|
305
306
|
delete this.indizies[t][i];
|
|
306
307
|
|
|
@@ -345,10 +346,12 @@ class STD {
|
|
|
345
346
|
|
|
346
347
|
alter.f[t] = {};
|
|
347
348
|
alter.f[t][k] = this.foreign[t][k];
|
|
348
|
-
this.modF[t] = {};
|
|
349
|
+
if (!this.modF[t]) this.modF[t] = {};
|
|
349
350
|
this.modF[t][k] = this.foreign[t][k];
|
|
350
351
|
delete this.foreign[t][k];
|
|
351
352
|
|
|
353
|
+
this.modC.push({ t: 1, a: 'addForeignKey', c: [t, k] });
|
|
354
|
+
|
|
352
355
|
return Promise.resolve(alter);
|
|
353
356
|
}
|
|
354
357
|
|
|
@@ -8,6 +8,8 @@ module.exports = {
|
|
|
8
8
|
getInterface: (context, file, driver, internals, pdriver) => {
|
|
9
9
|
const done = () =>
|
|
10
10
|
function () {
|
|
11
|
+
// in memory first, a failing write must not hide the executed step
|
|
12
|
+
internals.migrationDone = internals.migrationOp;
|
|
11
13
|
return State.done(pdriver, internals.migrationOp, internals);
|
|
12
14
|
};
|
|
13
15
|
|
|
@@ -46,6 +46,11 @@ const methods = {
|
|
|
46
46
|
return driver.changeColumn(t, c, internals.modSchema.c[t][c]);
|
|
47
47
|
},
|
|
48
48
|
|
|
49
|
+
addForeignKey: async (driver, [t, k], internals) => {
|
|
50
|
+
const foreign = internals.modSchema.f[t][k];
|
|
51
|
+
return driver.addForeignKey(t, foreign.rt, k, foreign.m, foreign.r);
|
|
52
|
+
},
|
|
53
|
+
|
|
49
54
|
addIndex: async (driver, [t, i], internals) => {
|
|
50
55
|
if (!internals.modSchema.i[t][i]) {
|
|
51
56
|
log.warn(
|