ent schema pre codegen

This commit is contained in:
2022-04-08 21:23:41 +02:00
parent e3904ae21c
commit d2a5f9bcac
8 changed files with 264 additions and 0 deletions

34
ent/schema/account.go Normal file
View File

@ -0,0 +1,34 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"time"
)
// Account holds the schema definition for the Account entity.
type Account struct {
ent.Schema
}
// Fields of the Account.
func (Account) Fields() []ent.Field {
return []ent.Field{
field.Int64("id"),
field.Time("created").Default(time.Now).Immutable(),
field.Time("modified").Default(time.Now).UpdateDefault(time.Now).Optional(),
field.String("username"),
field.Bytes("password"),
field.Bool("super"),
field.Bool("active"),
}
}
// Edges of the Account.
func (Account) Edges() []ent.Edge {
return []ent.Edge{
edge.To("domains", Domain.Type),
edge.To("logs", Logentry.Type),
}
}

33
ent/schema/alias.go Normal file
View File

@ -0,0 +1,33 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"time"
)
// Alias holds the schema definition for the Alias entity.
type Alias struct {
ent.Schema
}
// Fields of the Alias.
func (Alias) Fields() []ent.Field {
return []ent.Field{
field.Int64("id"),
field.Time("created").Default(time.Now).Immutable(),
field.Time("modified").Default(time.Now).UpdateDefault(time.Now).Nillable().Optional(),
field.Int64("domain_id").Optional(),
field.Text("goto"),
field.Bool("active"),
}
}
// Edges of the Alias.
func (Alias) Edges() []ent.Edge {
return []ent.Edge{
edge.From("domain", Domain.Type).Ref("aliases").Field("domain_id").Unique(),
}
}

46
ent/schema/domain.go Normal file
View File

@ -0,0 +1,46 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"time"
)
// Domain holds the schema definition for the Domain entity.
type Domain struct {
ent.Schema
}
// Fields of the Domain.
func (Domain) Fields() []ent.Field {
return []ent.Field{
field.Int64("id"),
field.Time("created").Default(time.Now).Immutable(),
field.Time("modified").Default(time.Now).UpdateDefault(time.Now).Nillable().Optional(),
field.String("domain"),
field.String("description").Nillable().Optional(),
field.Int64("max_aliases"),
field.Int64("max_mailboxes"),
field.Int64("max_quota"),
field.Int64("quota"),
field.String("transport"),
field.Bool("backup_mx"),
field.Bool("active"),
// field.String("homedir").Nillable().Optional(),
// field.String("maildir").Nillable().Optional(),
// field.Int32("uid").Nillable().Optional(),
// field.Int32("gid").Nillable().Optional(),
}
}
// Edges of the Domain.
func (Domain) Edges() []ent.Edge {
return []ent.Edge{
edge.To("mailboxes", Mailbox.Type),
edge.To("aliases", Alias.Type),
edge.To("logs", Logentry.Type),
edge.From("accounts", Account.Type).Ref("domains"),
}
}

33
ent/schema/logentry.go Normal file
View File

@ -0,0 +1,33 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"time"
)
// Logentry holds the schema definition for the Logentry entity.
type Logentry struct {
ent.Schema
}
// Fields of the Logentry.
func (Logentry) Fields() []ent.Field {
return []ent.Field{
field.Int64("id"),
field.Time("timestamp").Default(time.Now).Immutable(),
field.String("action"),
field.Text("data").Optional().Nillable(),
field.Int64("account_id"),
field.Int64("domain_id"),
}
}
// Edges of the Logentry.
func (Logentry) Edges() []ent.Edge {
return []ent.Edge{
edge.From("account", Account.Type).Ref("logs").Field("account_id").Unique(),
edge.From("domain", Domain.Type).Ref("logs").Field("domain_id").Unique(),
}
}

40
ent/schema/mailbox.go Normal file
View File

@ -0,0 +1,40 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"time"
)
// Mailbox holds the schema definition for the Mailbox entity.
type Mailbox struct {
ent.Schema
}
// Fields of the Mailbox.
func (Mailbox) Fields() []ent.Field {
return []ent.Field{
field.Int64("id"),
field.Bool("active"),
field.Time("created").Default(time.Now).Immutable(),
field.Time("modified").Default(time.Now).UpdateDefault(time.Now).Nillable().Optional(),
field.Int64("domain_id").Optional(),
field.String("username"),
field.Bytes("password"),
field.String("name").Nillable().Optional(),
field.Int64("quota"),
field.String("local_part"),
field.String("homedir").Nillable().Optional(),
field.String("maildir").Nillable().Optional(),
field.Int32("uid").Nillable().Optional(),
field.Int32("gid").Nillable().Optional(),
}
}
// Edges of the Mailbox.
func (Mailbox) Edges() []ent.Edge {
return []ent.Edge{
edge.From("domain", Domain.Type).Ref("mailboxes").Field("domain_id").Unique(),
}
}