You can execute arbitrary SQL in your migrations as well.
We have some helper methods that add foreign keys to our tables:
def add_foreign_key(from_table, from_column, to_table)
constraint_name = "fk_#{from_table}_#{from_column}"
execute %{alter table #{from_table}
add constraint #{constraint_name}
foreign key (#{from_column})
references #{to_table}(id)
}
end
You can use any SQL your database supports.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…