package de.roko.genalogy.downloader.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class DatenbankReset {

    private static final String DB = "archion.db";

    public static void main(String[] args) throws Exception {
        reset();
        System.out.println("✅ Datenbank erfolgreich geleert.");
    }

    public static void reset() throws Exception {
        try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + DB);
             Statement stmt = conn.createStatement()) {

            // Reihenfolge beachten wegen FK-Beziehungen (falls vorhanden)
            stmt.executeUpdate("DELETE FROM ort");
            stmt.executeUpdate("DELETE FROM kreis");
            stmt.executeUpdate("DELETE FROM archive");

            // Optional: IDs zurücksetzen (nur nötig bei AUTOINCREMENT-Reset)
            stmt.executeUpdate("DELETE FROM sqlite_sequence WHERE name IN ('archive', 'kreis', 'ort')");
        }
    }
}
