CREATE TABLE IF NOT EXISTS tournament_signup_fields (
    id SERIAL PRIMARY KEY,
    tournament_id INTEGER NOT NULL REFERENCES tournament_info(id) ON DELETE CASCADE,
    field_key TEXT NOT NULL,
    scope TEXT NOT NULL CHECK (scope IN ('entry', 'participant')),
    label TEXT NOT NULL,
    field_type TEXT NOT NULL,
    required BOOLEAN NOT NULL DEFAULT FALSE,
    placeholder TEXT,
    position INTEGER NOT NULL DEFAULT 0,
    UNIQUE (tournament_id, field_key)
);

CREATE INDEX IF NOT EXISTS idx_tournament_signup_fields_tournament
    ON tournament_signup_fields (tournament_id, scope, position, id);
