fix: migration not applying on db

This commit is contained in:
2025-09-22 22:33:05 +05:30
parent 13702d117a
commit d150af5d10
4 changed files with 29 additions and 34 deletions

View File

@@ -1,10 +1,6 @@
package utils
import (
"fmt"
"os"
"path"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
@@ -26,19 +22,17 @@ type Environment struct {
var DB *gorm.DB
func Init() {
config, err := os.UserConfigDir()
if err != nil {
fmt.Println(ErrStyle.Render("Error accessing config directory:", err.Error()))
return
}
DB, err = gorm.Open(sqlite.Open(path.Join(config, "envy.db")), &gorm.Config{})
if err != nil {
ErrPrint("Error while opening database:" + err.Error())
func InitDb() {
var openErr error
DB, openErr = gorm.Open(sqlite.Open(EnvyPath), &gorm.Config{})
if openErr != nil {
ErrPrint("Error while opening database:" + openErr.Error())
}
}
func Migrate() {
DB.AutoMigrate(&Project{}, &Environment{})
func MigrateDb() {
err := DB.AutoMigrate(&Project{}, &Environment{})
if err != nil {
panic(err)
}
}