blt/models/init.go

27 lines
460 B
Go
Raw Normal View History

2023-11-27 22:36:58 -05:00
package models
import (
"log"
"gorm.io/gorm"
"gorm.io/driver/sqlite"
)
var (
DB *gorm.DB
)
// Initializes the Gorm database object
func Open() {
2023-11-27 22:36:58 -05:00
// Initialize database object
var err error
DB, err = gorm.Open(sqlite.Open("data/blt.db"), &gorm.Config{})
2023-11-27 22:36:58 -05:00
if err != nil {
panic("Failed to connect database")
}
// Migrate the schema
2023-12-02 22:16:16 -05:00
DB.AutoMigrate(&Test{}, &Hardware{}, &Benchmark{})
2023-11-27 22:36:58 -05:00
log.Println("Database migrations complete.")
}