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

fix: v0.22.5: start fail caused by incorrect migration file naming #3873

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

leo9800
Copy link
Contributor

@leo9800 leo9800 commented Sep 3, 2024

memos failed starting when using PostgreSQL as DB after upgrade to v0.22.5, which the following error message emitted: (docker installation, logs obtained by docker logs memos)

2024/09/03 15:18:39 ERROR failed to migrate error="strconv.Atoi: parsing \"00_reaction.sql\": invalid syntax\nfailed to convert patch version to int: 00_reaction.sql\ngithub.com/usememos/memos/store.(*Store).getSchemaVersionOfMigrateScript\n\tgithub.com/usememos/memos/store/migrator.go:233\ngithub.com/usememos/memos/store.(*Store).normalizedMigrationHistoryList\n\tgithub.com/usememos/memos/store/migrator.go:272\ngithub.com/usememos/memos/store.(*Store).preMigrate\n\tgithub.com/usememos/memos/store/migrator.go:151\ngithub.com/usememos/memos/store.(*Store).Migrate\n\tgithub.com/usememos/memos/store/migrator.go:37\nmain.init.func1\n\t./main.go:61\ngithub.com/spf13/cobra.(*Command).execute\n\tgithub.com/spf13/[email protected]/command.go:989\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/[email protected]/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/[email protected]/command.go:1041\nmain.main\n\t./main.go:171\nruntime.main\n\truntime/proc.go:271\nruntime.goexit\n\truntime/asm_amd64.s:1695\nfailed to get schema version of migrate script\ngithub.com/usememos/memos/store.(*Store).normalizedMigrationHistoryList\n\tgithub.com/usememos/memos/store/migrator.go:274\ngithub.com/usememos/memos/store.(*Store).preMigrate\n\tgithub.com/usememos/memos/store/migrator.go:151\ngithub.com/usememos/memos/store.(*Store).Migrate\n\tgithub.com/usememos/memos/store/migrator.go:37\nmain.init.func1\n\t./main.go:61\ngithub.com/spf13/cobra.(*Command).execute\n\tgithub.com/spf13/[email protected]/command.go:989\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/[email protected]/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/[email protected]/command.go:1041\nmain.main\n\t./main.go:171\nruntime.main\n\truntime/proc.go:271\nruntime.goexit\n\truntime/asm_amd64.s:1695\nfailed to normalize migration history list\ngithub.com/usememos/memos/store.(*Store).preMigrate\n\tgithub.com/usememos/memos/store/migrator.go:152\ngithub.com/usememos/memos/store.(*Store).Migrate\n\tgithub.com/usememos/memos/store/migrator.go:37\nmain.init.func1\n\t./main.go:61\ngithub.com/spf13/cobra.(*Command).execute\n\tgithub.com/spf13/[email protected]/command.go:989\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/[email protected]/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/[email protected]/command.go:1041\nmain.main\n\t./main.go:171\nruntime.main\n\truntime/proc.go:271\nruntime.goexit\n\truntime/asm_amd64.s:1695\nfailed to pre-migrate\ngithub.com/usememos/memos/store.(*Store).Migrate\n\tgithub.com/usememos/memos/store/migrator.go:38\nmain.init.func1\n\t./main.go:61\ngithub.com/spf13/cobra.(*Command).execute\n\tgithub.com/spf13/[email protected]/command.go:989\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/[email protected]/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/[email protected]/command.go:1041\nmain.main\n\t./main.go:171\nruntime.main\n\truntime/proc.go:271\nruntime.goexit\n\truntime/asm_amd64.s:1695"

Which gives error message as below, after unescaping \t and \n:

strconv.Atoi: parsing \"00_reaction.sql\": invalid syntax
failed to convert patch version to int: 00_reaction.sql
github.com/usememos/memos/store.(*Store).getSchemaVersionOfMigrateScript
	github.com/usememos/memos/store/migrator.go:233
github.com/usememos/memos/store.(*Store).normalizedMigrationHistoryList
	github.com/usememos/memos/store/migrator.go:272
github.com/usememos/memos/store.(*Store).preMigrate
	github.com/usememos/memos/store/migrator.go:151
github.com/usememos/memos/store.(*Store).Migrate
	github.com/usememos/memos/store/migrator.go:37
main.init.func1
	./main.go:61
github.com/spf13/cobra.(*Command).execute
	github.com/spf13/[email protected]/command.go:989
github.com/spf13/cobra.(*Command).ExecuteC
	github.com/spf13/[email protected]/command.go:1117
github.com/spf13/cobra.(*Command).Execute
	github.com/spf13/[email protected]/command.go:1041
main.main
	./main.go:171
runtime.main
	runtime/proc.go:271
runtime.goexit
	runtime/asm_amd64.s:1695
failed to get schema version of migrate script
github.com/usememos/memos/store.(*Store).normalizedMigrationHistoryList
	github.com/usememos/memos/store/migrator.go:274
