diff --git a/internal/photos/api/db.go b/internal/photos/api/db.go index d2d926a..16686af 100644 --- a/internal/photos/api/db.go +++ b/internal/photos/api/db.go @@ -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() { diff --git a/internal/photos/models/album.go b/internal/photos/models/album.go new file mode 100644 index 0000000..d3f8d5a --- /dev/null +++ b/internal/photos/models/album.go @@ -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 +} diff --git a/internal/photos/models/photo.go b/internal/photos/models/photo.go index d74b6b0..20bf699 100644 --- a/internal/photos/models/photo.go +++ b/internal/photos/models/photo.go @@ -1,6 +1,15 @@ package models +import "time" + type Photo struct { - ID uint32 `gorm:"primary_key"` - File string + ID uint32 `gorm:"primary_key"` + 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 }