go-backend-starter-project/migrate/migration.go

27 lines
414 B
Go
Raw Normal View History

2024-02-15 00:36:17 +01:00
package main
import (
"go-backend-starter-project/initializers"
"go-backend-starter-project/models"
"log"
)
func init() {
initializers.LoadEnv()
initializers.ConnectToDB()
}
func main() {
log.Println("Migrating models to DB...")
err := initializers.DB.AutoMigrate(
&models.User{},
)
if err != nil {
log.Fatalf("Automatic migration has failed: %v", err)
}
log.Println("Migration sucessful!")
}