-- 014: service: bloque del frontmatter de app.md → columnas apps + tabla service_targets
-- Issue 0105

ALTER TABLE apps ADD COLUMN service_port INTEGER NOT NULL DEFAULT 0;
ALTER TABLE apps ADD COLUMN service_health_endpoint TEXT NOT NULL DEFAULT '';
ALTER TABLE apps ADD COLUMN service_health_timeout_s INTEGER NOT NULL DEFAULT 0;
ALTER TABLE apps ADD COLUMN service_systemd_unit TEXT NOT NULL DEFAULT '';
ALTER TABLE apps ADD COLUMN service_systemd_scope TEXT NOT NULL DEFAULT '';
ALTER TABLE apps ADD COLUMN service_restart_policy TEXT NOT NULL DEFAULT '';
ALTER TABLE apps ADD COLUMN service_runtime TEXT NOT NULL DEFAULT '';
ALTER TABLE apps ADD COLUMN service_is_local_only INTEGER NOT NULL DEFAULT 0;

CREATE TABLE IF NOT EXISTS service_targets (
    app_id     TEXT NOT NULL,
    pc_id      TEXT NOT NULL,
    role       TEXT NOT NULL DEFAULT 'primary',
    PRIMARY KEY (app_id, pc_id)
);

CREATE INDEX IF NOT EXISTS idx_service_targets_pc ON service_targets(pc_id);
CREATE INDEX IF NOT EXISTS idx_service_targets_app ON service_targets(app_id);
