From 5f53ffec4f620ffa76fcc18089cef331eb1b0afa Mon Sep 17 00:00:00 2001 From: t Date: Thu, 2 Apr 2026 15:00:31 -0400 Subject: [PATCH] updated sqlite engine to address compilation errors --- go.mod | 13 +++++++++++++ go.sum | 21 +++++++++++++++++++++ pkg/datastore/concurrency_test.go | 6 +++--- pkg/datastore/db.go | 7 ++++--- pkg/datastore/diff_test.go | 4 ++-- pkg/datastore/migrate_test.go | 4 ++-- pkg/sla/sla_test.go | 4 ++-- 7 files changed, 47 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index f9d9566..ca6d4f5 100644 --- a/go.mod +++ b/go.mod @@ -6,3 +6,16 @@ require ( github.com/mattn/go-sqlite3 v1.14.34 golang.org/x/crypto v0.48.0 ) + +require ( + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/ncruces/go-strftime v1.0.0 // indirect + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + golang.org/x/sys v0.42.0 // indirect + modernc.org/libc v1.70.0 // indirect + modernc.org/mathutil v1.7.1 // indirect + modernc.org/memory v1.11.0 // indirect + modernc.org/sqlite v1.48.0 // indirect +) diff --git a/go.sum b/go.sum index 70d63c0..55fd6f9 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,25 @@ +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.14.34 h1:3NtcvcUnFBPsuRcno8pUtupspG/GM+9nZ88zgJcp6Zk= github.com/mattn/go-sqlite3 v1.14.34/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= +github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= +golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +modernc.org/libc v1.70.0 h1:U58NawXqXbgpZ/dcdS9kMshu08aiA6b7gusEusqzNkw= +modernc.org/libc v1.70.0/go.mod h1:OVmxFGP1CI/Z4L3E0Q3Mf1PDE0BucwMkcXjjLntvHJo= +modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= +modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= +modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI= +modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw= +modernc.org/sqlite v1.48.0 h1:ElZyLop3Q2mHYk5IFPPXADejZrlHu7APbpB0sF78bq4= +modernc.org/sqlite v1.48.0/go.mod h1:hWjRO6Tj/5Ik8ieqxQybiEOUXy0NJFNp2tpvVpKlvig= diff --git a/pkg/datastore/concurrency_test.go b/pkg/datastore/concurrency_test.go index 2924977..8c63427 100644 --- a/pkg/datastore/concurrency_test.go +++ b/pkg/datastore/concurrency_test.go @@ -7,7 +7,7 @@ import ( "sync" "testing" - _ "github.com/mattn/go-sqlite3" + _ "modernc.org/sqlite" ) // runChaosEngine fires 100 concurrent workers at the provided database connection @@ -73,8 +73,8 @@ func TestSQLiteConcurrency_Tuned_Succeeds(t *testing.T) { tempDir := t.TempDir() dbPath := filepath.Join(tempDir, "tuned.db") - dsn := fmt.Sprintf("%s?_journal_mode=WAL&_synchronous=NORMAL&_busy_timeout=5000", dbPath) - db, err := sql.Open("sqlite3", dsn) + dsn := fmt.Sprintf("%s?_pragma=journal_mode(WAL)&_pragma=synchronous(NORMAL)&_pragma=busy_timeout(5000)", dbPath) + db, err := sql.Open("sqlite", dsn) if err != nil { t.Fatalf("Failed to open tuned DB: %v", err) } diff --git a/pkg/datastore/db.go b/pkg/datastore/db.go index 3aa9c3f..a7b09da 100644 --- a/pkg/datastore/db.go +++ b/pkg/datastore/db.go @@ -9,7 +9,7 @@ import ( "time" "epigas.gitea.cloud/RiskRancher/core/pkg/domain" - _ "github.com/mattn/go-sqlite3" + _ "modernc.org/sqlite" ) //go:embed schema.sql @@ -19,9 +19,10 @@ var schemaSQL string var defaultAdaptersFS embed.FS func InitDB(filepath string) *sql.DB { - dsn := "file:" + filepath + "?_journal=WAL&_timeout=5000&_sync=1&_fk=1" - db, err := sql.Open("sqlite3", dsn) + dsn := "file:" + filepath + "?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)&_pragma=synchronous(NORMAL)&_pragma=foreign_keys(1)" + + db, err := sql.Open("sqlite", dsn) if err != nil { log.Fatalf("Failed to open database: %v", err) } diff --git a/pkg/datastore/diff_test.go b/pkg/datastore/diff_test.go index 847c665..4b19a85 100644 --- a/pkg/datastore/diff_test.go +++ b/pkg/datastore/diff_test.go @@ -6,11 +6,11 @@ import ( "testing" "epigas.gitea.cloud/RiskRancher/core/pkg/domain" - _ "github.com/mattn/go-sqlite3" // We need the SQLite driver for the test + _ "modernc.org/sqlite" // We need the SQLite driver for the test ) func setupTestDB(t *testing.T) *SQLiteStore { - db, err := sql.Open("sqlite3", ":memory:") + db, err := sql.Open("sqlite", ":memory:") if err != nil { t.Fatalf("Failed to open in-memory SQLite database: %v", err) } diff --git a/pkg/datastore/migrate_test.go b/pkg/datastore/migrate_test.go index 167ba31..25eda73 100644 --- a/pkg/datastore/migrate_test.go +++ b/pkg/datastore/migrate_test.go @@ -4,11 +4,11 @@ import ( "database/sql" "testing" - _ "github.com/mattn/go-sqlite3" + _ "modernc.org/sqlite" ) func TestSchemaMigrations(t *testing.T) { - db, err := sql.Open("sqlite3", ":memory:") + db, err := sql.Open("sqlite", ":memory:") if err != nil { t.Fatalf("Failed to open test db: %v", err) } diff --git a/pkg/sla/sla_test.go b/pkg/sla/sla_test.go index 626569f..12b1c30 100644 --- a/pkg/sla/sla_test.go +++ b/pkg/sla/sla_test.go @@ -4,7 +4,7 @@ import ( "database/sql" "testing" - _ "github.com/mattn/go-sqlite3" + _ "modernc.org/sqlite" ) // GetSLAPolicy simulates the core engine function that fetches SLA rules @@ -16,7 +16,7 @@ func GetSLAPolicy(db *sql.DB, domain string, severity string) (daysToRemediate i // setupTestDB spins up an isolated, in-memory database for testing func setupTestDB(t *testing.T) *sql.DB { - db, err := sql.Open("sqlite3", ":memory:") + db, err := sql.Open("sqlite", ":memory:") if err != nil { t.Fatalf("Failed to open test database: %v", err) }