mirror of
https://github.com/silicoflare/envy.git
synced 2026-05-26 19:57:59 +05:30
41 lines
730 B
Go
41 lines
730 B
Go
package utils
|
|
|
|
import (
|
|
"path"
|
|
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Project struct {
|
|
ID uint `gorm:"primaryKey"`
|
|
Name string
|
|
Environments []Environment
|
|
}
|
|
|
|
type Environment struct {
|
|
ID uint `gorm:"primaryKey"`
|
|
Name string
|
|
Data string
|
|
Active bool
|
|
ProjectID uint
|
|
Project Project `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
|
|
}
|
|
|
|
var DB *gorm.DB
|
|
|
|
func InitDb() {
|
|
var openErr error
|
|
DB, openErr = gorm.Open(sqlite.Open(path.Join(EnvyPath, "envy.db")), &gorm.Config{})
|
|
if openErr != nil {
|
|
ErrPrint("Error while opening database:" + openErr.Error())
|
|
}
|
|
}
|
|
|
|
func MigrateDb() {
|
|
err := DB.AutoMigrate(&Project{}, &Environment{})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|