before svelte upgrade

This commit is contained in:
2025-02-07 13:33:43 +01:00
parent 57cf5e617a
commit 0501c11c49
17 changed files with 396 additions and 88 deletions

36
model/init.go Normal file
View File

@ -0,0 +1,36 @@
package model
import (
"log"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func InitDB() *gorm.DB {
db, err := gorm.Open(sqlite.Open("tournament.db"))
if err != nil {
log.Panic(err)
}
db.AutoMigrate(&Game{}, &Participant{}, &Tournament{}, &Match{})
db.Save(&Game{
Model: gorm.Model{
ID: 1,
},
Name: "CS:GO",
})
db.Save(&Game{
Model: gorm.Model{
ID: 2,
},
Name: "Overwatch",
})
db.Save(&Game{
Model: gorm.Model{
ID: 3,
},
Name: "Minecraft",
})
return db
}

44
model/model.go Normal file
View File

@ -0,0 +1,44 @@
package model
import (
"gorm.io/gorm"
)
type Game struct {
gorm.Model
Name string
}
type Participant struct {
gorm.Model
Name string
IsTemporary bool // only for one tournament
IsTeam bool
Tournaments []*Tournament `gorm:"many2many:partcipant_tournaments;"`
}
type Tournament struct {
gorm.Model
Title string
GameID int
Game Game `gorm:"foreignKey:GameID"`
Size int `json:"Size,string,omitempty"` // number of prarticipants
TournamentState int
WinnierParticipantID int
WinnierParticipant Participant `gorm:"foreignKey:WinnierParticipantID"`
Participants []*Participant `gorm:"many2many:partcipant_tournaments;"`
}
type Match struct {
gorm.Model
TournamentID int
Stage int
Order int
Participant1ID int
Participant1 Participant `gorm:"foreignKey:Participant1ID"`
Participant2ID int
Participant2 Participant `gorm:"foreignKey:Participant2ID"`
WinnierParticipantID int
WinnierParticipant Participant `gorm:"foreignKey:WinnierParticipantID"`
}