diff --git a/README.md b/README.md index bab8db09..f7d2e8e7 100644 --- a/README.md +++ b/README.md @@ -757,7 +757,7 @@ const umzug = new Umzug({ }) ``` -The create command includes some safety checks to make sure migrations aren't created with ambiguous ordering, and that they will be picked up by umzug when applying migrations. +The create command includes some safety checks to make sure migrations aren't created with ambiguous ordering, and that they will be picked up by umzug when applying migrations. The first pair is expected to be the "up" migration file, and to be picked up by the `pending` command. Use `node migrator create --help` for more options: diff --git a/src/umzug.ts b/src/umzug.ts index c5f35fb9..90e0b496 100644 --- a/src/umzug.ts +++ b/src/umzug.ts @@ -397,10 +397,12 @@ export class Umzug extends emittery p.path && path.resolve(p.path) === path.resolve(filepath))) { + if (!pending.some(p => p.path && path.resolve(p.path) === path.resolve(firstFilePath))) { + const paths = pending.map(p => p.path).join(', '); throw new Error( - `Expected ${filepath} to be a pending migration but it wasn't! You should investigate this. Use skipVerify to bypass this error.` + `Expected ${firstFilePath} to be a pending migration but it wasn't! Pending migration paths: ${paths}. You should investigate this. Use skipVerify to bypass this error.` ); } } diff --git a/test/cli.test.ts b/test/cli.test.ts index 353ee431..0f905e86 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -278,7 +278,7 @@ describe('create migration file', () => { ); await expect(runCLI(['create', '--name', 'm4.txt', '--allow-extension', '.txt'])).rejects.toThrowError( - /Expected .*2000.01.06T00.00.00.m4.txt to be a pending migration but it wasn't! You should investigate this./ + /Expected .*2000.01.06T00.00.00.m4.txt to be a pending migration but it wasn't! Pending migration paths: (.*). You should investigate this./ ); await expect(runCLI(['create', '--name', 'm4.txt', '--allow-extension', '.txt', '--skip-verify'])).resolves diff --git a/test/umzug.test.ts b/test/umzug.test.ts index fa8b8980..8df46430 100644 --- a/test/umzug.test.ts +++ b/test/umzug.test.ts @@ -93,6 +93,27 @@ describe('custom context', () => { expect(spy).toHaveBeenCalledTimes(1); }); + test(`create with custom template extension doesn't cause bogus warning`, async () => { + const syncer = fsSyncer(path.join(__dirname, 'generated/create-custom-template'), {}); + syncer.sync(); + + const umzug = new Umzug({ + migrations: { + glob: ['*.js', { cwd: syncer.baseDir }], + }, + logger: undefined, + create: { + folder: syncer.baseDir, + template: filepath => [[`${filepath}.x.js`, `/* custom template */`]], + }, + }); + + await umzug.create({ name: 'test' }); + const pending = names(await umzug.pending()); + expect(pending).toHaveLength(1); + expect(pending[0]).toContain('test.x.js'); + }); + describe(`resolve asynchronous context getter before the migrations run`, () => { const sleep = async (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); const getContext = async () => {