2020-03-24 16:45:27 +01:00
|
|
|
# frozen_string_literal:true
|
2019-01-07 12:29:52 +01:00
|
|
|
|
2020-03-24 16:45:27 +01:00
|
|
|
class ProtectAccountingPeriods < ActiveRecord::Migration[4.2]
|
2019-01-07 12:29:52 +01:00
|
|
|
# PostgreSQL only
|
|
|
|
def up
|
2019-03-18 12:09:54 +01:00
|
|
|
return if Rails.env.development? || Rails.env.test?
|
|
|
|
|
2019-01-07 16:45:31 +01:00
|
|
|
execute("CREATE RULE accounting_periods_del_protect AS ON DELETE TO #{AccountingPeriod.arel_table.name} DO INSTEAD NOTHING;")
|
|
|
|
execute("CREATE RULE accounting_periods_upd_protect AS ON UPDATE TO #{AccountingPeriod.arel_table.name} DO INSTEAD NOTHING;")
|
2019-01-07 12:29:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2019-01-07 16:45:31 +01:00
|
|
|
execute("DROP RULE IF EXISTS accounting_periods_del_protect ON #{AccountingPeriod.arel_table.name};")
|
|
|
|
execute("DROP RULE IF EXISTS accounting_periods_upd_protect ON #{AccountingPeriod.arel_table.name};")
|
2019-01-07 12:29:52 +01:00
|
|
|
end
|
|
|
|
end
|