Change MySQL UUID storage from unsupported type to VARCHAR(36)

This commit is contained in:
2024-09-25 21:20:55 +07:00
parent b89439ff1d
commit 5d7dc70f1b
3 changed files with 224 additions and 80 deletions

View File

@ -30,3 +30,44 @@ type Allowance struct {
AllowanceFile uint64 `gorm:"not null"`
User *User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;"`
}
type MysqlUser struct {
UserID string `gorm:"type:varchar(36);primaryKey"`
Username string `gorm:"type:varchar(255);unique;not null"`
Email string `gorm:"type:varchar(255);unique;not null"`
Password string `gorm:"type:text;not null"`
Totp string `gorm:"type:varchar(255);not null"`
}
func (MysqlUser) TableName() string {
return "users"
}
type MysqlFile struct {
ID string `gorm:"type:varchar(36);primaryKey"`
OwnerID string `gorm:"type:varchar(36);not null"`
Name string `gorm:"type:text;not null"`
Size uint64 `gorm:"not null"`
TotalChunk uint64 `gorm:"not null"`
StartHash string `gorm:"type:text;not null"`
EndHash string `gorm:"type:text;not null"`
IsPrivate bool `gorm:"not null;default:true"`
Type string `gorm:"type:varchar(5);not null;default:'doc'"`
Downloaded uint64 `gorm:"not null;default:0"`
Owner *MysqlUser `gorm:"foreignKey:OwnerID;constraint:OnDelete:CASCADE;"`
}
func (MysqlFile) TableName() string {
return "files"
}
type MysqlAllowance struct {
UserID string `gorm:"type:varchar(36);primaryKey"`
AllowanceByte uint64 `gorm:"not null"`
AllowanceFile uint64 `gorm:"not null"`
User *MysqlUser `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;"`
}
func (MysqlAllowance) TableName() string {
return "allowances"
}