add support for SQLite as an alternative database backend
Some checks failed
Build & Publish Docker Image / build-and-push (push) Failing after 33s

Implement SQLite support using the pure Go `modernc.org/sqlite` driver and update the migration system to handle driver-specific schemas. Users can now choose between MySQL and SQLite by setting the `DB_DRIVER` environment variable.
This commit is contained in:
Flavio Fois
2026-03-29 17:46:27 +02:00
parent e6d663f4f2
commit fa1f65baf7
14 changed files with 317 additions and 79 deletions

View File

@@ -21,6 +21,7 @@ type RateLimitConfig struct {
type Config struct {
Port string
Driver string
DSN string
Database string
APIKey string
@@ -80,9 +81,19 @@ func load() *Config {
connMaxLifetime = 5
}
dbName := os.Getenv("DATABASE_NAME")
if dbName == "" {
panic("DATABASE_NAME environment variable is required")
driver := os.Getenv("DB_DRIVER")
if driver == "" {
driver = "mysql"
}
var dbName string
if driver == "sqlite" {
dbName = "main"
} else {
dbName = os.Getenv("DATABASE_NAME")
if dbName == "" {
panic("DATABASE_NAME environment variable is required")
}
}
if os.Getenv("DB_DSN") == "" {
@@ -91,6 +102,7 @@ func load() *Config {
return &Config{
Port: port,
Driver: driver,
DSN: os.Getenv("DB_DSN"),
Database: dbName,
APIKey: apiKey,