Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI create: "Expected to be a pending migration but it wasn't!" when using create.template name transformation #559

Closed
kf6kjg opened this issue Aug 5, 2022 · 5 comments · Fixed by #565
Labels

Comments

@kf6kjg
Copy link

kf6kjg commented Aug 5, 2022

Looks like Umzug isn't handling the renaming of the inbound filename terribly well. I could make the "error" go away by adding the flag it mentions, but that just masks the problem.

Environment

Umzug 3.1.1
SequelizeStorage
Node 16 & 18
TypeScript, CommonJS

Relevant code snippet

	return new Umzug<QueryInterface>({
		context: sequelize?.getQueryInterface(),
		create: {
			folder: migrationsDir,
			template: (filepath): [string, string][] => {
				return [
					[
						`${filepath.toLowerCase()}.m.ts`,
						`import { DataTypes, QueryInterface } from "sequelize";

Example execution

$ ts-node --files -- src/cli "create" "--name" "asdfQWER"

{
  event: 'created',
  path: 'REDACTED/src/migrations/2022.08.05t21.35.28.asdfqwer.m.ts'
}

Error: Expected REDACTED/src/migrations/2022.08.05T21.35.28.asdfQWER to be a pending migration but it wasn't! You should investigate this. Use --skip-verify to bypass this error.

The file gets created, so this is more of a warning than an actual error, but it does cause confusion for the team members.

@mmkal
Copy link
Contributor

mmkal commented Aug 12, 2022

This warning isn't so much about the file failing to be created, but about it not being picked up by your migrations.glob setting (or other migrations configuration). After the file is created (and the warning ignored), is it listed by ts-node --files -- src/cli pending?

@kf6kjg
Copy link
Author

kf6kjg commented Aug 12, 2022

It is.

$ npx ts-node --files -- src/cli "create" "--name" "asdfQWER"
{
  event: 'created',
  path: 'REDACTED/src/migrations/2022.08.12t19.04.33.asdfqwer.m.ts'
}

Error: Expected REDACTED/src/migrations/2022.08.12T19.04.33.asdfQWER to be a pending migration but it wasn't! You should investigate this. Use --skip-verify to bypass this error.
$ npx ts-node --files -- src/cli pending
2022.06.03T08.13.57.example.m
2022.08.12t19.04.33.asdfqwer.m

@github-actions
Copy link

Release v3.2.1 addresses this.

@mmkal
Copy link
Contributor

mmkal commented Aug 13, 2022

@kf6kjg fixed in the release above. Note that the code snippet you posted has a bug though and may still hit the warning - you are calling .toLowerCase() on the whole file path, which might have unexpected behaviour for some users who clone into a path with caps in it (e.g. /Users/bob/src/yourapp). You should probably make a change along these lines (using import * as path from 'path'):

			template: (filepath): [string, string][] => {
+				const parsed = path.parse(filepath);
				return [
					[
-						`${filepath.toLowerCase()}.m.ts`,
+						`${path.join(parsed.dir, parsed.base.toLowerCase())}.m.ts`,
						`import { DataTypes, QueryInterface } from "sequelize";

@kf6kjg
Copy link
Author

kf6kjg commented Aug 14, 2022

Oooh! Excellent catch and excellent that the error is fixed!

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants