-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 - Force MigrationsTable in 'public' schema #414
Conversation
I wonder what behavior is/should be when
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delayed response.
I think the best course of action is to manage your RDBMS outside of migrate
. e.g. don't use migrations to manage your root schema and single root/super user.
Based on the docs, the default postgres search_path
is "$user", public
. As mentioned by the docs, new tables should be created in the public
schema by default:
The first schema in the search path that exists is the default location for creating new objects. That is the reason that by default objects are created in the public schema.
Using the public
schema is not the right change since it'll break any users that set the search_path
. The postgres db driver is designed to work with search_path
.
Can you provide more detail as to what your migrations were doing? More insight as to why migrations failed to run a second time would be helpful.
In an empty (postgres) DB named CREATE SCHEMA IF NOT EXISTS app;
CREATE TABLE app.application (
id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
name VARCHAR NOT null,
-- etc
);
--etc On first run the On second run (nothing should migrate as they were just migrated successfully and I use exactly the same (bash) script to start the whole process), I run into errors:
I am not changing the |
Using the same schema name as your role/user may be causing the issue since the default My guess is that the 2nd (and subsequent) run use the |
Makes sense, but it breaks the migrate experience as a subsequent run should work and keep existing schema intact without any change. If you don't like this solution, would removing |
|
ok, I added an example to the postgres tutorial how to circumvent the issue. But this can only be done when using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I added an example to the postgres tutorial how to circumvent the issue. But this can only be done when using migrate in the application. When using the (pre-build) tool, it cannot be circumvented...
Thanks for updating the docs!
I believe you can set the search_path
as part of the DB connection string/URL/DSN.
Yes you are right, I found out a little later and updated the doc/PR |
I ran into troubles when I migrated a new schema in the database:
MigrationsTable
was stored inpublic
schema (in empty DB this was only available schema)MigrationsTable
was stored in created schema, as it was not available (obviously), the migrations were (tried to) run again, resulting in the dirty flag set in the 'new'MigrationsTable
I am not entirely sure how this happened, because the 'default schema' is not changed, so it should be/stay be public.
This PR forces the
MigrationsTable
in public schema.I chose this approach (and not using
SchemaName
) to be backwards compatible, if requested I can modify the PR to useSchemaName
instead of 'public' for theMigrationsTable
location.