create photo and album

This commit is contained in:
celogeek 2022-02-05 21:48:34 +01:00
parent 45683cbc0d
commit 51a40f294b
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
3 changed files with 26 additions and 2 deletions

View File

@ -12,6 +12,8 @@ func (s *Service) Migrate() {
tx := s.DB.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")
tx.AutoMigrate(&models.Account{})
tx.AutoMigrate(&models.Session{})
tx.AutoMigrate(&models.Album{})
tx.AutoMigrate(&models.Photo{})
}
func (s *Service) DBConfig() {

View File

@ -0,0 +1,13 @@
package models
import "time"
type Album struct {
ID uint32 `gorm:"primary_key"`
Name string `gorm:"not null"`
Parent *Album `gorm:"constraint:OnDelete:SET NULL,OnUpdate:CASCADE"`
ParentId uint32
Photos []*Photo `gorm:"many2many:album_photos"`
CreatedAt time.Time
UpdatedAt time.Time
}

View File

@ -1,6 +1,15 @@
package models
import "time"
type Photo struct {
ID uint32 `gorm:"primary_key"`
File string
File string `gorm:"not null"`
Name string `gorm:"not null"`
Checksum string `gorm:"unique;size:44;not null"`
Account *Account `gorm:"constraint:OnDelete:SET NULL,OnUpdate:CASCADE"`
AccountId uint32
Albums []*Album `gorm:"many2many:album_photos"`
CreatedAt time.Time
UpdatedAt time.Time
}