Class: Migration::ColumnDropper
- Inherits:
-
Object
- Object
- Migration::ColumnDropper
- Defined in:
- lib/migration/column_dropper.rb
Class Method Summary collapse
- .drop_readonly(table_name, column_name) ⇒ Object
- .execute_drop(table, columns) ⇒ Object
- .mark_readonly(table_name, column_name) ⇒ Object
Class Method Details
.drop_readonly(table_name, column_name) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/migration/column_dropper.rb', line 31 def self.drop_readonly(table_name, column_name) BaseDropper.drop_readonly_function(table_name, column_name) # Backward compatibility for old functions created in the public schema DB.exec( "DROP FUNCTION IF EXISTS #{BaseDropper.old_readonly_function_name(table_name, column_name)} CASCADE", ) end |
.execute_drop(table, columns) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/migration/column_dropper.rb', line 20 def self.execute_drop(table, columns) table = table.to_s columns.each do |column| column = column.to_s self.drop_readonly(table, column) # safe cause it is protected on method entry, can not be passed in params DB.exec("ALTER TABLE #{table} DROP COLUMN IF EXISTS #{column}") end end |
.mark_readonly(table_name, column_name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/migration/column_dropper.rb', line 7 def self.mark_readonly(table_name, column_name) BaseDropper.create_readonly_function(table_name, column_name) DB.exec <<~SQL CREATE TRIGGER #{BaseDropper.readonly_trigger_name(table_name, column_name)} BEFORE INSERT OR UPDATE OF #{column_name} ON #{table_name} FOR EACH ROW WHEN (NEW.#{column_name} IS NOT NULL) EXECUTE PROCEDURE #{BaseDropper.readonly_function_name(table_name, column_name)}; SQL end |