module Avram::Migrator::StatementHelpers
Included Modules
Direct including types
Defined in:
avram/migrator/statement_helpers.crInstance Method Summary
- #create_foreign_key(from : TableName, to : TableName, on_delete : Symbol, column : Symbol | Nil, primary_key = :id)
- #create_function(name : String, body : String, returns : String = "trigger")
- #create_index(table_name : TableName, columns : Columns, unique = false, using = :btree, name : String | Nil | Symbol | Nil = nil)
-
#create_trigger(table_name : TableName, name : String, function_name : String, callback : Symbol = :before, on : Array(Symbol) = [:update])
Drop any existing trigger by this name first before creating.
- #disable_extension(name : String)
- #drop(table_name)
- #drop_foreign_key(from : TableName, references : TableName, column : Symbol | Nil)
- #drop_function(name : String)
- #drop_index(table_name : TableName, columns : Columns | Nil = nil, if_exists = false, on_delete = :do_nothing, name : String | Nil | Symbol | Nil = nil)
-
#drop_trigger(table_name : TableName, name : String)
Drop the tigger
name
for the tabletable_name
- #enable_extension(name : String)
- #make_optional(table : TableName, column : Symbol)
- #make_required(table : TableName, column : Symbol)
- #update_extension(name : String, to : String | Nil = nil)
Macro Summary
Instance methods inherited from module Avram::Migrator::IndexStatementHelpers
add_index(column : Symbol, unique = false, using : Symbol = :btree)
add_index,
index_added?(index : String, column : Symbol)
index_added?
Instance Method Detail
def create_foreign_key(from : TableName, to : TableName, on_delete : Symbol, column : Symbol | Nil, primary_key = :id)
#
def create_index(table_name : TableName, columns : Columns, unique = false, using = :btree, name : String | Nil | Symbol | Nil = nil)
#
def create_trigger(table_name : TableName, name : String, function_name : String, callback : Symbol = :before, on : Array(Symbol) = [:update])
#
Drop any existing trigger by this name first before creating. Postgres does not support updating or replacing a trigger as of version 12
Creates a new TRIGGER named name
on the table table_name
.
function_name
- The PG function to run from this trigger.
callback
- When to run this trigger (BEFORE or AFTER). Default :before
on
- The operation(s) for this trigger (INSERT, UPDATE, DELETE). Default is [:update]
create_trigger(:users, "trigger_set_timestamps", "set_timestamps")
# => CREATE TRIGGER trigger_set_timestamps BEFORE UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE set_timestamps();
def drop_index(table_name : TableName, columns : Columns | Nil = nil, if_exists = false, on_delete = :do_nothing, name : String | Nil | Symbol | Nil = nil)
#
Drop the tigger name
for the table table_name