Rename ISPmail models to use Virtual* prefix
- Domain -> VirtualDomain - User -> VirtualUser - Alias -> VirtualAlias This clarifies which tables are ISPmail tables vs IMC tables.
This commit is contained in:
parent
93922e4cad
commit
d5880d5096
8 changed files with 87 additions and 96 deletions
|
|
@ -28,46 +28,46 @@ type DB struct {
|
|||
// These tables are shared with the ISPmail system and must not be modified.
|
||||
// =============================================================================
|
||||
|
||||
// Domain represents a mail domain (e.g., "example.org").
|
||||
// VirtualDomain represents a mail domain (e.g., "example.org").
|
||||
// This corresponds to the existing ISPmail virtual_domains table.
|
||||
type Domain struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"` // Primary key, auto-increment
|
||||
Name string `gorm:"uniqueIndex;size:50;not null" json:"name"` // Domain name, must be unique
|
||||
CreatedAt time.Time `json:"createdAt"` // When the domain was added
|
||||
Users []User `gorm:"foreignKey:DomainID" json:"users,omitempty"` // Mail users in this domain
|
||||
Aliases []Alias `gorm:"foreignKey:DomainID" json:"aliases,omitempty"` // Aliases in this domain
|
||||
type VirtualDomain struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"` // Primary key, auto-increment
|
||||
Name string `gorm:"uniqueIndex;size:50;not null" json:"name"` // Domain name, must be unique
|
||||
CreatedAt time.Time `json:"createdAt"` // When the domain was added
|
||||
Users []VirtualUser `gorm:"foreignKey:DomainID" json:"users,omitempty"` // Mail users in this domain
|
||||
Aliases []VirtualAlias `gorm:"foreignKey:DomainID" json:"aliases,omitempty"` // Aliases in this domain
|
||||
}
|
||||
|
||||
// TableName tells GORM to use the existing ISPmail table name.
|
||||
func (Domain) TableName() string { return "virtual_domains" }
|
||||
func (VirtualDomain) TableName() string { return "virtual_domains" }
|
||||
|
||||
// User represents a mail user (e.g., "user@example.org").
|
||||
// VirtualUser represents a mail user (e.g., "user@example.org").
|
||||
// This corresponds to the existing ISPmail virtual_users table.
|
||||
type User struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"` // Primary key
|
||||
DomainID uint `gorm:"not null" json:"domainId"` // Foreign key to Domain
|
||||
Email string `gorm:"uniqueIndex;size:100;not null" json:"email"` // Full email address, must be unique
|
||||
Password string `gorm:"size:150;not null" json:"-"` // Mailbox password (bcrypt hash, - means exclude from JSON)
|
||||
Quota int64 `gorm:"default:0" json:"quota"` // Mailbox size limit in bytes (0 = default)
|
||||
Domain *Domain `gorm:"foreignKey:DomainID" json:"domain,omitempty"` // Associated domain
|
||||
type VirtualUser struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"` // Primary key
|
||||
DomainID uint `gorm:"not null" json:"domainId"` // Foreign key to VirtualDomain
|
||||
Email string `gorm:"uniqueIndex;size:100;not null" json:"email"` // Full email address, must be unique
|
||||
Password string `gorm:"size:150;not null" json:"-"` // Mailbox password (bcrypt hash, - means exclude from JSON)
|
||||
Quota int64 `gorm:"default:0" json:"quota"` // Mailbox size limit in bytes (0 = default)
|
||||
Domain *VirtualDomain `gorm:"foreignKey:DomainID" json:"domain,omitempty"` // Associated domain
|
||||
}
|
||||
|
||||
// TableName tells GORM to use the existing ISPmail table name.
|
||||
func (User) TableName() string { return "virtual_users" }
|
||||
func (VirtualUser) TableName() string { return "virtual_users" }
|
||||
|
||||
// Alias represents an email alias/forwarding rule.
|
||||
// VirtualAlias represents an email alias/forwarding rule.
|
||||
// Maps one email address (source) to another (destination).
|
||||
// This corresponds to the existing ISPmail virtual_aliases table.
|
||||
type Alias struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"` // Primary key
|
||||
DomainID uint `gorm:"not null" json:"domainId"` // Foreign key to Domain
|
||||
Source string `gorm:"size:100;not null" json:"source"` // Original email address (alias)
|
||||
Destination string `gorm:"size:100;not null" json:"destination"` // Forward-to email address
|
||||
Domain *Domain `gorm:"foreignKey:DomainID" json:"domain,omitempty"` // Associated domain
|
||||
type VirtualAlias struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"` // Primary key
|
||||
DomainID uint `gorm:"not null" json:"domainId"` // Foreign key to VirtualDomain
|
||||
Source string `gorm:"size:100;not null" json:"source"` // Original email address (alias)
|
||||
Destination string `gorm:"size:100;not null" json:"destination"` // Forward-to email address
|
||||
Domain *VirtualDomain `gorm:"foreignKey:DomainID" json:"domain,omitempty"` // Associated domain
|
||||
}
|
||||
|
||||
// TableName tells GORM to use the existing ISPmail table name.
|
||||
func (Alias) TableName() string { return "virtual_aliases" }
|
||||
func (VirtualAlias) TableName() string { return "virtual_aliases" }
|
||||
|
||||
// =============================================================================
|
||||
// IMC Application Models (tables created by this app)
|
||||
|
|
@ -90,11 +90,11 @@ func (ImcUser) TableName() string { return "imc_users" }
|
|||
// ImcUserDomain represents the many-to-many relationship between admin users and domains.
|
||||
// An admin user can have access to multiple domains, and a domain can be accessed by multiple users.
|
||||
type ImcUserDomain struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"` // Primary key
|
||||
UserID uint `gorm:"not null" json:"userId"` // Foreign key to ImcUser
|
||||
DomainID uint `gorm:"not null" json:"domainId"` // Foreign key to Domain
|
||||
CreatedAt time.Time `json:"createdAt"` // When access was granted
|
||||
Domain *Domain `gorm:"foreignKey:DomainID" json:"domain,omitempty"` // Associated domain (for preloading)
|
||||
ID uint `gorm:"primaryKey" json:"id"` // Primary key
|
||||
UserID uint `gorm:"not null" json:"userId"` // Foreign key to ImcUser
|
||||
DomainID uint `gorm:"not null" json:"domainId"` // Foreign key to VirtualDomain
|
||||
CreatedAt time.Time `json:"createdAt"` // When access was granted
|
||||
Domain *VirtualDomain `gorm:"foreignKey:DomainID" json:"domain,omitempty"` // Associated domain (for preloading)
|
||||
}
|
||||
|
||||
// TableName specifies the database table name for ImcUserDomain.
|
||||
|
|
@ -128,14 +128,14 @@ type DomainStats struct {
|
|||
|
||||
// AliasWithDomain combines an alias with its domain name for API responses.
|
||||
type AliasWithDomain struct {
|
||||
Alias // Embed Alias struct
|
||||
DomainName string `json:"domainName"` // Denormalized domain name for convenience
|
||||
VirtualAlias // Embed VirtualAlias struct
|
||||
DomainName string `json:"domainName"` // Denormalized domain name for convenience
|
||||
}
|
||||
|
||||
// UserWithDomain combines a user with their domain name for API responses.
|
||||
type UserWithDomain struct {
|
||||
User // Embed User struct
|
||||
DomainName string `json:"domainName"` // Denormalized domain name for convenience
|
||||
VirtualUser // Embed VirtualUser struct
|
||||
DomainName string `json:"domainName"` // Denormalized domain name for convenience
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue