Initial commit: party-mix-app with prefetch cache, audio preload optimizations
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
39
apps/backend/internal/database/database.go
Normal file
39
apps/backend/internal/database/database.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/toyffee/party-mix/internal/config"
|
||||
"github.com/toyffee/party-mix/internal/models"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
func Connect(cfg *config.Config) *gorm.DB {
|
||||
dsn := fmt.Sprintf(
|
||||
"host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=UTC",
|
||||
cfg.DBHost, cfg.DBUser, cfg.DBPass, cfg.DBName, cfg.DBPort,
|
||||
)
|
||||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Warn),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("database connection failed: %v", err)
|
||||
}
|
||||
if err := db.AutoMigrate(
|
||||
&models.Party{},
|
||||
&models.Participant{},
|
||||
&models.Track{},
|
||||
&models.HistoryItem{},
|
||||
&models.User{},
|
||||
&models.Playlist{},
|
||||
&models.PlaylistTrack{},
|
||||
&models.UserVersion{},
|
||||
); err != nil {
|
||||
log.Fatalf("database migration failed: %v", err)
|
||||
}
|
||||
log.Println("Database connected and migrated")
|
||||
return db
|
||||
}
|
||||
Reference in New Issue
Block a user