Skip to content

Commit 207dc5b

Browse files
committed
additional state travel but without stepping
Signed-off-by: Tobias Gurtzick <[email protected]>
1 parent d0d7080 commit 207dc5b

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

lib/executors/versioned/v2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const State = require('../../state');
55
const log = require('db-migrate-shared').log;
66
const Learn = require('../../learn');
77
const Chain = require('../../chain');
8-
const StateTravel = require('../../methods/v2/statetravel');
8+
const StateTravel = require('../../methods/v2/statetravel')();
9+
const StateNoStepTravel = require('../../methods/v2/statetravel')(false);
910
const Migrate = require('../../methods/v2/migrate');
1011
const TranslateState = require('../../methods/v2/translatestate');
1112
const AddConventions = require('../../methods/v2/conventions');
@@ -33,8 +34,9 @@ const execUnit = {
3334
if (!_file._meta.noDefaultColumn) {
3435
chain.addChain(AddConventions);
3536
}
36-
chain.addChain(Learn);
3737
chain.addChain(StateTravel);
38+
chain.addChain(Learn);
39+
chain.addChain(StateNoStepTravel);
3840
chain.addChain(Migrate);
3941

4042
await State.startMigration(context._pdriver, file, context.internals);

lib/methods/v2/statetravel.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ const DEFAULT = {
1818
};
1919

2020
class StateTravel {
21-
constructor (internals, file, driver, pdriver) {
21+
constructor (internals, file, driver, pdriver, stepOnly = true) {
2222
this.file = file;
2323
this.internals = internals;
2424
this.driver = driver;
2525
this.pdriver = pdriver;
2626
this._counter = 0;
2727
this._default = async function _default () {
28-
await State.step(this.pdriver, ++this._counter, this.internals);
28+
if (!stepOnly) {
29+
await State.step(this.pdriver, ++this._counter, this.internals);
30+
}
2931

3032
return State.update(
3133
this.pdriver,
@@ -49,24 +51,25 @@ const noTravelError = prop => {
4951
};
5052
};
5153

52-
module.exports = {
53-
getInterface: (context, file, driver, internals, pdriver) => {
54-
if (context.learnable) {
55-
const st = new StateTravel(internals, file, context, pdriver);
54+
module.exports = function (step = true) {
55+
return {
56+
getInterface: (context, file, driver, internals, pdriver) => {
57+
if (context.learnable) {
58+
const st = new StateTravel(internals, file, context, pdriver, step);
59+
return Shadow.overshadow(
60+
driver,
61+
Object.assign(st, context.statechanger),
62+
noTravelError
63+
);
64+
}
65+
5666
return Shadow.overshadow(
5767
driver,
58-
Object.assign(st, context.statechanger),
68+
new StateTravel(internals, file, context, pdriver, step),
5969
noTravelError
6070
);
6171
}
6272

63-
return Shadow.overshadow(
64-
driver,
65-
new StateTravel(internals, file, context, pdriver),
66-
noTravelError
67-
);
68-
}
69-
7073
/* hasModification: true,
7174
7275
modify: (context, driver, internals) => {
@@ -84,4 +87,5 @@ module.exports = {
8487
8588
return { driver: _driver };
8689
} */
90+
};
8791
};

0 commit comments

Comments
 (0)