postgres-migrations
postgres-migrations copied to clipboard
Search for the migrations table in the correct schema
Currently, when checking if the migrations
table has to be created, doesTableExist()
will succeed if there a table named migrations
can be found in any schema. This means that postgres-migrations
fails to start if there is another table called migrations
, even if it's in another schema!
In our case, this lead to an incompatibility with graphile-worker, which has its own migrations
table in its own schema.
The fix ensures that only the public
schema is considered when looking for the table.
See #33
I see, same problem, different solution. But that one requires tests and there doesn't seem to be progress since January, whereas this fix "just works". Doesn't it?
No. This approach was suggested in the thread I linked to, but was thought to be a breaking change:
However it could break things for users who have their migrations table in a schema other than public, which is already possible with the current version of postgres-migrations.
For example if you revoke access to public from your migration user:
REVOKE ALL ON SCHEMA public FROM username;
Then postgres-migrations would create the migrations table in the username schema, and this would work just fine.
To which I responded:
I guess if we add the schema as a user option, we'd have to default to omitting the schema and leaving it implicit.
^ This is what I will accept a PR for. With appropriate tests.
To make sure this keeps working for people, tests for the following would be good:
- using another schema for the migrations table
- backwards compatibility: revoke access to
public
, then run migrations
Sorry, I wasn't aware that it's possible to have the migrations table anywhere else but in the public
schema. Is this documented anywhere? Searching for "schema" in this repo reveals only rejected PRs and open issues...
I also didn't know that! This is why I linked to #33 - it's in there.
See here for some documentation: https://www.postgresql.org/docs/9.6/ddl-schemas.html#DDL-SCHEMAS-PATH