76 lines
2.7 KiB
Go
76 lines
2.7 KiB
Go
package web
|
|
|
|
import (
|
|
"database/sql"
|
|
"github.com/jinzhu/gorm"
|
|
//system "dev.sum7.de/sum7/warehost/system"
|
|
)
|
|
|
|
// Website struct
|
|
type Website struct {
|
|
ID int64
|
|
Name string `gorm:"type:varchar(255);column:name" json:"name"`
|
|
Domains []Domain `gorm:"foreignkey:Domain" json:"domains"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Website) TableName() string { return "web_website" }
|
|
|
|
// Domain struct
|
|
type Domain struct {
|
|
WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website;primary_key"`
|
|
Name string `gorm:"type:varchar(255);unique;column:name" json:"name"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Domain) TableName() string { return "web_domain" }
|
|
|
|
// Manager struct
|
|
type Manager struct {
|
|
LoginID int64 `sql:"type:bigint REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login;primary_key" json:"login"`
|
|
WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website;primary_key" json:"-"`
|
|
Website Website `gorm:"foreignkey:Website" json:"website"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Manager) TableName() string { return "web_manager" }
|
|
|
|
// Media struct
|
|
type Media struct {
|
|
WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website;primary_key"`
|
|
Path string `gorm:"type:varchar(255);column:path;primary_key" json:"path"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Media) TableName() string { return "web_media" }
|
|
|
|
// Menu struct
|
|
type Menu struct {
|
|
ID int64 `gorm:"primary_key"`
|
|
WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website"`
|
|
Name string `gorm:"type:varchar(255);column:name" json:"name"`
|
|
Shorturl string `gorm:"type:varchar(255);column:url" json:"url"`
|
|
ParentID sql.NullInt64 `sql:"type:bigint REFERENCES web_menu(id) ON UPDATE SET NULL ON DELETE SET NULL;column:menu"`
|
|
Menu []*Menu `gorm:"foreignkey:Menu" json:"menu"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Menu) TableName() string { return "web_menu" }
|
|
|
|
// Page struct
|
|
type Page struct {
|
|
ID int64 `gorm:"primary_key"`
|
|
WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website"`
|
|
MenuID int64 `sql:"type:bigint REFERENCES web_menu(id) ON UPDATE CASCADE ON DELETE CASCADE;column:menu"`
|
|
Title string `gorm:"type:varchar(255);column:title" json:"title"`
|
|
Content string `gorm:"type:text;column:content" json:"content"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Page) TableName() string { return "web_page" }
|
|
|
|
// SyncModels to verify the database schema
|
|
func SyncModels(dbconnection *gorm.DB) {
|
|
dbconnection.AutoMigrate(&Website{}, &Domain{}, &Manager{}, &Media{}, &Menu{}, &Page{})
|
|
}
|