-- ACL de visibilidade de repositorios GitHub por equipe
-- Objetivo:
-- 1) permitir restringir repositorios mapeados a equipes especificas
-- 2) manter compatibilidade: repos sem linhas na ACL continuam sem restricao especifica
-- 3) preparar a base para comparacao futura com times oficiais do GitHub

CREATE TABLE IF NOT EXISTS wpjy_github_repo_team_access (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    repo_mapping_id BIGINT UNSIGNED NOT NULL,
    equipe_id BIGINT UNSIGNED NOT NULL,
    access_level VARCHAR(20) NOT NULL DEFAULT 'view',
    notes TEXT NULL,
    created_by BIGINT UNSIGNED NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    UNIQUE KEY uq_wpjy_github_repo_team_access_repo_team (repo_mapping_id, equipe_id),
    KEY idx_wpjy_github_repo_team_access_repo (repo_mapping_id),
    KEY idx_wpjy_github_repo_team_access_team (equipe_id),
    KEY idx_wpjy_github_repo_team_access_level (access_level)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
