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 ( // RidesColumns holds the columns for the "rides" table. RidesColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "city", Type: field.TypeString}, {Name: "vehicle_city", Type: field.TypeString, Nullable: true}, {Name: "start_address", Type: field.TypeString, Nullable: true}, {Name: "end_address", Type: field.TypeString, Nullable: true}, {Name: "start_time", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "TIMESTAMP"}}, {Name: "end_time", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "TIMESTAMP"}}, {Name: "revenue", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(10,2)"}}, {Name: "rider_id", Type: field.TypeUUID, Nullable: true}, {Name: "vehicle_id", Type: field.TypeUUID, Nullable: true}, } // RidesTable holds the schema information for the "rides" table. RidesTable = &schema.Table{ Name: "rides", Columns: RidesColumns, PrimaryKey: []*schema.Column{RidesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "rides_users_user", Columns: []*schema.Column{RidesColumns[8]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "rides_vehicles_vehicle", Columns: []*schema.Column{RidesColumns[9]}, RefColumns: []*schema.Column{VehiclesColumns[0]}, OnDelete: schema.SetNull, }, }, Indexes: []*schema.Index{ { Name: "ride_city_id", Unique: false, Columns: []*schema.Column{RidesColumns[1], RidesColumns[0]}, }, }, } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "city", Type: field.TypeString}, {Name: "name", Type: field.TypeString, Nullable: true}, {Name: "address", Type: field.TypeString, Nullable: true}, {Name: "credit_card", Type: field.TypeString, Nullable: true}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ Name: "users", Columns: UsersColumns, PrimaryKey: []*schema.Column{UsersColumns[0]}, Indexes: []*schema.Index{ { Name: "user_city_id", Unique: false, Columns: []*schema.Column{UsersColumns[1], UsersColumns[0]}, }, }, } // UserPromoCodesColumns holds the columns for the "user_promo_codes" table. UserPromoCodesColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "city", Type: field.TypeString}, {Name: "code", Type: field.TypeString}, {Name: "timestamp", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "TIMESTAMP"}}, {Name: "usage_count", Type: field.TypeInt, Nullable: true}, {Name: "user_id", Type: field.TypeUUID}, } // UserPromoCodesTable holds the schema information for the "user_promo_codes" table. UserPromoCodesTable = &schema.Table{ Name: "user_promo_codes", Columns: UserPromoCodesColumns, PrimaryKey: []*schema.Column{UserPromoCodesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "user_promo_codes_users_user_promo_codes", Columns: []*schema.Column{UserPromoCodesColumns[5]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { Name: "userpromocode_city_user_id_code", Unique: false, Columns: []*schema.Column{UserPromoCodesColumns[1], UserPromoCodesColumns[5], UserPromoCodesColumns[2]}, }, }, } // VehiclesColumns holds the columns for the "vehicles" table. VehiclesColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "city", Type: field.TypeString}, {Name: "type", Type: field.TypeString, Nullable: true}, {Name: "creation_time", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "TIMESTAMP"}}, {Name: "status", Type: field.TypeString, Nullable: true}, {Name: "current_location", Type: field.TypeString, Nullable: true}, {Name: "ext", Type: field.TypeJSON, Nullable: true}, {Name: "owner_id", Type: field.TypeUUID, Nullable: true}, } // VehiclesTable holds the schema information for the "vehicles" table. VehiclesTable = &schema.Table{ Name: "vehicles", Columns: VehiclesColumns, PrimaryKey: []*schema.Column{VehiclesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "vehicles_users_vehicles", Columns: []*schema.Column{VehiclesColumns[7]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, }, Indexes: []*schema.Index{ { Name: "vehicle_city_id", Unique: false, Columns: []*schema.Column{VehiclesColumns[1], VehiclesColumns[0]}, }, { Name: "vehicle_city_owner_id", Unique: false, Columns: []*schema.Column{VehiclesColumns[1], VehiclesColumns[7]}, }, }, } // VehicleLocationHistoriesColumns holds the columns for the "vehicle_location_histories" table. VehicleLocationHistoriesColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "city", Type: field.TypeString}, {Name: "timestamp", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "TIMESTAMP"}}, {Name: "lat", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "FLOAT8"}}, {Name: "long", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "FLOAT8"}}, {Name: "ride_id", Type: field.TypeUUID}, } // VehicleLocationHistoriesTable holds the schema information for the "vehicle_location_histories" table. VehicleLocationHistoriesTable = &schema.Table{ Name: "vehicle_location_histories", Columns: VehicleLocationHistoriesColumns, PrimaryKey: []*schema.Column{VehicleLocationHistoriesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "vehicle_location_histories_rides_vehicle_location_histories", Columns: []*schema.Column{VehicleLocationHistoriesColumns[5]}, RefColumns: []*schema.Column{RidesColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { Name: "vehiclelocationhistory_city_ride_id_timestamp", Unique: false, Columns: []*schema.Column{VehicleLocationHistoriesColumns[1], VehicleLocationHistoriesColumns[5], VehicleLocationHistoriesColumns[2]}, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ RidesTable, UsersTable, UserPromoCodesTable, VehiclesTable, VehicleLocationHistoriesTable, } )
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.