Skip to content

Conversation

@BClark88
Copy link
Contributor

@BClark88 BClark88 commented May 28, 2024

Context

#create_enum allows for if_not_exists and force options
If no down migration is specifically created this will then cause an error on rollback
I was able to replicate this in a basic rails app with the following migration:

class EnumTest < ActiveRecord::Migration[7.1]
  def change
    create_enum :my_enum, %w[foo bar baz], if_not_exists: true
  end
end
➜ enum-test git:(main) ✗ rails db:rollback --trace                                                                                                                                                                                                                                                          [24-05-28|13:05:55]
** Invoke db:rollback (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:rollback
== 20240528043812 EnumTest: reverting =========================================
bin/rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

wrong number of arguments (given 3, expected 2)
/Users/enumlover42/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-postgres_enum-2.0.1/lib/active_record/postgres_enum/command_recorder.rb:6:in `create_enum'
/Users/enumlover42/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-7.1.3.3/lib/active_record/migration/default_strategy.rb:10:in `method_missing'
/Users/enumlover42/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-7.1.3.3/lib/active_record/migration.rb:1047:in `block in method_missing'
/Users/enumlover42/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-7.1.3.3/lib/active_record/migration.rb:1017:in `block in say_with_time'
/Users/enumlover42/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/benchmark.rb:296:in `measure'

Related tickets

What's inside

Adds an optional unused arg to ActiveRecord::PostgresEnum::CommandRecorder. This allows rollbacks to be handled gracefully when options are passed in

Checklist:

  • I have added tests
  • I have made corresponding changes to the documentation

@bibendi
Copy link
Owner

bibendi commented May 28, 2024

Thank you!

@bibendi bibendi merged commit 0810a4b into bibendi:master May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants