CREATE TABLE reconcile_runs_v3 (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    batch_id INTEGER,
    host_id INTEGER NOT NULL,
    provider_id INTEGER NOT NULL,
    status TEXT NOT NULL,
    summary_json TEXT NOT NULL DEFAULT '{}',
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT fk_reconcile_runs_batch FOREIGN KEY (batch_id) REFERENCES import_batches(id) ON DELETE CASCADE,
    CONSTRAINT fk_reconcile_runs_host FOREIGN KEY (host_id) REFERENCES hosts(id) ON DELETE CASCADE,
    CONSTRAINT fk_reconcile_runs_provider FOREIGN KEY (provider_id) REFERENCES providers(id) ON DELETE CASCADE
);

INSERT INTO reconcile_runs_v3 (id, batch_id, host_id, provider_id, status, summary_json, created_at)
SELECT rr.id, NULL, rr.host_id, rr.provider_id, rr.status, rr.summary_json, rr.created_at
FROM reconcile_runs rr;

DROP TABLE reconcile_runs;
ALTER TABLE reconcile_runs_v3 RENAME TO reconcile_runs;
