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

When using non-public schema for Postgres, "goose_db_version" table cannot be found #863

Closed
jamesleeht opened this issue Nov 28, 2024 · 3 comments

Comments

@jamesleeht
Copy link

jamesleeht commented Nov 28, 2024

The first migration works fine, as the search path set on my user will cause the goose_db_version table to be created in my custom schema.

However, when running the second migration, this will cause the goose_db_version to not be found.

ERROR: relation "goose_db_version" already exists (SQLSTATE 42P07)

Related issues:
#800

Related code:
https://github.com/pressly/goose/blob/master/migrate.go#L216
https://github.com/pressly/goose/blob/master/internal/dialect/dialectquery/postgres.go#L60-L66

According to the code above, it will automatically assign the public schema for the list migrations table. How do we configure goose to read the goose version table from another schema?

There is another issue listing a potential solution:
#205

However, setting the search path in the connection string does not seem to fix this issue.

@jamesleeht jamesleeht changed the title When using non-public schema for Postgres, migration table cannot be found When using non-public schema for Postgres, "goose_db_version" table cannot be found Nov 28, 2024
@mfridman
Copy link
Collaborator

The code you linked only applies to the goose provider, which is not yet hooked up to the CLI.

If you're only using the CLI, you could override the goose table to something like myschema.goose_db_version. E.g.,

goose -table="myschema.goose_db_version"

By default, goose assumes the public schema.

@jamesleeht
Copy link
Author

Ah that works! Thanks for the info @mfridman.

@mfridman
Copy link
Collaborator

We should probably update both the README and add a section to the docs to clarify. Thanks for flagging.

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

No branches or pull requests

2 participants