Skip to content

Commit

Permalink
empty state initializer
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 26df095 commit d091931
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/commands/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function prepare (internals, config) {

internals.migrationsDir = migrator.directory;

await migrator.createMigrationsTable();
await migrator.createMigrationsTable({ emptyState: true });
log.verbose('migration table created');

return migrator;
Expand Down
6 changes: 3 additions & 3 deletions lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ module.exports = {
}
},

init: async function (driver, internals) {
init: async function (driver, internals, { emptyState }) {
await driver._createKV(internals.migrationState);
const schema = await driver._getKV(internals.migrationState, SSTATE);
const schema = emptyState ? await driver._getKV(internals.migrationState, SSTATE) : null;
if (schema) {
internals.schema = JSON.parse(schema.value);
} else {
} else if (!emptyState) {
await driver._insertKV(internals.migrationState, SSTATE, '{}');
}

Expand Down
8 changes: 4 additions & 4 deletions lib/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ const Walker = function (driver, directory, mode, intern, prefix) {
};

Walker.prototype = {
createTables: async function () {
await State.init(this._driver, this.internals);
createTables: async function (options) {
await State.init(this._driver, this.internals, options);
return this._driver._createList(this.internals.migrationTable);
},

createMigrationsTable: function () {
createMigrationsTable: function (options) {
if (
typeof this._driver._createList !== 'function' ||
typeof this._driver._getList !== 'function' ||
Expand All @@ -85,7 +85,7 @@ Walker.prototype = {
}
}

return this.createTables();
return this.createTables(options);
},

writeMigrationRecord: function (migration, callback) {
Expand Down

0 comments on commit d091931

Please sign in to comment.