diff --git a/cmd/web/main.go b/cmd/web/main.go index 11ab24e..1b6924f 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -8,7 +8,6 @@ import ( "context" "database/sql" _ "github.com/mattn/go-sqlite3" - "log" "log/slog" "net/http" "os" @@ -66,14 +65,11 @@ func main() { } func openDb() (*sql.DB, error) { - db, err := sql.Open("sqlite3", "./qv.sqlite") + + db, err := sql.Open("sqlite3", "./qv.sqlite?_foreign_keys=on") if err == nil { err = db.Ping() } - _, err = db.Exec("PRAGMA foreign_keys = ON") - if err != nil { - log.Fatalf("Failed to enable foreign key constraints: %v", err) - } return db, err } diff --git a/internal/migrations/sql/000001_init.up.sql b/internal/migrations/sql/000001_init.up.sql index 1a236ac..754c3c8 100644 --- a/internal/migrations/sql/000001_init.up.sql +++ b/internal/migrations/sql/000001_init.up.sql @@ -70,5 +70,3 @@ CREATE TRIGGER prevent_created_at_update_votes BEGIN SELECT RAISE(FAIL, 'created_at column is read-only'); END; - -PRAGMA foreign_keys = ON; -- run after opening the connection so foreign key constraints are checked \ No newline at end of file