Add: model/folder
This commit is contained in:
parent
ceb8ee72d8
commit
4c1ece4b96
3 changed files with 31 additions and 1 deletions
17
models/folder.go
Normal file
17
models/folder.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package model
|
||||
|
||||
import "github.com/jinzhu/gorm"
|
||||
|
||||
// Folder 目录
|
||||
type Folder struct {
|
||||
// 表字段
|
||||
gorm.Model
|
||||
Name string
|
||||
ParentID uint
|
||||
Position string `gorm:"size:65536"`
|
||||
OwnerID uint
|
||||
PositionAbsolute string `gorm:"size:65536"`
|
||||
|
||||
// 关联模型
|
||||
OptionsSerialized PolicyOption `gorm:"-"`
|
||||
}
|
|
@ -25,7 +25,7 @@ func migration() {
|
|||
util.Log().Info("开始进行数据库自动迁移...")
|
||||
|
||||
// 自动迁移模式
|
||||
DB.Set("gorm:table_options", "ENGINE=InnoDB").AutoMigrate(&User{}, &Setting{}, &Group{}, &Policy{})
|
||||
DB.Set("gorm:table_options", "ENGINE=InnoDB").AutoMigrate(&User{}, &Setting{}, &Group{}, &Policy{}, &Folder{})
|
||||
|
||||
// 创建初始存储策略
|
||||
addDefaultPolicy()
|
||||
|
|
|
@ -107,6 +107,19 @@ func (user *User) BeforeSave() (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
// AfterCreate 创建用户后的钩子
|
||||
func (user *User) AfterCreate(tx *gorm.DB) (err error) {
|
||||
// 创建用户的默认根目录
|
||||
defaultFolder := &Folder{
|
||||
Name: "根目录",
|
||||
Position: ".",
|
||||
OwnerID: user.ID,
|
||||
PositionAbsolute: "/",
|
||||
}
|
||||
tx.Create(defaultFolder)
|
||||
return err
|
||||
}
|
||||
|
||||
//SerializeOptions 将序列后的Option写入到数据库字段
|
||||
func (user *User) SerializeOptions() (err error) {
|
||||
optionsValue, err := json.Marshal(&user.OptionsSerialized)
|
||||
|
|
Loading…
Add table
Reference in a new issue