This commit is contained in:
2025-11-03 12:24:01 +02:00
commit 0806865287
177 changed files with 18453 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package scripts
import (
"fmt"
"log"
"go-server/internal/config"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
// Define models for migration
type User struct {
ID uint `gorm:"primaryKey"`
Email string `gorm:"uniqueIndex"`
Password string
}
// Migrate function to run database migrations
func Migrate() {
// Load from environment variables or configuration
cfg, err := config.LoadConfig()
if err != nil {
panic(err)
}
dsn := cfg.Database.DSN()
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
// AutoMigrate runs the migration
err = db.AutoMigrate(&User{})
if err != nil {
log.Fatalf("Migration failed: %v", err)
}
fmt.Println("Migration completed successfully!")
}