How to skip Phoenix's schema migrations table check on read-only connections

I’m trying to connect Ecto to a database (for local development) to which I have read-only access - I don’t want, nor can, issue any CREATE statements. The problem is that when I send the request to a controller, I get following error:

[error] #PID<0.631.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.630.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /...
** (exit) an exception was raised:
    ** (MyXQL.Error) (1142) CREATE command denied to user '...' for table 'schema_migrations'

    query: CREATE TABLE IF NOT EXISTS `schema_migrations` (`version` bigint, `inserted_at` datetime, PRIMARY KEY (`version`)) ENGINE = INNODB
        (ecto_sql 3.10.2) lib/ecto/adapters/sql.ex:1047: Ecto.Adapters.SQL.raise_sql_call_error/1
        (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
        (ecto_sql 3.10.2) lib/ecto/adapters/sql.ex:1154: Ecto.Adapters.SQL.execute_ddl/4
        (ecto_sql 3.10.2) lib/ecto/migrator.ex:756: Ecto.Migrator.verbose_schema_migration/3

The table does exist in fact but Phoenix doesn’t check beforehand, banking on IF NOT EXISTS to cover both cases.

I’ve tried setting read_only: true to my repo, but didn’t help.

Can I somehow work around this?

Thanks!

1 Like

This is caused by Phoenix.Ecto.CheckRepoStatus. You could remove that plug, but I’d also consider it a bug, that it doesn’t react to the read_only configuration accordingly.

4 Likes

Thanks for the response. I’ve submitted a bug report.

Could you post a link to the bug, please? I want to follow it and was unable to find it in the list of issues for ecto and efto_sql on GitHub.

Sure, here is the bug report: Phoenix.Endpoint.SyncCodeReloadPlug issues CREATE TABLE even though repo is read-only · Issue #5569 · phoenixframework/phoenix · GitHub

1 Like