Skip to content

Commit

Permalink
#228 Fixed issue with migrations not working when having clean instal…
Browse files Browse the repository at this point in the history
…lation of dever
  • Loading branch information
czprz committed Jul 24, 2023
1 parent dfbcafb commit 7e1da1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
10 changes: 5 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class EntryPoint {
this.#argv = process.argv.slice(2);
}

start() {
async start() {
if (!Migrator.migrate()) {
return;
}

versionChecker.fetch();

if (this.#argv.length === 0 || constants.notAllowedKeywords.some(x => x === this.#argv[0])) {
this.#defaultYargs();
return;
Expand Down Expand Up @@ -59,6 +61,8 @@ class EntryPoint {
EntryPoint.#projectYargs(keyword, project);
})
.catch((_) => _);

versionChecker.inform();
}

#defaultYargs() {
Expand Down Expand Up @@ -111,8 +115,4 @@ class EntryPoint {
}
}

versionChecker.fetch();

new EntryPoint().start();

versionChecker.inform();
15 changes: 11 additions & 4 deletions bin/migrator/dot-dever.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import schemaValidator, {SchemaTypes} from "../common/validators/schema-validator.js";
import ConfigLoader from "../configuration/config-loader.js";

import {Config} from '../common/models/dot-dever/external.js';

import DotDeverAddMigrationVersion002 from "./migrations/dot-dever/dot-dever-add-migration-version.002.js";
import DotDeverCreateConfigFile001 from "./migrations/dot-dever/dot-dever-create-config-file.001.js";

export default new class {
migrate() {
let config = ConfigLoader.get();

/**
* Migrate
* @param config {Config}
* @param migrationVersion {number}
* @returns {boolean}
*/
migrate(config, migrationVersion) {
config = DotDeverCreateConfigFile001.migrate(config);
config = DotDeverAddMigrationVersion002.migrate(config);

Expand All @@ -16,8 +22,9 @@ export default new class {
return false;
}

config.migrationVersion = migrationVersion;
ConfigLoader.write(config);

return true;
}
}
}
9 changes: 2 additions & 7 deletions bin/migrator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ export default new class {
return true;
}

if (dotDever.migrate(config)) {
config.migrationVersion = this.#migrationVersion;
configLoader.write(config);

console.log(`Migration to version ${this.#migrationVersion} completed successfully`);

if (dotDever.migrate(config, this.#migrationVersion)) {
return true;
} else {
console.error(chalk.redBright('Migration of .dever failed validation.'));
Expand All @@ -27,4 +22,4 @@ export default new class {
return false;
}
}
}
}

0 comments on commit 7e1da1e

Please sign in to comment.