2023-11-27 22:36:58 -05:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"gorm.io/driver/sqlite"
|
|
|
|
)
|
|
|
|
|
2023-11-27 23:41:48 -05:00
|
|
|
var (
|
|
|
|
DB *gorm.DB
|
|
|
|
)
|
|
|
|
|
2023-11-28 14:40:12 -05:00
|
|
|
// Initializes the Gorm database object
|
|
|
|
func Open() {
|
2023-11-27 22:36:58 -05:00
|
|
|
// Initialize database object
|
2023-11-28 14:40:12 -05:00
|
|
|
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.")
|
|
|
|
}
|