package db import ( "fmt" "git.freecumextremist.com/grumbulon/pomme/internal" "github.com/glebarez/sqlite" "gorm.io/gorm" ) // InitDb is the init function for the database. func InitDb(path string) (db *gorm.DB, err error, ok bool) { ok = true db, err = gorm.Open(sqlite.Open(path), &gorm.Config{}) if err != nil { return db, fmt.Errorf("failed to connect database: %w", err), !ok } // Migrate the schema err = db.AutoMigrate(&internal.User{}, &internal.ZoneRequest{}) if err != nil { return &gorm.DB{}, fmt.Errorf("failed to run DB migration: %w", err), !ok } return db, nil, ok }