Sha256: fe037e526de01e5b557941ebef601df65a64a6e50c3155442d6879b299e2909e

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

module StrongMigrations
  module Migration
    def migrate(direction)
      strong_migrations_checker.direction = direction
      super
      connection.begin_db_transaction if strong_migrations_checker.transaction_disabled
    end

    def method_missing(method, *args)
      return super if is_a?(ActiveRecord::Schema)

      # Active Record 7.0.2+ versioned schema
      return super if defined?(ActiveRecord::Schema::Definition) && is_a?(ActiveRecord::Schema::Definition)

      catch(:safe) do
        strong_migrations_checker.perform(method, *args) do
          super
        end
      end
    end
    # same as ActiveRecord::Migration
    ruby2_keywords(:method_missing)

    def revert(*)
      if strong_migrations_checker.version_safe?
        safety_assured { super }
      else
        super
      end
    end

    def safety_assured
      strong_migrations_checker.class.safety_assured do
        yield
      end
    end

    def stop!(message, header: "Custom check")
      raise StrongMigrations::UnsafeMigration, "\n=== #{header} #strong_migrations ===\n\n#{message}\n"
    end

    private

    def strong_migrations_checker
      @strong_migrations_checker ||= StrongMigrations::Checker.new(self)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
strong_migrations-2.2.0 lib/strong_migrations/migration.rb
strong_migrations-2.1.0 lib/strong_migrations/migration.rb