mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 10:50:26 -06:00
FIX: Allow post migrations using #change
to carry out unsafe migration
This commit is contained in:
parent
4601833e4e
commit
9ab5801a1b
@ -34,13 +34,17 @@ class Migration::SafeMigrate
|
|||||||
private
|
private
|
||||||
|
|
||||||
def is_post_deploy_migration?
|
def is_post_deploy_migration?
|
||||||
|
instance_methods = self.class.instance_methods(false)
|
||||||
|
|
||||||
method =
|
method =
|
||||||
if self.respond_to?(:up)
|
if instance_methods.include?(:up)
|
||||||
:up
|
:up
|
||||||
elsif self.respond_to?(:change)
|
elsif instance_methods.include?(:change)
|
||||||
:change
|
:change
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return false if !method
|
||||||
|
|
||||||
self.method(method).source_location.first.include?(
|
self.method(method).source_location.first.include?(
|
||||||
Discourse::DB_POST_MIGRATE_PATH
|
Discourse::DB_POST_MIGRATE_PATH
|
||||||
)
|
)
|
||||||
|
@ -99,18 +99,28 @@ describe Migration::SafeMigrate do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'for a post deployment migration' do
|
describe 'for a post deployment migration' do
|
||||||
it 'should not ban unsafe migrations' do
|
it 'should not ban unsafe migrations using up' do
|
||||||
user = Fabricate(:user)
|
|
||||||
Migration::SafeMigrate::SafeMigration.enable_safe!
|
Migration::SafeMigrate::SafeMigration.enable_safe!
|
||||||
|
|
||||||
path = File.expand_path "#{Rails.root}/spec/fixtures/db/post_migrate"
|
path = File.expand_path "#{Rails.root}/spec/fixtures/db/post_migrate/drop_table"
|
||||||
|
|
||||||
|
output = capture_stdout do
|
||||||
|
migrate_up(path)
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(output).to include("drop_table(:email_logs)")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not ban unsafe migrations using change' do
|
||||||
|
Migration::SafeMigrate::SafeMigration.enable_safe!
|
||||||
|
|
||||||
|
path = File.expand_path "#{Rails.root}/spec/fixtures/db/post_migrate/change"
|
||||||
|
|
||||||
output = capture_stdout do
|
output = capture_stdout do
|
||||||
migrate_up(path)
|
migrate_up(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(output).to include("drop_table(:email_logs)")
|
expect(output).to include("drop_table(:email_logs)")
|
||||||
expect(user.reload).to eq(user)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
10
spec/fixtures/db/post_migrate/change/20990309014015_drop_email_logs.rb
vendored
Normal file
10
spec/fixtures/db/post_migrate/change/20990309014015_drop_email_logs.rb
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class DropEmailLogs < ActiveRecord::Migration[5.2]
|
||||||
|
DROPPED_TABLES ||= %i{email_logs}
|
||||||
|
|
||||||
|
def change
|
||||||
|
drop_table :email_logs
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user