Module: Fx::Statements::Trigger
- Defined in:
- lib/fx/statements/trigger.rb
Overview
Methods that are made available in migrations for managing Fx triggers.
Constant Summary collapse
- DEFINTION_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'trigger'
Instance Method Summary collapse
-
#create_trigger(name, version: nil, on: nil, sql_definition: nil) ⇒ Object
Create a new database trigger.
-
#drop_trigger(name, *_opts, on: nil, revert_to_version: nil) ⇒ Object
Drop a database trigger by name.
-
#update_trigger(name, version: nil, on: nil, sql_definition: nil, revert_to_version: nil) ⇒ Object
Update a database trigger to a new version.
Instance Method Details
#create_trigger(name, version: nil, on: nil, sql_definition: nil) ⇒ Object
Create a new database trigger.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fx/statements/trigger.rb', line 32 def create_trigger(name, version: nil, on: nil, sql_definition: nil) if version.present? && sql_definition.present? raise( ArgumentError, 'sql_definition and version cannot both be set' ) end if version.nil? version = 1 end sql_definition = sql_definition.strip_heredoc if sql_definition sql_definition ||= Fx::Definition.new( name: name, version: version, type: DEFINTION_TYPE, ).to_sql Fx.database.create_trigger(sql_definition) end |
#drop_trigger(name, *_opts, on: nil, revert_to_version: nil) ⇒ Object
Drop a database trigger by name.
67 68 69 |
# File 'lib/fx/statements/trigger.rb', line 67 def drop_trigger(name, *_opts, on: nil, revert_to_version: nil) Fx.database.drop_trigger(name, on: on) end |
#update_trigger(name, version: nil, on: nil, sql_definition: nil, revert_to_version: nil) ⇒ Object
Update a database trigger to a new version.
The existing trigger is dropped and recreated using the supplied ‘on` and `version` parameter.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/fx/statements/trigger.rb', line 103 def update_trigger(name, version: nil, on: nil, sql_definition: nil, revert_to_version: nil) if version.nil? && sql_definition.nil? raise( ArgumentError, 'version or sql_definition must be specified' ) end if version.present? && sql_definition.present? raise( ArgumentError, 'sql_definition and version cannot both be set' ) end raise ArgumentError, 'on is required' if on.nil? sql_definition = sql_definition.strip_heredoc if sql_definition sql_definition ||= Fx::Definition.new( name: name, version: version, type: DEFINTION_TYPE ).to_sql Fx.database.update_trigger( name, on: on, sql_definition: sql_definition ) end |