Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(migrator): store snapshot only after migration is generated (#5470)
### The problem When using custom migration fileName function which forces using name (throws) as in the example in documentaion https://mikro-orm.io/docs/migrations#using-custom-migration-names and having snapshots enabled, causes the update of snapshot. Second retry with using name is not generating migration, because the snapshot has already been updated and no changes are found. ```typescript migrations: { fileName: (timestamp: string, name?: string) => { // force user to provide the name, otherwise you would end up with `Migration20230421212713_undefined` if (!name) { throw new Error('Specify migration name via `mikro-orm migration:create --name=...`'); } return `Migration${timestamp}_${name}`; }, snapshot: true, }, ``` ### Description of the solution Delaying update of snapshot after migration file is actually generated. Thus, updating it only after successful call to `this.generator.generate` which, under the hood, calls custom `fileName` function which is throwing error.
- Loading branch information
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters