초기화

This commit is contained in:
AI Assistant
2026-03-12 14:53:20 +09:00
parent 2dab67dcc6
commit b162536254
18 changed files with 0 additions and 1556 deletions

View File

@@ -1,50 +0,0 @@
package models
import (
"log"
"os"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
var DB *gorm.DB
type MediaHistory struct {
gorm.Model
SourceURL string `gorm:"uniqueIndex"`
FilePath string
Status string
Type string // ENUM: "download", "upload"
}
func InitDB(dbPath string) {
var err error
// 도커 로그 디버깅을 위해 SQL 쿼리를 디테일하게 출력하는 로거 설정
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags),
logger.Config{
LogLevel: logger.Info,
Colorful: true,
},
)
log.Println("Connecting to SQLite at:", dbPath)
DB, err = gorm.Open(sqlite.Open(dbPath), &gorm.Config{
Logger: newLogger,
})
if err != nil {
log.Fatal("Failed to connect to database:", err)
}
// SQLite 동시성 최적화를 위해 WAL(Write-Ahead Logging) 모드를 활성화
DB.Exec("PRAGMA journal_mode=WAL;")
err = DB.AutoMigrate(&MediaHistory{})
if err != nil {
log.Println("Database migration error:", err)
}
log.Println("Database initialized and migrated.")
}