Documentation ¶
Index ¶
- Variables
- func Create(ctx context.Context, s *Schema, tables []*schema.Table, ...) error
- func Diff(ctx context.Context, url string, opts ...schema.MigrateOption) error
- func NamedDiff(ctx context.Context, url, name string, opts ...schema.MigrateOption) error
- type Schema
- func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error
- func (s *Schema) Diff(ctx context.Context, opts ...schema.MigrateOption) error
- func (s *Schema) NamedDiff(ctx context.Context, name string, opts ...schema.MigrateOption) error
- func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error
Constants ¶
This section is empty.
Variables ¶
View Source
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 // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. WithForeignKeys = schema.WithForeignKeys )
View Source
var ( // LoadBalancersColumns holds the columns for the "load_balancers" table. LoadBalancersColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "name", Type: field.TypeString, Size: 2147483647}, {Name: "owner_id", Type: field.TypeString}, {Name: "location_id", Type: field.TypeString}, {Name: "provider_id", Type: field.TypeString}, } // LoadBalancersTable holds the schema information for the "load_balancers" table. LoadBalancersTable = &schema.Table{ Name: "load_balancers", Columns: LoadBalancersColumns, PrimaryKey: []*schema.Column{LoadBalancersColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "load_balancers_providers_provider", Columns: []*schema.Column{LoadBalancersColumns[6]}, RefColumns: []*schema.Column{ProvidersColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { Name: "loadbalancer_created_at", Unique: false, Columns: []*schema.Column{LoadBalancersColumns[1]}, }, { Name: "loadbalancer_updated_at", Unique: false, Columns: []*schema.Column{LoadBalancersColumns[2]}, }, { Name: "loadbalancer_provider_id", Unique: false, Columns: []*schema.Column{LoadBalancersColumns[6]}, }, { Name: "loadbalancer_location_id", Unique: false, Columns: []*schema.Column{LoadBalancersColumns[5]}, }, { Name: "loadbalancer_owner_id", Unique: false, Columns: []*schema.Column{LoadBalancersColumns[4]}, }, }, } // OriginsColumns holds the columns for the "origins" table. OriginsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "name", Type: field.TypeString}, {Name: "target", Type: field.TypeString}, {Name: "port_number", Type: field.TypeInt}, {Name: "active", Type: field.TypeBool, Default: true}, {Name: "pool_id", Type: field.TypeString}, } // OriginsTable holds the schema information for the "origins" table. OriginsTable = &schema.Table{ Name: "origins", Columns: OriginsColumns, PrimaryKey: []*schema.Column{OriginsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "origins_pools_pool", Columns: []*schema.Column{OriginsColumns[7]}, RefColumns: []*schema.Column{PoolsColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { Name: "origin_created_at", Unique: false, Columns: []*schema.Column{OriginsColumns[1]}, }, { Name: "origin_updated_at", Unique: false, Columns: []*schema.Column{OriginsColumns[2]}, }, { Name: "origin_pool_id", Unique: false, Columns: []*schema.Column{OriginsColumns[7]}, }, }, } // PoolsColumns holds the columns for the "pools" table. PoolsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "name", Type: field.TypeString}, {Name: "protocol", Type: field.TypeEnum, Enums: []string{"tcp", "udp"}}, {Name: "owner_id", Type: field.TypeString}, } // PoolsTable holds the schema information for the "pools" table. PoolsTable = &schema.Table{ Name: "pools", Columns: PoolsColumns, PrimaryKey: []*schema.Column{PoolsColumns[0]}, Indexes: []*schema.Index{ { Name: "pool_created_at", Unique: false, Columns: []*schema.Column{PoolsColumns[1]}, }, { Name: "pool_updated_at", Unique: false, Columns: []*schema.Column{PoolsColumns[2]}, }, { Name: "pool_owner_id", Unique: false, Columns: []*schema.Column{PoolsColumns[5]}, }, }, } // PortsColumns holds the columns for the "ports" table. PortsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "number", Type: field.TypeInt}, {Name: "name", Type: field.TypeString}, {Name: "load_balancer_id", Type: field.TypeString}, } // PortsTable holds the schema information for the "ports" table. PortsTable = &schema.Table{ Name: "ports", Columns: PortsColumns, PrimaryKey: []*schema.Column{PortsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "ports_load_balancers_load_balancer", Columns: []*schema.Column{PortsColumns[5]}, RefColumns: []*schema.Column{LoadBalancersColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { Name: "port_created_at", Unique: false, Columns: []*schema.Column{PortsColumns[1]}, }, { Name: "port_updated_at", Unique: false, Columns: []*schema.Column{PortsColumns[2]}, }, { Name: "port_load_balancer_id", Unique: false, Columns: []*schema.Column{PortsColumns[5]}, }, { Name: "port_load_balancer_id_number", Unique: true, Columns: []*schema.Column{PortsColumns[5], PortsColumns[3]}, }, }, } // ProvidersColumns holds the columns for the "providers" table. ProvidersColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "name", Type: field.TypeString}, {Name: "owner_id", Type: field.TypeString}, } // ProvidersTable holds the schema information for the "providers" table. ProvidersTable = &schema.Table{ Name: "providers", Columns: ProvidersColumns, PrimaryKey: []*schema.Column{ProvidersColumns[0]}, Indexes: []*schema.Index{ { Name: "provider_created_at", Unique: false, Columns: []*schema.Column{ProvidersColumns[1]}, }, { Name: "provider_updated_at", Unique: false, Columns: []*schema.Column{ProvidersColumns[2]}, }, { Name: "provider_owner_id", Unique: false, Columns: []*schema.Column{ProvidersColumns[4]}, }, }, } // PoolPortsColumns holds the columns for the "pool_ports" table. PoolPortsColumns = []*schema.Column{ {Name: "pool_id", Type: field.TypeString}, {Name: "port_id", Type: field.TypeString}, } // PoolPortsTable holds the schema information for the "pool_ports" table. PoolPortsTable = &schema.Table{ Name: "pool_ports", Columns: PoolPortsColumns, PrimaryKey: []*schema.Column{PoolPortsColumns[0], PoolPortsColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "pool_ports_pool_id", Columns: []*schema.Column{PoolPortsColumns[0]}, RefColumns: []*schema.Column{PoolsColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "pool_ports_port_id", Columns: []*schema.Column{PoolPortsColumns[1]}, RefColumns: []*schema.Column{PortsColumns[0]}, OnDelete: schema.Cascade, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ LoadBalancersTable, OriginsTable, PoolsTable, PortsTable, ProvidersTable, PoolPortsTable, } )
Functions ¶
func Create ¶
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error
Create creates all table resources using the given schema driver.
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is the API for creating, migrating and dropping a schema.
func (*Schema) Diff ¶
Diff creates a migration file containing the statements to resolve the diff between the Ent schema and the connected database.
func (*Schema) NamedDiff ¶
NamedDiff creates a named migration file containing the statements to resolve the diff between the Ent schema and the connected database.
Click to show internal directories.
Click to hide internal directories.