84 lines
3.4 KiB
Go
84 lines
3.4 KiB
Go
package host
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"dev.sum7.eu/sum7/warehost/system"
|
|
)
|
|
|
|
// Profil struct
|
|
type Profil struct {
|
|
ID int64
|
|
LoginID int64 `sql:"type:bigint NOT NULL UNIQUE REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"-"`
|
|
Login *system.Login `gorm:"foreignkey:Login;" json:"login"`
|
|
Reseller bool `sql:"default:false;column:reseller" json:"reseller"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Profil) TableName() string { return "host_profil" }
|
|
|
|
// Domain struct
|
|
type Domain struct {
|
|
ID int64
|
|
ProfilID int64 `sql:"type:bigint NOT NULL REFERENCES host_profil(id) ON UPDATE CASCADE ON DELETE CASCADE;column:profil" json:"-"`
|
|
Profil *Profil `gorm:"foreignkey:Profil;" json:"profil"`
|
|
FQDN string `sql:"type:varchar(255) NOT NULL UNIQUE;column:fqdn" json:"fqdn"`
|
|
Code string `sql:"type:varchar(255);column:code" json:"-"`
|
|
Active bool `sql:"default:false;column:active" json:"active"`
|
|
Mail bool `sql:"default:false;column:mail" json:"mail"`
|
|
Web bool `sql:"default:false;column:web" json:"web"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Domain) TableName() string { return "host_domain" }
|
|
|
|
// Web struct
|
|
type Web struct {
|
|
ID int64
|
|
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"-"`
|
|
Domain *Domain `gorm:"foreignkey:Domain;unique_index:idx_host_domain_web" json:"domain"`
|
|
Subdomain string `sql:"type:varchar(255);column:subdomain" gorm:"unique_index:idx_host_domain_web" json:"subdomain"`
|
|
PHP bool `sql:"default:false;column:php" json:"php"`
|
|
SSL bool `sql:"default:true;column:ssl" json:"ssl"`
|
|
SSLRedirect bool `sql:"default:false;column:sslredirect" json:"sslredirect"`
|
|
Redirect string `sql:"type:varchar(255);column:redirect" json:"redirect"`
|
|
Proxy string `sql:"type:varchar(255);column:proxy" json:"proxy"`
|
|
//FTP []int64 `sql:"type:bigint[];column:ftp" json:"ftp"`
|
|
//HTTPAccess []int64 `sql:"type:bigint[];column:httpaccess" json:"httpaccess"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Web) TableName() string { return "host_web" }
|
|
|
|
// Mail struct
|
|
type Mail struct {
|
|
ID int64
|
|
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"-"`
|
|
Domain *Domain `gorm:"foreignkey:Domain;unique_index:idx_host_domain_mail" json:"domain"`
|
|
Name string `sql:"type:varchar(255);column:name" gorm:"unique_index:idx_host_domain_mail" json:"name"`
|
|
//Forward []string `sql:"type:varchar(255)[];column:forward" json:"forward"`
|
|
LoginID sql.NullInt64 `sql:"type:bigint NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Mail) TableName() string { return "host_mail" }
|
|
|
|
// Database struct
|
|
type Database struct {
|
|
ID int64
|
|
ProfilID int64 `sql:"type:bigint NOT NULL REFERENCES host_profil(id) ON UPDATE CASCADE ON DELETE CASCADE;column:profil" json:"-"`
|
|
Profil *Profil `gorm:"foreignkey:Profil;" json:"profil"`
|
|
Password string `sql:"type:varchar(255);column:password" json:"password"`
|
|
Comment string `sql:"type:varchar(255);column:comment" json:"comment"`
|
|
}
|
|
|
|
// TableName of struct
|
|
func (Database) TableName() string { return "host_database" }
|
|
|
|
// SyncModels to verify the database schema
|
|
func SyncModels(dbconnection *gorm.DB) {
|
|
dbconnection.AutoMigrate(&Profil{}, &Domain{}, &Web{}, &Mail{}, &Database{})
|
|
}
|