Added models; started working on project routes
This commit is contained in:
12
models/benchmark.go
Normal file
12
models/benchmark.go
Normal file
@ -0,0 +1,12 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Benchmark struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
ScoringType string
|
||||
Description string
|
||||
}
|
13
models/hardware.go
Normal file
13
models/hardware.go
Normal file
@ -0,0 +1,13 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Hardware struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
Type string
|
||||
SerialNumber string
|
||||
Description string
|
||||
}
|
@ -7,14 +7,18 @@ import (
|
||||
"gorm.io/driver/sqlite"
|
||||
)
|
||||
|
||||
var (
|
||||
DB *gorm.DB
|
||||
)
|
||||
|
||||
func InitDatabase() {
|
||||
// Initialize database object
|
||||
db, err := gorm.Open(sqlite.Open("data/blt.db"), &gorm.Config{})
|
||||
DB, err := gorm.Open(sqlite.Open("data/blt.db"), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("Failed to connect database")
|
||||
}
|
||||
|
||||
// Migrate the schema
|
||||
db.AutoMigrate(&Project{})
|
||||
DB.AutoMigrate(&Project{}, &Hardware{}, &Benchmark{})
|
||||
log.Println("Database migrations complete.")
|
||||
}
|
||||
|
Reference in New Issue
Block a user