Avram::Migrator::StatementHelpers
Inherits Avram::TableFor < Avram::Migrator::IndexStatementHelpers
Instance methods
create_foreign_key(from : TableName, to : TableName, on_delete : Symbol, column : Symbol | Nil, primary_key = :id)
Sourcecreate_function(name : String, body : String, returns : String = "trigger", language : String = "plpgsql", behavior : Avram::Migrator::CreateFunctionStatement::Behavior = Avram::Migrator::CreateFunctionStatement::Behavior::VOLATILE)
Sourcecreate_index(table_name : TableName, columns : Columns, unique = false, concurrently = false, using = :btree, name : String | Nil | Symbol | Nil = nil)
Sourcecreate_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();
drop(table_name, *, if_exists = false)
Sourcedrop_index(table_name : TableName, columns : Columns | Nil = nil, if_exists = false, on_delete = :do_nothing, name : String | Nil | Symbol | Nil = nil)
SourceDrop the tigger name for the table table_name
Macros
alter(table_name, *, if_exists = false)
Sourcecreate(table_name, *, if_not_exists = false)
Source