Skip to content

Commit 6acaf40

Browse files
committed
all state actions on secondary db line
Signed-off-by: Tobias Gurtzick <[email protected]>
1 parent 5bafb17 commit 6acaf40

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

lib/chain.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ const dbmControl = {
5555
};
5656

5757
class Chain {
58-
constructor (context, file, driver, internals) {
58+
constructor (context, file, driver, internals, pdriver) {
5959
this.file = file;
6060
this.context = context;
6161
this.driver = context;
62+
this.pdriver = pdriver;
6263
this.udriver = driver;
6364
if (this.udriver._dbmControl !== true) {
6465
this.udriver._counter = dbmControl;
@@ -113,7 +114,8 @@ class Chain {
113114
this.context,
114115
this.file,
115116
this.udriver,
116-
this.internals
117+
this.internals,
118+
this.pdriver
117119
);
118120
}
119121

@@ -136,6 +138,7 @@ class Chain {
136138
this._step.useState(ret);
137139
}
138140

141+
// need to check if we still want this
139142
if (this._step.hasModification) {
140143
const ret = this._step.modify(
141144
this.context,

lib/executors/versioned/v2.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ const execUnit = {
2929

3030
up: async function (context, driver, file) {
3131
const _file = file.get();
32-
const chain = new Chain(context._driver, file, driver, context.internals);
32+
const chain = new Chain(context._driver, file, driver, context.internals, context._pdriver);
3333
if (!_file._meta.noDefaultColumn) {
3434
chain.addChain(AddConventions);
3535
}
3636
chain.addChain(Learn);
3737
chain.addChain(StateTravel);
3838
chain.addChain(Migrate);
3939

40-
await State.startMigration(context._driver, file, context.internals);
40+
await State.startMigration(context._pdriver, file, context.internals);
4141
// startMigration - needs secondary instance since we can not afford to
4242
// loose state and the transaction start will include these for roll back
4343
// we will disable them probably at all from DDL when the driver does not
@@ -62,20 +62,20 @@ const execUnit = {
6262
throw err;
6363
}
6464
await Promise.promisify(context.writeMigrationRecord.bind(context))(file);
65-
return State.endMigration(context._driver, file, context.internals);
65+
return State.endMigration(context._pdriver, file, context.internals);
6666
// end migration, same as start migration
6767
},
6868

6969
fix: async function (context, driver, file) {
7070
const _file = file.get();
71-
const chain = new Chain(context._driver, file, driver, context.internals);
71+
const chain = new Chain(context._driver, file, driver, context.internals, context._pdriver);
7272
if (!_file._meta.noDefaultColumn) {
7373
chain.addChain(AddConventions);
7474
}
7575
chain.addChain(Learn);
7676
chain.addChain(StateTravel);
7777

78-
await State.startMigration(context._driver, file, context.internals);
78+
await State.startMigration(context._pdriver, file, context.internals);
7979
// startMigration - needs secondary instance since we can not afford to
8080
// loose state and the transaction start will include these for roll back
8181
// we will disable them probably at all from DDL when the driver does not
@@ -99,16 +99,16 @@ const execUnit = {
9999
await execUnit.down(context, driver, file);
100100
throw err;
101101
}
102-
await State.endMigration(context._driver, file, context.internals);
102+
await State.endMigration(context._pdriver, file, context.internals);
103103
log.verbose(`[fix] current schema`, util.inspect(context.internals.schema, false, null, true));
104104
// end migration, same as start migration
105105
},
106106

107107
down: async function (context, driver, file) {
108108
// start migration, see up comments
109-
await State.startMigration(context._driver, file, context.internals);
110-
await TranslateState(context._driver, file, driver, context.internals);
111-
await State.endMigration(context._driver, file, context.internals);
109+
await State.startMigration(context._pdriver, file, context.internals);
110+
await TranslateState(context._driver, file, driver, context.internals, context._pdriver);
111+
await State.endMigration(context._pdriver, file, context.internals);
112112
return Promise.promisify(context.deleteMigrationRecord.bind(context))(file);
113113
// end migration, see up comments
114114
}

lib/methods/v2/statetravel.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ const DEFAULT = {
1818
};
1919

2020
class StateTravel {
21-
constructor (internals, file, driver) {
21+
constructor (internals, file, driver, pdriver) {
2222
this.file = file;
2323
this.internals = internals;
2424
this.driver = driver;
25+
this.pdriver = pdriver;
2526
this._counter = 0;
2627
this._default = async function _default () {
27-
await State.step(this.driver, ++this._counter, this.internals);
28+
await State.step(this.pdriver, ++this._counter, this.internals);
2829

2930
return State.update(
30-
this.driver,
31+
this.pdriver,
3132
this.file,
3233
this.internals.modSchema,
3334
this.internals
@@ -49,9 +50,9 @@ const noTravelError = prop => {
4950
};
5051

5152
module.exports = {
52-
getInterface: (context, file, driver, internals) => {
53+
getInterface: (context, file, driver, internals, pdriver) => {
5354
if (context.learnable) {
54-
const st = new StateTravel(internals, file, context);
55+
const st = new StateTravel(internals, file, context, pdriver);
5556
return Shadow.overshadow(
5657
driver,
5758
Object.assign(st, context.statechanger),

lib/methods/v2/translatestate.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async function processEntry (
7272
file,
7373
driver,
7474
internals,
75+
pdriver,
7576
{ t: type, a: action, c: args }
7677
) {
7778
let skip = false;
@@ -101,20 +102,20 @@ async function processEntry (
101102
}
102103

103104
internals.modSchema.s.shift();
104-
await State.update(context, file, internals.modSchema, internals);
105+
await State.update(pdriver, file, internals.modSchema, internals);
105106
}
106107

107-
module.exports = async (context, file, driver, internals) => {
108+
module.exports = async (context, file, driver, internals, pdriver) => {
108109
const mod = internals.modSchema;
109110

110-
const chain = new Chain(context, file, driver, internals);
111+
const chain = new Chain(context, file, driver, internals, pdriver);
111112
internals.unlearn = true;
112113

113114
chain.addChain(Learn);
114115
chain.addChain(Migrate);
115116
await Promise.resolve(mod.s.reverse()).each(args =>
116-
processEntry(context, file, chain, internals, args)
117+
processEntry(context, file, chain, internals, pdriver, args)
117118
);
118119

119-
await State.deleteState(context, file, internals);
120+
await State.deleteState(pdriver, file, internals);
120121
};

lib/walker.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const INTERFACES = {
2727
const Walker = function (driver, directory, mode, intern, prefix, opts = {}) {
2828
this.driver = dbmUtil.reduceToInterface(driver, INTERFACES[prefix]);
2929
this._driver = driver;
30+
this._pdriver = opts.db2;
3031
Promise.promisifyAll(this._driver);
32+
Promise.promisifyAll(this._pdriver);
3133
this.directory = directory;
3234
this.internals = intern;
3335
/**
@@ -60,7 +62,7 @@ const Walker = function (driver, directory, mode, intern, prefix, opts = {}) {
6062

6163
Walker.prototype = {
6264
createTables: async function (options) {
63-
await State.init(this._driver, this.internals, options);
65+
await State.init(this._pdriver, this.internals, options);
6466
return this._driver._createList(this.internals.migrationTable);
6567
},
6668

0 commit comments

Comments
 (0)