shelfy/internal/db/db.go

50 lines
885 B
Go
Raw Normal View History

2025-06-06 07:42:55 +00:00
package db
import (
2025-06-09 14:13:32 +00:00
"app/shelfly/internal/debridlink"
2025-06-06 07:42:55 +00:00
"app/shelfly/internal/models"
2025-06-09 14:13:32 +00:00
"fmt"
2025-06-06 07:42:55 +00:00
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func InitDB()*gorm.DB {
dbName:="shelfly_db.db"
// Ouvre une connexion à la base de données
db, err := gorm.Open(sqlite.Open(dbName), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
// Migrate the schema
2025-06-09 14:13:32 +00:00
db.AutoMigrate(
&models.User{},
&models.Files{},
&models.LibrarySection{},
&models.MediaItem{},
&models.MediaPart{},
&models.MetadataItem{},
&models.SectionLocation{},
&models.Tag{},
&models.Tagging{},
&models.PathDownload{},
&debridlink.File{},
&debridlink.Link{},
&debridlink.RSSFeed{},
&debridlink.RSSItem{},
&debridlink.Torrent{},
&debridlink.DebridAccount{},
)
2025-06-06 07:42:55 +00:00
fmt.Println("Connexion réussie à MySQL !")
fmt.Println("Auto migration completed")
return db
}