ent schema post generation
This commit is contained in:
71
ent/migrate/migrate.go
Normal file
71
ent/migrate/migrate.go
Normal file
@ -0,0 +1,71 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||
// for the ids of each entity (table).
|
||||
// Note that this option cannot be applied on tables that already exist.
|
||||
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||
// WithDropColumn sets the drop column option to the migration.
|
||||
// If this option is enabled, ent migration will drop old columns
|
||||
// that were used for both fields and edges. This defaults to false.
|
||||
WithDropColumn = schema.WithDropColumn
|
||||
// WithDropIndex sets the drop index option to the migration.
|
||||
// If this option is enabled, ent migration will drop old indexes
|
||||
// that were defined in the schema. This defaults to false.
|
||||
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||
// and therefore, it's recommended to enable this option to get more
|
||||
// flexibility in the schema changes.
|
||||
WithDropIndex = schema.WithDropIndex
|
||||
// WithFixture sets the foreign-key renaming option to the migration when upgrading
|
||||
// ent from v0.1.0 (issue-#285). Defaults to false.
|
||||
WithFixture = schema.WithFixture
|
||||
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||
WithForeignKeys = schema.WithForeignKeys
|
||||
)
|
||||
|
||||
// Schema is the API for creating, migrating and dropping a schema.
|
||||
type Schema struct {
|
||||
drv dialect.Driver
|
||||
}
|
||||
|
||||
// NewSchema creates a new schema client.
|
||||
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||
|
||||
// Create creates all schema resources.
|
||||
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %w", err)
|
||||
}
|
||||
return migrate.Create(ctx, Tables...)
|
||||
}
|
||||
|
||||
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||
//
|
||||
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
//
|
||||
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||
drv := &schema.WriteDriver{
|
||||
Writer: w,
|
||||
Driver: s.drv,
|
||||
}
|
||||
migrate, err := schema.NewMigrate(drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %w", err)
|
||||
}
|
||||
return migrate.Create(ctx, Tables...)
|
||||
}
|
174
ent/migrate/schema.go
Normal file
174
ent/migrate/schema.go
Normal file
@ -0,0 +1,174 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// AccountsColumns holds the columns for the "accounts" table.
|
||||
AccountsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "created", Type: field.TypeTime},
|
||||
{Name: "modified", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "username", Type: field.TypeString},
|
||||
{Name: "password", Type: field.TypeBytes},
|
||||
{Name: "super", Type: field.TypeBool},
|
||||
{Name: "active", Type: field.TypeBool},
|
||||
}
|
||||
// AccountsTable holds the schema information for the "accounts" table.
|
||||
AccountsTable = &schema.Table{
|
||||
Name: "accounts",
|
||||
Columns: AccountsColumns,
|
||||
PrimaryKey: []*schema.Column{AccountsColumns[0]},
|
||||
}
|
||||
// AliasColumns holds the columns for the "alias" table.
|
||||
AliasColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "created", Type: field.TypeTime},
|
||||
{Name: "modified", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "goto", Type: field.TypeString, Size: 2147483647},
|
||||
{Name: "active", Type: field.TypeBool},
|
||||
{Name: "domain_id", Type: field.TypeInt64, Nullable: true},
|
||||
}
|
||||
// AliasTable holds the schema information for the "alias" table.
|
||||
AliasTable = &schema.Table{
|
||||
Name: "alias",
|
||||
Columns: AliasColumns,
|
||||
PrimaryKey: []*schema.Column{AliasColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "alias_domains_aliases",
|
||||
Columns: []*schema.Column{AliasColumns[5]},
|
||||
RefColumns: []*schema.Column{DomainsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// DomainsColumns holds the columns for the "domains" table.
|
||||
DomainsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "created", Type: field.TypeTime},
|
||||
{Name: "modified", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "domain", Type: field.TypeString},
|
||||
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||
{Name: "max_aliases", Type: field.TypeInt64},
|
||||
{Name: "max_mailboxes", Type: field.TypeInt64},
|
||||
{Name: "max_quota", Type: field.TypeInt64},
|
||||
{Name: "quota", Type: field.TypeInt64},
|
||||
{Name: "transport", Type: field.TypeString},
|
||||
{Name: "backup_mx", Type: field.TypeBool},
|
||||
{Name: "active", Type: field.TypeBool},
|
||||
}
|
||||
// DomainsTable holds the schema information for the "domains" table.
|
||||
DomainsTable = &schema.Table{
|
||||
Name: "domains",
|
||||
Columns: DomainsColumns,
|
||||
PrimaryKey: []*schema.Column{DomainsColumns[0]},
|
||||
}
|
||||
// LogentriesColumns holds the columns for the "logentries" table.
|
||||
LogentriesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "timestamp", Type: field.TypeTime},
|
||||
{Name: "action", Type: field.TypeString},
|
||||
{Name: "data", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||
{Name: "account_id", Type: field.TypeInt64, Nullable: true},
|
||||
{Name: "domain_id", Type: field.TypeInt64, Nullable: true},
|
||||
}
|
||||
// LogentriesTable holds the schema information for the "logentries" table.
|
||||
LogentriesTable = &schema.Table{
|
||||
Name: "logentries",
|
||||
Columns: LogentriesColumns,
|
||||
PrimaryKey: []*schema.Column{LogentriesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "logentries_accounts_logs",
|
||||
Columns: []*schema.Column{LogentriesColumns[4]},
|
||||
RefColumns: []*schema.Column{AccountsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "logentries_domains_logs",
|
||||
Columns: []*schema.Column{LogentriesColumns[5]},
|
||||
RefColumns: []*schema.Column{DomainsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// MailboxesColumns holds the columns for the "mailboxes" table.
|
||||
MailboxesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "active", Type: field.TypeBool},
|
||||
{Name: "created", Type: field.TypeTime},
|
||||
{Name: "modified", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "username", Type: field.TypeString},
|
||||
{Name: "password", Type: field.TypeBytes},
|
||||
{Name: "name", Type: field.TypeString, Nullable: true},
|
||||
{Name: "quota", Type: field.TypeInt64},
|
||||
{Name: "local_part", Type: field.TypeString},
|
||||
{Name: "homedir", Type: field.TypeString, Nullable: true},
|
||||
{Name: "maildir", Type: field.TypeString, Nullable: true},
|
||||
{Name: "uid", Type: field.TypeInt32, Nullable: true},
|
||||
{Name: "gid", Type: field.TypeInt32, Nullable: true},
|
||||
{Name: "domain_id", Type: field.TypeInt64, Nullable: true},
|
||||
}
|
||||
// MailboxesTable holds the schema information for the "mailboxes" table.
|
||||
MailboxesTable = &schema.Table{
|
||||
Name: "mailboxes",
|
||||
Columns: MailboxesColumns,
|
||||
PrimaryKey: []*schema.Column{MailboxesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "mailboxes_domains_mailboxes",
|
||||
Columns: []*schema.Column{MailboxesColumns[13]},
|
||||
RefColumns: []*schema.Column{DomainsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// AccountDomainsColumns holds the columns for the "account_domains" table.
|
||||
AccountDomainsColumns = []*schema.Column{
|
||||
{Name: "account_id", Type: field.TypeInt64},
|
||||
{Name: "domain_id", Type: field.TypeInt64},
|
||||
}
|
||||
// AccountDomainsTable holds the schema information for the "account_domains" table.
|
||||
AccountDomainsTable = &schema.Table{
|
||||
Name: "account_domains",
|
||||
Columns: AccountDomainsColumns,
|
||||
PrimaryKey: []*schema.Column{AccountDomainsColumns[0], AccountDomainsColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "account_domains_account_id",
|
||||
Columns: []*schema.Column{AccountDomainsColumns[0]},
|
||||
RefColumns: []*schema.Column{AccountsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "account_domains_domain_id",
|
||||
Columns: []*schema.Column{AccountDomainsColumns[1]},
|
||||
RefColumns: []*schema.Column{DomainsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
AccountsTable,
|
||||
AliasTable,
|
||||
DomainsTable,
|
||||
LogentriesTable,
|
||||
MailboxesTable,
|
||||
AccountDomainsTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
AliasTable.ForeignKeys[0].RefTable = DomainsTable
|
||||
LogentriesTable.ForeignKeys[0].RefTable = AccountsTable
|
||||
LogentriesTable.ForeignKeys[1].RefTable = DomainsTable
|
||||
MailboxesTable.ForeignKeys[0].RefTable = DomainsTable
|
||||
AccountDomainsTable.ForeignKeys[0].RefTable = AccountsTable
|
||||
AccountDomainsTable.ForeignKeys[1].RefTable = DomainsTable
|
||||
}
|
Reference in New Issue
Block a user