CREATE TABLE failover_log (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  service_id INTEGER NOT NULL REFERENCES services(id) ON DELETE CASCADE,
  binding_id INTEGER NOT NULL REFERENCES service_bindings(id) ON DELETE CASCADE,
  fqdn TEXT NOT NULL,
  ip TEXT NOT NULL,
  action TEXT NOT NULL CHECK (action IN ('added', 'removed')),
  created_at TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE INDEX idx_failover_log_service ON failover_log(service_id, created_at DESC);
