-- host-metrics 0001: adopt_host_metrics_tables -- Generated by termix-plugin migrations. Review before committing. CREATE TABLE IF NOT EXISTS "host_metrics_preferences" ( "id" integer PRIMARY KEY AUTOINCREMENT, "user_id" text NOT NULL, "host_id" integer NOT NULL, "layout" text NOT NULL, "created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE, FOREIGN KEY ("host_id") REFERENCES "ssh_data" ("id") ON DELETE CASCADE ); CREATE UNIQUE INDEX IF NOT EXISTS "idx_host_metrics_prefs_user_host" ON "host_metrics_preferences" ("user_id", "host_id"); ALTER TABLE "host_metrics_preferences" RENAME TO "p_host_metrics_host_metrics_preferences"; CREATE TABLE IF NOT EXISTS "host_health_checks" ( "id" integer PRIMARY KEY AUTOINCREMENT, "user_id" text NOT NULL, "host_id" integer NOT NULL, "checks" text NOT NULL, "interval_seconds" integer NOT NULL DEFAULT 300, "created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE, FOREIGN KEY ("host_id") REFERENCES "ssh_data" ("id") ON DELETE CASCADE ); CREATE UNIQUE INDEX IF NOT EXISTS "idx_host_health_checks_user_host" ON "host_health_checks" ("user_id", "host_id"); ALTER TABLE "host_health_checks" RENAME TO "p_host_metrics_host_health_checks"; CREATE TABLE IF NOT EXISTS "host_health_history" ( "id" integer PRIMARY KEY AUTOINCREMENT, "user_id" text NOT NULL, "host_id" integer NOT NULL, "check_id" text NOT NULL, "ts" text NOT NULL DEFAULT CURRENT_TIMESTAMP, "ok" integer NOT NULL, "latency_ms" integer, "detail" text, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE, FOREIGN KEY ("host_id") REFERENCES "ssh_data" ("id") ON DELETE CASCADE ); CREATE INDEX IF NOT EXISTS "idx_host_health_history_lookup" ON "host_health_history" ("user_id", "host_id", "check_id", "ts"); ALTER TABLE "host_health_history" RENAME TO "p_host_metrics_host_health_history"; CREATE TABLE IF NOT EXISTS "host_metrics_history" ( "id" integer PRIMARY KEY AUTOINCREMENT, "host_id" integer NOT NULL, "ts" text NOT NULL DEFAULT CURRENT_TIMESTAMP, "cpu_percent" real, "mem_percent" real, "disk_percent" real, "net_rx_bytes" integer, "net_tx_bytes" integer, FOREIGN KEY ("host_id") REFERENCES "ssh_data" ("id") ON DELETE CASCADE ); CREATE INDEX IF NOT EXISTS "idx_host_metrics_history_host_ts" ON "host_metrics_history" ("host_id", "ts"); ALTER TABLE "host_metrics_history" RENAME TO "p_host_metrics_host_metrics_history";