usememos / memos

An open source, lightweight note-taking service. Easily capture and share your great thoughts.
https://usememos.com
MIT License
30.3k stars 2.27k forks source link

Postgresql docker compose data migration failure on fresh non-default database #3902

Closed agent019 closed 2 weeks ago

agent019 commented 2 weeks ago

Describe the bug

When running the application through docker compose, receive the following error when trying to run database migrations on fresh, non-default postgresql database.

Error:

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/cobra@v1.8.1/command.go:989\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/cobra@v1.8.1/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/cobra@v1.8.1/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/cobra@v1.8.1/command.go:989\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/cobra@v1.8.1/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/cobra@v1.8.1/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/cobra@v1.8.1/command.go:989\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/cobra@v1.8.1/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/cobra@v1.8.1/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/cobra@v1.8.1/command.go:989\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/cobra@v1.8.1/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/cobra@v1.8.1/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"

Migrations seem to run up until v0.20 until they fail trying, it seems, to parse the 00_reaction.sql filename.

Relevant docker compose:

memos:
    image: neosmemo/memos:stable
    container_name: memos
    volumes:
      - memos-data:/var/opt/memos
    environment:
      - MEMOS_DRIVER=postgres
      - MEMOS_DSN=user=memos password=<redacted> dbname=memos host=postgres port=5432 sslmode=disable
    ports:
      - 5230:5230
    depends_on:
      postgres:
        condition: service_healthy
  postgres:
    container_name: postgres
    image: postgres:latest
    restart: always
    shm_size: 128mb
    volumes:
      - pgdata:/var/lib/postgresql/data
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=<redacted>
      - POSTGRES_DB=postgres
    ports:
      - 5432:5432
    healthcheck:
      test: ["CMD-SHELL", "pg_isready", "-d", "postgres", "-U", "postgres"]
      interval: 30s
      timeout: 20s
      retries: 3

Steps to reproduce

  1. Create default postgresql database in docker compose with provided example sql
  2. Connect to created postgres instance and create new user "memos" and database "memos"
  3. Spin up memos instance, check logs and see migrations failure at "00_reaction.sql"

The version of Memos you're using.

v0.22.4

Screenshots or additional context

OS: Ubuntu 24.04 LTS Docker: docker compose v2.29.1 memos_db_failed_migrations

RoccoSmit commented 2 weeks ago

Duplicate of https://github.com/usememos/memos/issues/3885 See the following pr for more info https://github.com/usememos/memos/pull/3873