Documentation ¶
Index ¶
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 ( // FoodsColumns holds the columns for the "foods" table. FoodsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "key", Type: field.TypeString, Unique: true}, {Name: "name", Type: field.TypeString}, {Name: "brand", Type: field.TypeString, Nullable: true}, {Name: "cal100", Type: field.TypeFloat64}, {Name: "prot100", Type: field.TypeFloat64}, {Name: "fat100", Type: field.TypeFloat64}, {Name: "carb100", Type: field.TypeFloat64}, {Name: "comment", Type: field.TypeString, Nullable: true}, } // FoodsTable holds the schema information for the "foods" table. FoodsTable = &schema.Table{ Name: "foods", Columns: FoodsColumns, PrimaryKey: []*schema.Column{FoodsColumns[0]}, } // JournalsColumns holds the columns for the "journals" table. JournalsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "userid", Type: field.TypeInt64}, {Name: "timestamp", Type: field.TypeTime}, {Name: "meal", Type: field.TypeInt64}, {Name: "foodweight", Type: field.TypeFloat64}, {Name: "food_journals", Type: field.TypeInt}, } // JournalsTable holds the schema information for the "journals" table. JournalsTable = &schema.Table{ Name: "journals", Columns: JournalsColumns, PrimaryKey: []*schema.Column{JournalsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "journals_foods_journals", Columns: []*schema.Column{JournalsColumns[5]}, RefColumns: []*schema.Column{FoodsColumns[0]}, OnDelete: schema.Restrict, }, }, Indexes: []*schema.Index{ { Name: "journal_userid_timestamp_meal_food_journals", Unique: true, Columns: []*schema.Column{JournalsColumns[1], JournalsColumns[2], JournalsColumns[3], JournalsColumns[5]}, }, }, } // UserSettingsColumns holds the columns for the "user_settings" table. UserSettingsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "userid", Type: field.TypeInt64, Unique: true}, {Name: "cal_limit", Type: field.TypeFloat64}, } // UserSettingsTable holds the schema information for the "user_settings" table. UserSettingsTable = &schema.Table{ Name: "user_settings", Columns: UserSettingsColumns, PrimaryKey: []*schema.Column{UserSettingsColumns[0]}, } // WeightsColumns holds the columns for the "weights" table. WeightsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "userid", Type: field.TypeInt64}, {Name: "timestamp", Type: field.TypeTime}, {Name: "value", Type: field.TypeFloat64}, } // WeightsTable holds the schema information for the "weights" table. WeightsTable = &schema.Table{ Name: "weights", Columns: WeightsColumns, PrimaryKey: []*schema.Column{WeightsColumns[0]}, Indexes: []*schema.Index{ { Name: "weight_userid_timestamp", Unique: true, Columns: []*schema.Column{WeightsColumns[1], WeightsColumns[2]}, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ FoodsTable, JournalsTable, UserSettingsTable, WeightsTable, } )
Functions ¶
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is the API for creating, migrating and dropping a schema.
Click to show internal directories.
Click to hide internal directories.