Initial commit for AI Media Hub
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
33
backend/models/db.go
Normal file
33
backend/models/db.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
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
|
||||
log.Println("Connecting to SQLite at:", dbPath)
|
||||
DB, err = gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatal("Failed to connect to database:", err)
|
||||
}
|
||||
|
||||
err = DB.AutoMigrate(&MediaHistory{})
|
||||
if err != nil {
|
||||
log.Println("Database migration error:", err)
|
||||
}
|
||||
log.Println("Database initialized and migrated.")
|
||||
}
|
||||
Reference in New Issue
Block a user