Skip to content

Commit

Permalink
fix: store failing validation after schema change
Browse files Browse the repository at this point in the history
Defer validation until after migrations are applied so that the store can be updated to the current schema.

Migrate store before validating store
  • Loading branch information
dopry authored Jun 21, 2024
1 parent a3c288b commit c3c5889
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ export default class Conf<T extends Record<string, any> = Record<string, unknown

const fileStore = this.store;
const store = Object.assign(createPlainObject(), options.defaults, fileStore);

if (options.migrations) {
if (!options.projectVersion) {
throw new Error('Please specify the `projectVersion` option.');
}

this._migrate(options.migrations, options.projectVersion, options.beforeEachMigration);
}

this._validate(store);

try {
Expand All @@ -149,13 +158,7 @@ export default class Conf<T extends Record<string, any> = Record<string, unknown
this._watch();
}

Check failure on line 159 in source/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on ubuntu-latest

Block must not be padded by blank lines.

Check failure on line 159 in source/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Block must not be padded by blank lines.

if (options.migrations) {
if (!options.projectVersion) {
throw new Error('Please specify the `projectVersion` option.');
}

this._migrate(options.migrations, options.projectVersion, options.beforeEachMigration);
}

Check failure on line 161 in source/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on ubuntu-latest

Trailing spaces not allowed.

Check failure on line 161 in source/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on ubuntu-latest

More than 1 blank line not allowed.

Check failure on line 161 in source/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Trailing spaces not allowed.

Check failure on line 161 in source/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

More than 1 blank line not allowed.
}

/**
Expand Down

0 comments on commit c3c5889

Please sign in to comment.