CREATE TABLE IF NOT EXISTS xbp_nginx_configs (
    nginx_config_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
    project_id uuid REFERENCES xbp_projects(project_id) ON DELETE SET NULL,
    domain text NOT NULL,
    config_path text NOT NULL,
    content text,
    upstream_ports jsonb NOT NULL DEFAULT '[]'::jsonb,
    listen_ports jsonb NOT NULL DEFAULT '[]'::jsonb,
    metadata jsonb NOT NULL DEFAULT '{}'::jsonb,
    created_at timestamptz NOT NULL DEFAULT now(),
    updated_at timestamptz NOT NULL DEFAULT now(),
    UNIQUE (domain, config_path)
);

CREATE INDEX IF NOT EXISTS idx_xbp_nginx_configs_project_id ON xbp_nginx_configs (project_id);
CREATE INDEX IF NOT EXISTS idx_xbp_nginx_configs_domain ON xbp_nginx_configs (domain);
