2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-03-21 22:28:52 +08:00
|
|
|
require 'migration/base_dropper'
|
2018-03-20 15:20:50 +08:00
|
|
|
|
|
|
|
module Migration
|
2018-10-08 15:47:38 +08:00
|
|
|
class Migration::TableDropper
|
2018-03-20 15:20:50 +08:00
|
|
|
def self.read_only_table(table_name)
|
2018-10-08 15:47:38 +08:00
|
|
|
BaseDropper.create_readonly_function(table_name)
|
2018-03-20 15:20:50 +08:00
|
|
|
|
2018-06-19 14:13:14 +08:00
|
|
|
DB.exec <<~SQL
|
2018-10-08 15:47:38 +08:00
|
|
|
CREATE TRIGGER #{BaseDropper.readonly_trigger_name(table_name)}
|
2018-03-20 15:20:50 +08:00
|
|
|
BEFORE INSERT OR UPDATE OR DELETE OR TRUNCATE
|
|
|
|
ON #{table_name}
|
|
|
|
FOR EACH STATEMENT
|
2018-10-08 15:47:38 +08:00
|
|
|
EXECUTE PROCEDURE #{BaseDropper.readonly_function_name(table_name)};
|
2018-03-20 15:20:50 +08:00
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
2018-10-08 15:47:38 +08:00
|
|
|
def self.execute_drop(table_name)
|
|
|
|
DB.exec("DROP TABLE IF EXISTS #{table_name}")
|
2019-08-08 22:58:13 +08:00
|
|
|
BaseDropper.drop_readonly_function(table_name)
|
2018-03-20 15:20:50 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|