This repository has been archived on 2023-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
2019-09-21 16:46:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class CreateRelationTransitions < ActiveRecord::Migration[6.0]
|
|
|
|
include Partynest::Migration
|
|
|
|
|
|
|
|
def change
|
|
|
|
create_table :relation_transitions do |t|
|
|
|
|
t.timestamps null: false
|
|
|
|
|
|
|
|
t.references :from_status, foreign_key: { to_table: :relation_statuses }
|
|
|
|
|
|
|
|
t.references :to_status,
|
|
|
|
null: false,
|
|
|
|
foreign_key: { to_table: :relation_statuses }
|
|
|
|
|
|
|
|
t.string :name, null: false, index: { unique: true }
|
|
|
|
|
|
|
|
t.index %i[from_status_id to_status_id], unique: true
|
|
|
|
end
|
|
|
|
|
2019-09-29 14:00:55 +00:00
|
|
|
add_constraint :relation_transitions, :name, <<~SQL
|
2019-09-21 16:46:20 +00:00
|
|
|
is_good_small_text(name)
|
|
|
|
SQL
|
|
|
|
|
2019-09-29 14:00:55 +00:00
|
|
|
add_constraint :relation_transitions, :statuses, <<~SQL
|
2019-09-21 16:46:20 +00:00
|
|
|
from_status_id != to_status_id
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
end
|