migrate to postgres

This commit is contained in:
m
2026-07-12 23:49:25 +02:00
parent e7b418b004
commit e59fde6a48
15 changed files with 151 additions and 125 deletions
+6 -8
View File
@@ -5,25 +5,23 @@ import (
"fmt"
"os"
_ "modernc.org/sqlite"
_ "github.com/lib/pq"
)
const driver = "sqlite"
const driver = "postgres"
func Connect() (*sql.DB, error) {
path := os.Getenv("DB_PATH")
if path == "" {
path = "vaultdrop.db"
dsn := os.Getenv("DATABASE_URL")
if dsn == "" {
dsn = "postgres://localhost:5432/vaultdrop?sslmode=disable"
}
dsn := fmt.Sprintf("file:%s?_journal_mode=WAL&_busy_timeout=5000&_foreign_keys=on", path)
database, err := sql.Open(driver, dsn)
if err != nil {
return nil, fmt.Errorf("open db: %w", err)
}
database.SetMaxOpenConns(1)
database.SetMaxOpenConns(25)
if err := database.Ping(); err != nil {
return nil, fmt.Errorf("ping db: %w", err)