Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Irreversible migration rollback prevents schema dump #98

Closed
ka8725 opened this issue Sep 6, 2024 · 1 comment · Fixed by #100
Closed

Irreversible migration rollback prevents schema dump #98

ka8725 opened this issue Sep 6, 2024 · 1 comment · Fixed by #100
Labels
bug Something isn't working

Comments

@ka8725
Copy link
Member

ka8725 commented Sep 6, 2024

The migration should show the message about irreversibility but should be passed by and allowed to proceed with the schema dump.

Decide what to do with a migration being failed due to:

  • irreversible migration;
  • any other error.

What can it do:

  1. skip and later just show info?
  2. prevent from moving forward?
  3. ask what to do from user?
  4. should it be configurable?

Current output and behavior:

StandardError: An error has occurred, this and all later migrations canceled:



This migration uses change_column, which is not automatically reversible.
To make the migration reversible you can either:
1. Define #up and #down methods in place of the #change method.
2. Use the #reversible method to define reversible behavior.


/Users/andrei/projects/test/tmp/migrated/20240902112130_change_commitments_fields_from_integer_to_float.rb:4:in `block in change'
/Users/andrei/projects/test/tmp/migrated/20240902112130_change_commitments_fields_from_integer_to_float.rb:3:in `change'

Caused by:
ActiveRecord::IrreversibleMigration:

This migration uses change_column, which is not automatically reversible.
To make the migration reversible you can either:
1. Define #up and #down methods in place of the #change method.
2. Use the #reversible method to define reversible behavior.


/Users/andrei/projects/test/tmp/migrated/20240902112130_change_commitments_fields_from_integer_to_float.rb:4:in `block in change'
/Users/andrei/projects/test/tmp/migrated/20240902112130_change_commitments_fields_from_integer_to_float.rb:3:in `change'
Tasks: TOP => db:schema:dump => db:rollback_branches
(See full trace by running task with --trace)
  • stops right away. And that's annoying.
@ka8725 ka8725 added the bug Something isn't working label Sep 6, 2024
@ka8725
Copy link
Member Author

ka8725 commented Sep 6, 2024

Trace from this method:

      def handle_migration_error(error, migration)
        raise unless error.message.include?("ActiveRecord::IrreversibleMigration")

        ActualDbSchema.failed << migration
      end
(byebug) Rails.version
"6.1.7.6"
(byebug) error.message
"An error has occurred, this and all later migrations canceled:\n\n\n\nThis migration uses change_column, which is not automatically reversible.\nTo make the migration reversible you can either:\n1. Define #up and #down methods in place of the #change method.\n2. Use the #reversible method to define reversible behavior.\n\n\n"
(byebug) error.cause
#<ActiveRecord::IrreversibleMigration:

This migration uses change_column, which is not automatically reversible.
To make the migration reversible you can either:
1. Define #up and #down methods in place of the #change method.
2. Use the #reversible method to define reversible behavior.

(byebug) error.class
StandardError
(byebug) error.cause.class
ActiveRecord::IrreversibleMigration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant