From e23feb6ada4eca6133ef32a87aee49aa0575ee4a Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 19 Jun 2025 17:44:41 +0200 Subject: [PATCH] integration/hsic: add SQLite schema validation before extraction - Check if database file exists at expected path - Verify database has actual schema/tables using sqlite3 command - Show file size and schema preview in logs - Error early if database is empty/uninitialized instead of extracting empty file This will help identify whether the issue is: - Missing database file - Empty/uninitialized database - Database created but not populated --- integration/hsic/hsic.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index 2f300795..9c6816fa 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -659,6 +659,31 @@ func (t *HeadscaleInContainer) SaveDatabase(savePath string) error { log.Printf("SQLite files found in %s:\n%s", t.hostname, sqliteFiles) } + // Check if the database file exists and has a schema + dbPath := "/tmp/integration_test_db.sqlite3" + fileInfo, err := t.Execute([]string{"ls", "-la", dbPath}) + if err != nil { + return fmt.Errorf("database file does not exist at %s: %w", dbPath, err) + } + log.Printf("Database file info: %s", fileInfo) + + // Check if the database has any tables (schema) + schemaCheck, err := t.Execute([]string{"sqlite3", dbPath, ".schema"}) + if err != nil { + return fmt.Errorf("failed to check database schema (sqlite3 command failed): %w", err) + } + + if strings.TrimSpace(schemaCheck) == "" { + return fmt.Errorf("database file exists but has no schema (empty database)") + } + + // Show a preview of the schema (first 500 chars) + schemaPreview := schemaCheck + if len(schemaPreview) > 500 { + schemaPreview = schemaPreview[:500] + "..." + } + log.Printf("Database schema preview:\n%s", schemaPreview) + tarFile, err := t.FetchPath("/tmp/integration_test_db.sqlite3") if err != nil { return fmt.Errorf("failed to fetch database file: %w", err)