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 ( // CreditEntriesColumns holds the columns for the "credit_entries" table. CreditEntriesColumns = []*schema.Column{ {Name: "id", Type: field.TypeOther, Unique: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "namespace", Type: field.TypeString}, {Name: "ledger_id", Type: field.TypeOther, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "entry_type", Type: field.TypeEnum, Enums: []string{"GRANT", "VOID_GRANT", "RESET"}}, {Name: "type", Type: field.TypeEnum, Nullable: true, Enums: []string{"USAGE"}}, {Name: "amount", Type: field.TypeFloat64, Nullable: true}, {Name: "priority", Type: field.TypeUint8, Default: 1}, {Name: "effective_at", Type: field.TypeTime}, {Name: "expiration_period_duration", Type: field.TypeEnum, Nullable: true, Enums: []string{"HOUR", "DAY", "WEEK", "MONTH", "YEAR"}}, {Name: "expiration_period_count", Type: field.TypeUint8, Nullable: true}, {Name: "expiration_at", Type: field.TypeTime, Nullable: true}, {Name: "rollover_type", Type: field.TypeEnum, Nullable: true, Enums: []string{"ORIGINAL_AMOUNT", "REMAINING_AMOUNT"}}, {Name: "rollover_max_amount", Type: field.TypeFloat64, Nullable: true}, {Name: "metadata", Type: field.TypeJSON, Nullable: true}, {Name: "parent_id", Type: field.TypeOther, Unique: true, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "feature_id", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, } // CreditEntriesTable holds the schema information for the "credit_entries" table. CreditEntriesTable = &schema.Table{ Name: "credit_entries", Columns: CreditEntriesColumns, PrimaryKey: []*schema.Column{CreditEntriesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "credit_entries_credit_entries_children", Columns: []*schema.Column{CreditEntriesColumns[16]}, RefColumns: []*schema.Column{CreditEntriesColumns[0]}, OnDelete: schema.Restrict, }, { Symbol: "credit_entries_features_credit_grants", Columns: []*schema.Column{CreditEntriesColumns[17]}, RefColumns: []*schema.Column{FeaturesColumns[0]}, OnDelete: schema.Restrict, }, }, Indexes: []*schema.Index{ { Name: "creditentry_namespace_ledger_id", Unique: false, Columns: []*schema.Column{CreditEntriesColumns[3], CreditEntriesColumns[4]}, }, }, } // FeaturesColumns holds the columns for the "features" table. FeaturesColumns = []*schema.Column{ {Name: "id", Type: field.TypeOther, Unique: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "namespace", Type: field.TypeString}, {Name: "name", Type: field.TypeString}, {Name: "meter_slug", Type: field.TypeString}, {Name: "meter_group_by_filters", Type: field.TypeJSON, Nullable: true}, {Name: "archived", Type: field.TypeBool, Default: false}, } // FeaturesTable holds the schema information for the "features" table. FeaturesTable = &schema.Table{ Name: "features", Columns: FeaturesColumns, PrimaryKey: []*schema.Column{FeaturesColumns[0]}, Indexes: []*schema.Index{ { Name: "feature_namespace_id", Unique: false, Columns: []*schema.Column{FeaturesColumns[3], FeaturesColumns[0]}, }, }, } // LedgersColumns holds the columns for the "ledgers" table. LedgersColumns = []*schema.Column{ {Name: "id", Type: field.TypeOther, Unique: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "namespace", Type: field.TypeString}, {Name: "subject", Type: field.TypeString}, {Name: "metadata", Type: field.TypeJSON, Nullable: true}, {Name: "highwatermark", Type: field.TypeTime}, } // LedgersTable holds the schema information for the "ledgers" table. LedgersTable = &schema.Table{ Name: "ledgers", Columns: LedgersColumns, PrimaryKey: []*schema.Column{LedgersColumns[0]}, Indexes: []*schema.Index{ { Name: "ledger_namespace_subject", Unique: true, Columns: []*schema.Column{LedgersColumns[3], LedgersColumns[4]}, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ CreditEntriesTable, FeaturesTable, LedgersTable, } )
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.