51 lines
1.1 KiB
Go
Raw Normal View History

2025-02-22 12:50:26 +08:00
package main
import (
"log"
"os"
"legalgo-BE-go/config"
"legalgo-BE-go/database"
subscribeplandomain "legalgo-BE-go/internal/domain/subscribe_plan"
"github.com/google/uuid"
"github.com/joho/godotenv"
)
2025-02-22 12:50:26 +08:00
func main() {
// Check if the .env file exists
if _, err := os.Stat(".env"); err == nil {
// Load environment variables from .env file if it exists
if err := godotenv.Load(); err != nil {
log.Println("Error loading .env file, continuing without it")
}
} else {
log.Println(".env file not found, skipping load")
}
config.InitEnv()
db, err := database.NewDB()
if err != nil {
log.Fatalf("failed to connect to database: %v", err)
}
2025-03-02 04:36:17 +08:00
// db.DropTables()
if err := db.Migrate(); err != nil {
log.Fatal("Migration failed: ", err)
}
var temp subscribeplandomain.SubscribePlan
if err := db.Where("code = ?", "basic").First(&temp).Error; err != nil {
2025-02-27 10:27:57 +08:00
log.Print("seeding basic subscribe plan")
db.Create(&subscribeplandomain.SubscribePlan{
ID: uuid.NewString(),
Code: "basic",
Name: "Basic",
})
}
2025-02-22 16:15:38 +08:00
log.Print("migrate success")
2025-02-22 16:15:38 +08:00
}