-- 010_settings_cascade.sql — v0.2.0
-- Adds team-scoped package settings for the three-tier cascade:
-- global (package_settings) → team (package_team_settings) → user (package_user_settings)

CREATE TABLE IF NOT EXISTS package_team_settings (
    package_id   TEXT        NOT NULL REFERENCES packages(id) ON DELETE CASCADE,
    team_id      UUID        NOT NULL REFERENCES teams(id) ON DELETE CASCADE,
    settings     JSONB       NOT NULL DEFAULT '{}',
    updated_at   TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    PRIMARY KEY (package_id, team_id)
);

CREATE INDEX IF NOT EXISTS idx_pkg_team_settings_team ON package_team_settings(team_id);
