This commit is contained in:
Tomas Dvorak
2026-03-13 14:34:19 +01:00
parent 84a8acf944
commit 30d70a6aeb
126 changed files with 27297 additions and 29069 deletions
+12 -84
View File
@@ -5,9 +5,11 @@ import (
"log"
"time"
_ "fotbal-club/database/goosemigrations"
"fotbal-club/internal/config"
"fotbal-club/internal/models"
"github.com/pressly/goose/v3"
"golang.org/x/crypto/bcrypt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
@@ -109,94 +111,20 @@ func WithTransaction(ctx context.Context, fn func(tx *gorm.DB) error) error {
// MigrateDB runs database migrations for all models
func MigrateDB(db *gorm.DB) error {
// Enable UUID extension
err := db.Exec(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`).Error
sqlDB, err := db.DB()
if err != nil {
return err
}
// Run migrations for all models
return db.AutoMigrate(
&models.User{},
&models.Article{},
&models.Category{},
&models.Team{},
&models.Player{},
&models.Sponsor{},
&models.Banner{},
&models.Settings{},
&models.MatchOverride{},
&models.TeamLogoOverride{},
&models.ContactMessage{},
&models.ContactCategory{},
&models.Contact{},
&models.NewsletterSubscription{},
&models.VisitorEvent{},
&models.ArticleTeamLink{},
&models.ArticleMatchLink{},
&models.CompetitionAlias{},
&models.EmailLog{},
&models.EmailEvent{},
&models.NewsletterSentLog{},
&models.MatchNotification{},
&models.BlogNotification{},
&models.PasswordReset{},
&models.AboutPage{},
// Add event tables so public endpoints don't fail before any writes occur
&models.Event{},
&models.EventAttachment{},
&models.UploadedFile{},
&models.FileUsage{},
&models.ShortLink{},
&models.LinkClick{},
&models.Comment{},
&models.CommentReaction{},
&models.CommentBan{},
&models.UnbanRequest{},
&models.CommentReport{},
&models.UserProfile{},
&models.PointsTransaction{},
&models.Achievement{},
&models.UserAchievement{},
&models.RewardItem{},
&models.RewardRedemption{},
// E-shop core models
&models.EshopProductCategory{},
&models.EshopProduct{},
&models.EshopProductVariant{},
&models.EshopCart{},
&models.EshopCartItem{},
&models.EshopOrder{},
&models.EshopOrderItem{},
&models.EshopPayment{},
&models.EshopShippingLabel{},
&models.EshopSettings{},
// Financial management models
&models.Budget{},
&models.Sponsorship{},
&models.SponsorshipPayment{},
&models.SponsorshipDocument{},
&models.Expense{},
&models.ExpenseDocument{},
&models.FinancialReport{},
&models.FinancialSettings{},
// Invoice system models
&models.Invoice{},
&models.InvoiceItem{},
&models.InvoicePayment{},
&models.InvoiceCustomer{},
&models.InvoiceTemplate{},
&models.InvoiceSettings{},
&models.InvoiceSequence{},
// Facility management models
&models.Facility{},
&models.FacilityAvailabilityRule{},
&models.FacilityBooking{},
&models.FacilityEquipment{},
&models.FacilityMaintenance{},
&models.WeatherCondition{},
&models.FacilityBookingTemplate{},
)
goose.SetLogger(log.New(log.Writer(), "[goose] ", log.LstdFlags))
if err := goose.SetDialect("postgres"); err != nil {
return err
}
if err := goose.UpContext(context.Background(), sqlDB, "database/goosemigrations"); err != nil {
return err
}
return nil
}
// SeedDB populates the database with initial data