github.com/usememos/memos/store.(*Store).preMigrate
	github.com/usememos/memos/store/migrator.go:151
github.com/usememos/memos/store.(*Store).Migrate
	github.com/usememos/memos/store/migrator.go:37
main.init.func1
	./main.go:61
github.com/spf13/cobra.(*Command).execute
	github.com/spf13/[email protected]/command.go:989
github.com/spf13/cobra.(*Command).ExecuteC
	github.com/spf13/[email protected]/command.go:1117
github.com/spf13/cobra.(*Command).Execute
	github.com/spf13/[email protected]/command.go:1041
main.main
	./main.go:171
runtime.main
	runtime/proc.go:271
runtime.goexit
	runtime/asm_amd64.s:1695
failed to normalize migration history list
github.com/usememos/memos/store.(*Store).preMigrate
	github.com/usememos/memos/store/migrator.go:152
github.com/usememos/memos/store.(*Store).Migrate
	github.com/usememos/memos/store/migrator.go:37
main.init.func1
	./main.go:61
github.com/spf13/cobra.(*Command).execute
	github.com/spf13/[email protected]/command.go:989
github.com/spf13/cobra.(*Command).ExecuteC
	github.com/spf13/[email protected]/command.go:1117
github.com/spf13/cobra.(*Command).Execute
	github.com/spf13/[email protected]/command.go:1041
main.main
	./main.go:171
runtime.main
	runtime/proc.go:271
runtime.goexit
	runtime/asm_amd64.s:1695
failed to pre-migrate
github.com/usememos/memos/store.(*Store).Migrate
	github.com/usememos/memos/store/migrator.go:38
main.init.func1
	./main.go:61
github.com/spf13/cobra.(*Command).execute
	github.com/spf13/[email protected]/command.go:989
github.com/spf13/cobra.(*Command).ExecuteC
	github.com/spf13/[email protected]/command.go:1117
github.com/spf13/cobra.(*Command).Execute
	github.com/spf13/[email protected]/command.go:1041
main.main
	./main.go:171
runtime.main
	runtime/proc.go:271
runtime.goexit
	runtime/asm_amd64.s:1695

This seems to be caused by the incorrect naming of store/migration/postgres/prod/0.20/00_reaction.sql, (only 1 underline between 00 and reaction) which should be 00__reaction.sql. (2 underlines)

We could confirm by reading the recent-changed store/migrator.go, the constant MigrateFileNameSplit is defined as __ and this constant is used when splitting the migrate files in function getSchemaVersionOfMigrateScript().

@leo9800 leo9800 requested a review from boojack as a code owner September 3, 2024 15:40
@leo9800
Copy link
Contributor Author

leo9800 commented Sep 3, 2024

This issue may only affect those who run memos with postgresql, since I did not found similar naming error in mysql or sqlite migration files.

@Morethanevil
Copy link

And I wondered why it crashed :D

Guess I need to wait until it is fixed

@boojack boojack merged commit 95939eb into usememos:main Sep 3, 2024
@gabe565
Copy link
Contributor

gabe565 commented Sep 3, 2024

I just tested using ghcr.io/usememos/memos:test@sha256:a6dc3674c1ef499dc0fa321f571299c76d0cf021a604e2e03cdb617fcb90cd80 and can confirm the issue is fixed. Thank you!

@leo9800 leo9800 deleted the fix-migrate-file-naming branch September 4, 2024 00:49
@Valen-C12
Copy link

When will it release, I use the neosmemo/memos:stable docker image and run into this issue yesterday. seems the issue still exist

@leo9800
Copy link
Contributor Author

leo9800 commented Sep 6, 2024

@Valen-C12

When will it release, I use the neosmemo/memos:stable docker image and run into this issue yesterday. seems the issue still exist

Try pull the docker image again. I personally use ghcr.io/usememos/memos (the default latest tag) in my production setup, the image has been rebuilt after this PR is merged.

Re-pulling and recreating the container would fix the issue.

@k3davis
Copy link

k3davis commented Sep 14, 2024

I had a new pull of the image but had to use latest, the fix doesn't seem to be in stable yet.

@dfface
Copy link

dfface commented Sep 16, 2024

Thanks, use latest solve this.
But, stable tag still has the problem. Which did't worth the stable name.

@mariushosting
Copy link

@boojack any news? @RoccoSmit

@Issues-translate-bot
Copy link

Issue is not in English. It has been translated automatically.


@boojack any news? @RoccoSmit

@leo9800
Copy link
Contributor Author

leo9800 commented Dec 16, 2024

@mariushosting This patch should have been included in the latest v0.23.0, according to the changelog.

@mariushosting
Copy link

@mariushosting This patch should have been included in the latest v0.23.0, according to the changelog.

Thank you Leo!

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

Successfully merging this pull request may close these issues.

9 participants