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

Error running statements that can't be run as a multi-command string

Open stevehogdahl opened this issue 3 years ago • 2 comments

When updating an enum multiple values can't be added at the same time so it requires one update statement per value. Altering types in postgres can't be done a mutli-command string which is how the migrations are executed. This requires one migration file per alter statement which can inflate the number of migration files by quite a lot. We've already run into this issue with two different enum causing us to create 9 different migration files. Is it possible to add a feature to allow multiple single queries with a comment between each to break up the multi-command strings?

Example:

-- postgres-migrations disable-transaction
ALTER TYPE test_type ADD VALUE 'Manual';
ALTER TYPE test_type ADD VALUE 'Automatic';

Error: ALTER TYPE ... ADD cannot be executed from a function or multi-command string

stevehogdahl avatar Dec 17 '21 14:12 stevehogdahl

Interesting case! Thanks for the issue.

I must admit, my time for maintenance on this library is minimal, so it's unlikely I'll spend time implementing this.

That said, this is a case I would consider support for.

I'd happily discuss a proposal on how this would look, and if we can agree on a design I would accept a PR with:

  • implementation
  • tests
  • docs

As part of a proposal I would like to hear how other libraries in this space (including other languages) handle this problem. If this is a solved problem elsewhere I'd like to know about it first before committing to a design.

ThomWright avatar Dec 20 '21 12:12 ThomWright

Thanks for getting back to me so quickly. Sounds good, I'm more than happy to look into this and propose an implementation design.

stevehogdahl avatar Dec 20 '21 14:12 stevehogdahl