123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- Rails.root.join('db/migrate').children.each do |migration|
- require migration.to_s
- end
- module DbMigrationHelper
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- def migrate(direction = :up)
- instance = described_class.new
- yield(instance) if block_given?
- instance.suppress_messages do
- instance.migrate(direction)
- end
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- def without_foreign_key(from_table, column:)
- suppress_messages do
- break if !foreign_key_exists?(from_table, column: column)
- remove_foreign_key(from_table, column: column)
- end
- end
-
-
-
-
-
-
-
-
-
-
-
- def without_column(from_table, column:)
- suppress_messages do
- Array(column).each do |elem|
- next if !column_exists?(from_table, elem)
- remove_column(from_table, elem)
- end
- end
- end
-
-
-
-
-
-
-
-
-
-
-
- def without_index(from_table, column:)
- suppress_messages do
- break if !index_exists?(from_table, column)
- remove_index(from_table, column: column)
- end
- end
-
-
-
-
-
-
-
-
- def method_missing(method, ...)
- ActiveRecord::Migration.send(method, ...)
- rescue NoMethodError
- super
- end
-
-
-
-
-
-
-
-
- def respond_to_missing?(...)
- true
- end
-
-
-
-
-
-
-
-
-
-
-
- def adds_foreign_key(from_table, column:)
- without_foreign_key(from_table, column: column)
- suppress_messages do
- expect do
- migrate
- end.to change {
- foreign_key_exists?(from_table, column: column)
- }
- end
- end
- def self.included(base)
-
- base.class_exec do
-
-
-
-
-
-
-
-
- before do |example|
- initialized = example.metadata.fetch(:system_init_done, true)
- system_init_done(initialized)
- end
- end
- end
- end
- RSpec.configure do |config|
- config.include DbMigrationHelper, type: :db_migration
- end
|