CREATE TABLE quiz_privilege_usage (
    id bigserial UNIQUE NOT NULL PRIMARY KEY,
    quiz_id BIGINT NOT NULL REFERENCES quiz(id) ON DELETE CASCADE,
    privilege_id BIGINT NOT NULL REFERENCES privilege(id) ON DELETE CASCADE,
    privilege_id_str VARCHAR(50) NOT NULL,
    used_count INT NOT NULL DEFAULT 0,
    created_at TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP
);

CREATE UNIQUE INDEX idx_quiz_privilege_unique ON quiz_privilege_usage (quiz_id, privilege_id, privilege_id_str);