40 lines
640 B
Go

package main
import (
"context"
"embed"
"gitea.seeseepuff.be/seeseemelk/mysqlite"
"log"
"os"
)
//go:embed migrations/*.sql
var migrations embed.FS
type ServerConfig struct {
Datasource string
Port string
}
func main() {
config := ServerConfig{
Datasource: os.Getenv("DB_PATH"),
}
start(context.Background(), config)
}
func start(ctx context.Context, config ServerConfig) {
// Open a file-based database
db, err := mysqlite.OpenDb(config.Datasource)
if err != nil {
log.Fatal(err)
}
defer db.MustClose()
// Apply migrations
err = db.MigrateDb(migrations, "migrations")
if err != nil {
log.Fatal(err)
}
}