hensei-api/db/migrate/20251204063649_create_crew_memberships.rb
Justin Edmund 9b01aa0ff3 add crew and crew_membership models with migrations
- crews table with name, gamertag, granblue_crew_id, description
- crew_memberships with role enum (member/vice_captain/captain)
- partial unique index ensures one active crew per user
- updated User model with crew associations and helper methods
2025-12-03 22:41:19 -08:00

20 lines
726 B
Ruby

class CreateCrewMemberships < ActiveRecord::Migration[8.0]
def change
create_table :crew_memberships, id: :uuid do |t|
t.references :crew, type: :uuid, null: false, foreign_key: true
t.references :user, type: :uuid, null: false, foreign_key: true
t.integer :role, default: 0, null: false
t.boolean :retired, default: false, null: false
t.datetime :retired_at
t.timestamps
end
add_index :crew_memberships, [:crew_id, :user_id], unique: true
add_index :crew_memberships, [:crew_id, :role]
add_index :crew_memberships, [:user_id],
unique: true,
where: "retired = false",
name: "index_crew_memberships_on_active_user"
end
end