Skip to content

Commit

Permalink
need learning on reverse, but respect its unlearning
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Gurtzick <[email protected]>
  • Loading branch information
wzrdtales committed Sep 7, 2023
1 parent 2504712 commit 458c5e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/learn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Promise = require('bluebird');
const Shadow = require('./driver/shadow');

class STD {
constructor ({ schema, modSchema: mod }, driver) {
constructor ({ schema, modSchema: mod, unlearn }, driver) {
this.checkColumn = function (t, c) {
if (!this.schema[t]) {
throw new Error(`There is no ${t} table in schema!`);
Expand All @@ -12,6 +12,7 @@ class STD {
throw new Error(`There is no ${c} column in schema!`);
}
};
this.unlearn = unlearn;
this.validations = {};
this.driver = driver;
this.indizies = schema.i;
Expand All @@ -21,10 +22,14 @@ class STD {
schema.e = {};
}
this.extra = schema.e;
if (unlearn) {
this.modC = [];
} else {
this.modC = mod.s;
}
this.modS = mod.c;
this.modI = mod.i;
this.modF = mod.f;
this.modC = mod.s;
}

dropTable (t) {
Expand Down Expand Up @@ -124,7 +129,7 @@ class STD {
const hasColumns = this.schema[t].columns !== undefined;
const columns = hasColumns ? this.schema[t].columns : this.schema[t];

if (columns[c].notNull === true) {
if (columns[c].notNull === true && !this.unlearn) {
if (this.validations.columnStrategies !== true) {
if (
this.driver._meta &&
Expand Down Expand Up @@ -172,7 +177,7 @@ class STD {

this.modS[t] = {};

if (columns[c].notNull === true) {
if (columns[c].notNull === true && !this.unlearn) {
switch (o.columnStrategy) {
case 'delay':
this.modS[t][c] = columns[c];
Expand All @@ -196,7 +201,7 @@ class STD {
this.modC.push({ t: 1, a: 'addColumn', c: [t, c, o] });
break;
}
} else {
} else if (!this.unlearn) {
this.modS[t][c] = columns[c];

this.modC.push({ t: 1, a: 'addColumn', c: [t, c, o] });
Expand Down
5 changes: 4 additions & 1 deletion lib/methods/v2/translatestate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Promise = require('bluebird');
const State = require('../../state');
const Chain = require('../../chain');
const Migrate = require('./migrate');
const Learn = require('../../learn');
const log = require('db-migrate-shared').log;

const methods = {
Expand Down Expand Up @@ -107,7 +108,9 @@ module.exports = async (context, file, driver, internals) => {
const mod = internals.modSchema;

const chain = new Chain(context, file, driver, internals);
// chain.addChain(Learn);
internals.unlearn = true;

chain.addChain(Learn);
chain.addChain(Migrate);
await Promise.resolve(mod.s.reverse()).each(args =>
processEntry(context, file, chain, internals, args)
Expand Down

0 comments on commit 458c5e8

Please sign in to comment.