# frozen_string_literal: true class CreateStreamConcurrencyViolations < ActiveRecord::Migration[7.2] def change create_table :stream_concurrency_violations, id: :uuid, default: -> { "gen_random_uuid()" } do |t| t.references :user, type: :uuid, foreign_key: { on_delete: :nullify } t.references :occupying_session, type: :uuid, foreign_key: { to_table: :stream_sessions, on_delete: :nullify } t.references :attempted_session, type: :uuid, foreign_key: { to_table: :stream_sessions, on_delete: :nullify } t.references :occupying_club, type: :uuid, foreign_key: { to_table: :clubs, on_delete: :nullify } t.references :attempted_club, type: :uuid, foreign_key: { to_table: :clubs, on_delete: :nullify } t.string :attempt_action, null: false, default: "start" t.string :user_email, null: false t.string :user_name t.string :occupying_club_name t.string :attempted_club_name t.string :occupying_match_label, null: false t.string :attempted_match_label, null: false t.string :occupying_status t.string :occupying_device t.string :attempted_device t.boolean :devices_differ, null: false, default: false t.jsonb :metadata, null: false, default: {} t.datetime :created_at, null: false end add_index :stream_concurrency_violations, :created_at add_index :stream_concurrency_violations, :devices_differ add_index :stream_sessions, %i[user_id status], name: "index_stream_sessions_on_user_id_and_status" end end