CREATE TABLE IF NOT EXISTS xbp_project_services (
    project_service_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
    project_id uuid NOT NULL REFERENCES xbp_projects(project_id) ON DELETE CASCADE,
    service_name text NOT NULL,
    target text,
    branch text,
    port integer,
    root_directory text,
    url text,
    healthcheck_path text,
    restart_policy text,
    start_wrapper text,
    systemd_service_name text,
    commands jsonb NOT NULL DEFAULT '{}'::jsonb,
    environment 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 (project_id, service_name)
);

CREATE INDEX IF NOT EXISTS idx_xbp_project_services_project_id ON xbp_project_services (project_id);
CREATE INDEX IF NOT EXISTS idx_xbp_project_services_port ON xbp_project_services (port);
