migrate icon indicating copy to clipboard operation
migrate copied to clipboard

Redshift: Add support for `x-migrations-table-quoted`

Open jfemino-2021 opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe. My company has a Redshift DB that is shared by a small number of services. I'd like to add support for migrations for my service (and still allow other services to each have their own separate schema_migrations). Unfortunately, the public schema is not available... and the Redshift connection does not currently allow one to specify another schema to use for the schema_migrations table.

In both of the following situations:

  • golang-migrate is used apply migrations to the Redshift DB
  • migrate CLI is used to perform any action (including version)

... Redshift tries to create tables in the public schema REGARDLESS of how the Redshift connection is configured. e.g.

  • migrate -path /blah -database "redshift://${USER}:${PASS}@${HOST}:${PORT}/${DB}?x-migrations-table=example.schema_migrations" version
    • This attempts to create the table public."example.schema_migrations" which is:
      • Not the intent
      • Still uses the public schema, which is forbidden by policy. does... so I'm unable to specify a schema other than public.
  • migrate -path /blah -database "redshift://${USER}:${PASS}@${HOST}:${PORT}/${DB}?x-migrations-table=\"example\".\"schema_migrations\"" version
    • This returns the error error: pq: zero-length delimited identifier at or near """" in line 0: CREATE TABLE ""example"."schema_migrations"" (version bigint not null primary key, dirty boolean not null)
    • The Redshift connector doesn't support the x-migrations-table-quoted query param, like PostgreSQL connector does.

Describe the solution you'd like Redshift connections would support x-migrations-table-quoted (like PostgreSQL) so that the target schema & table name can both be specified.

Describe alternatives you've considered

  • Moving to a different migration library
  • Writing my own migration utility, from scratch
  • Creating a fork of golang-migrate/migrate and modifying the Redshift code

Additional context The public schema in my company's Redshift DB is locked down for reasons I cannot get into... so I can't rely on simply using a different table name in the public schema, for each service. e.g. the following won't work for us:

public/
    |
    + service1_schema_migrations
    |
    + service2_schema_migrations

jfemino-2021 avatar Apr 21 '22 23:04 jfemino-2021