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

safety_assured not ignoring custom checks when safe_by_default is true #236

Closed
nleoutsa opened this issue Aug 9, 2023 · 1 comment
Closed

Comments

@nleoutsa
Copy link

nleoutsa commented Aug 9, 2023

Using:

ruby 3.2.1
rails 7.0.5.1
strong_migrations 1.6.0

Expectation:

Hey @bheemreddy181, `safety_assured` skips all checks, including custom ones. It allows developers to run any migration code.

Originally posted by @ankane in #66 (comment)

Based on the documentation and the above comment, I expect safety_assured to skip all checks, regardless of the value of safe_by_default.

Actual behavior:

safety_assured is not ignoring custom checks when safe_by_default is true

Steps to reproduce

(For this example, my DB has a users table and a phone (string) column)

  • Set StrongMigrations.safe_by_default = true in the config file
  • Add a custom check in the config file (I've used the exact one from the documentation):
    StrongMigrations.add_check do |method, args|
      if method == :add_index && args[0].to_s == "users"
        stop! "No more indexes on the users table"
      end
    end
    
  • Add a migration that violates the custom check, but wrap it in safety_assured:
    class AddIndexOnPhoneToUsers < ActiveRecord::Migration[7.0]
      disable_ddl_transaction!
    
      def change
        safety_assured {
          add_index :users, :phone
        }
      end
    end
    
  • Run the migration and note that it aborts:
    Migrating to AddIndexOnPhoneToUsers (20230809182230)
    == 20230809182230 AddIndexOnPhoneToUsers: migrating ===========================
       (0.3ms)  SHOW server_version_num
       (0.2ms)  SET statement_timeout TO 3600000
       (0.2ms)  SET lock_timeout TO 10000
       (0.3ms)  SELECT pg_advisory_unlock(400918011933137580)
    rails aborted!
    StandardError: An error has occurred, all later migrations canceled:
    
    === Custom check #strong_migrations ===
    
    No more indexes on the users table
    
@ankane ankane closed this as completed in ef8d306 Aug 9, 2023
@ankane
Copy link
Owner

ankane commented Aug 9, 2023

Hi @nleoutsa, thanks for the great report! Fixed in the commit above.

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

No branches or pull requests

2 participants