postgres-migrations icon indicating copy to clipboard operation
postgres-migrations copied to clipboard

Search for the migrations table in the correct schema

Open marton78 opened this issue 4 years ago • 5 comments

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.

marton78 avatar Apr 29 '20 07:04 marton78

See #33

ThomWright avatar Apr 29 '20 08:04 ThomWright

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?

marton78 avatar Apr 30 '20 09:04 marton78

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

ThomWright avatar May 01 '20 08:05 ThomWright

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...

marton78 avatar May 01 '20 19:05 marton78

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

ThomWright avatar May 04 '20 10:05 ThomWright