Skip to content

Commit

Permalink
Switched to skip_database method for consistency with enable/disable_…
Browse files Browse the repository at this point in the history
…check
  • Loading branch information
ankane committed Nov 9, 2024
1 parent 7cba344 commit d56919e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 2.1.0 (unreleased)

- Added `skip_databases` option
- Added `skip_database` method
- Added experimental `remove_invalid_indexes` option
- Added warning for unsupported adapters
- Improved output for `db:forward`, `db:rollback`, `db:migrate:up`, and `db:migrate:down`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ Check the [source code](https://github.com/ankane/strong_migrations/blob/master/
Skip checks and other functionality for specific databases with: [unreleased]

```ruby
StrongMigrations.skip_databases += [:catalog]
StrongMigrations.skip_database(:catalog)
```

Note: This does not affect `alphabetize_schema`.
Expand Down
8 changes: 6 additions & 2 deletions lib/strong_migrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class << self
:target_postgresql_version, :target_mysql_version, :target_mariadb_version,
:enabled_checks, :lock_timeout, :statement_timeout, :check_down, :target_version,
:safe_by_default, :target_sql_mode, :lock_timeout_retries, :lock_timeout_retry_delay,
:alphabetize_schema, :skip_databases, :remove_invalid_indexes
:alphabetize_schema, :skipped_databases, :remove_invalid_indexes
attr_writer :lock_timeout_limit
end
self.auto_analyze = false
Expand All @@ -40,7 +40,7 @@ class << self
self.safe_by_default = false
self.check_down = false
self.alphabetize_schema = false
self.skip_databases = []
self.skipped_databases = []
self.remove_invalid_indexes = false

# private
Expand Down Expand Up @@ -85,6 +85,10 @@ def self.check_enabled?(check, version: nil)
false
end
end

def self.skip_database(database)
self.skipped_databases << database
end
end

# load error messages
Expand Down
4 changes: 2 additions & 2 deletions lib/strong_migrations/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def version_safe?
end

def skip?
StrongMigrations.skip_databases.map(&:to_s).include?(db_config_name)
StrongMigrations.skipped_databases.map(&:to_s).include?(db_config_name)
end

private
Expand All @@ -157,7 +157,7 @@ def check_adapter
return if defined?(@adapter_checked)

if adapter.instance_of?(Adapters::AbstractAdapter)
warn "[strong_migrations] Unsupported adapter: #{connection.adapter_name}. Use StrongMigrations.skip_databases += #{[db_config_name.to_sym].inspect} to silence this warning."
warn "[strong_migrations] Unsupported adapter: #{connection.adapter_name}. Use StrongMigrations.skip_database(#{db_config_name.to_sym.inspect}) to silence this warning."
end

@adapter_checked = true
Expand Down
13 changes: 7 additions & 6 deletions test/multiple_databases_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_target_version_unconfigured
assert_equal "StrongMigrations.target_version is not configured for :animals database", error.message
end

def test_skip_databases
with_skip_databases([:animals]) do
def test_skip_database
with_skip_database(:animals) do
with_database(:primary) do
assert_unsafe CreateTableForce
end
Expand Down Expand Up @@ -59,9 +59,10 @@ def with_database(database, &block)
ActiveRecord::Base.establish_connection(previous_db_config) if previous_db_config
end

def with_skip_databases(skip_databases)
StrongMigrations.stub(:skip_databases, skip_databases) do
yield
end
def with_skip_database(database)
StrongMigrations.skip_database(database)
yield
ensure
StrongMigrations.skipped_databases.clear
end
end

0 comments on commit d56919e

Please sign in to comment.