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

Postgres driver not running migrations with the configured schema #353

Open
dhui opened this issue Mar 4, 2020 · 3 comments
Open

Postgres driver not running migrations with the configured schema #353

dhui opened this issue Mar 4, 2020 · 3 comments

Comments

@dhui
Copy link
Member

dhui commented Mar 4, 2020

Describe the Bug
It looks like the schema is only used for generating the advisory lock id and for dropping migrations.

Steps to Reproduce
See: #262 (comment)

Expected Behavior
Migrations should not need to run SET SCHEMA. Instead, the Postgres db driver should handle that for you

Migrate Version
v4.9.1

Loaded Source Drivers
N/A

Loaded Database Drivers
N/A

Go Version
1.14

Stacktrace
N/A

Additional context
N/A

Potential Solutions

  1. I think we can add a method (ensureUsingSchema()) to the postgres in a backwards compatible manner. Not sure if we should run ensureUsingSchema() before every migration since that may break existing migrations, we could run it when the connection opens. That way any exist SET SCHEMA call is honored and subsequent migrations would continue to use the set schema.

Testcases
Any fix should test the following cases:

Where schema specified: In config Not in config
In migration
Not in migration
@feketegy
Copy link

feketegy commented Mar 4, 2020

@dhui Bare in mind that SET SCHEMA in Postgres is fairly new, to cover older versions SET search_path TO my_schema;

@dhui
Copy link
Member Author

dhui commented Mar 4, 2020

Postgres 9.5 is the oldest supported version and it looks like it supports SET SCHEMA.

Another option would be to use SET search_path TO directly.

@feketegy
Copy link

feketegy commented Mar 4, 2020

SET SCHEMA my_schema is basically a shorthand for SET search_path TO my_schema. Postgres is doing that in the background.

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