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 ( // AddressesColumns holds the columns for the "addresses" table. AddressesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "city", Type: field.TypeString}, {Name: "country", Type: field.TypeString}, {Name: "flat", Type: field.TypeInt, Nullable: true}, {Name: "house", Type: field.TypeInt}, {Name: "letter", Type: field.TypeString, Nullable: true}, {Name: "postcode", Type: field.TypeInt}, {Name: "street", Type: field.TypeString}, {Name: "user_id", Type: field.TypeInt64}, } // AddressesTable holds the schema information for the "addresses" table. AddressesTable = &schema.Table{ Name: "addresses", Columns: AddressesColumns, PrimaryKey: []*schema.Column{AddressesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "address_user_fk", Columns: []*schema.Column{AddressesColumns[10]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.Cascade, }, }, } // CartsColumns holds the columns for the "carts" table. CartsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "amount", Type: field.TypeInt64}, {Name: "product_id", Type: field.TypeInt64}, {Name: "user_id", Type: field.TypeInt64}, } // CartsTable holds the schema information for the "carts" table. CartsTable = &schema.Table{ Name: "carts", Columns: CartsColumns, PrimaryKey: []*schema.Column{CartsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "cart_product_fk", Columns: []*schema.Column{CartsColumns[4]}, RefColumns: []*schema.Column{ProductsColumns[0]}, OnDelete: schema.Restrict, }, { Symbol: "cart_user_fk", Columns: []*schema.Column{CartsColumns[5]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.Cascade, }, }, Indexes: []*schema.Index{ { Name: "carts_user_id_product_id_unique", Unique: true, Columns: []*schema.Column{CartsColumns[5], CartsColumns[4]}, }, }, } // CategoriesColumns holds the columns for the "categories" table. CategoriesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "name", Type: field.TypeString}, } // CategoriesTable holds the schema information for the "categories" table. CategoriesTable = &schema.Table{ Name: "categories", Columns: CategoriesColumns, PrimaryKey: []*schema.Column{CategoriesColumns[0]}, } // OrdersColumns holds the columns for the "orders" table. OrdersColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "status", Type: field.TypeEnum, Enums: []string{"CREATED", "ACCEPTED", "CANCELED"}, Default: "CREATED", SchemaType: map[string]string{"postgres": "order_status"}}, {Name: "user_id", Type: field.TypeInt64}, } // OrdersTable holds the schema information for the "orders" table. OrdersTable = &schema.Table{ Name: "orders", Columns: OrdersColumns, PrimaryKey: []*schema.Column{OrdersColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "order_user_fk", Columns: []*schema.Column{OrdersColumns[4]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.Restrict, }, }, } // OrderProductsColumns holds the columns for the "order_products" table. OrderProductsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "amount", Type: field.TypeInt64, Default: 0}, {Name: "price", Type: field.TypeInt64}, {Name: "order_id", Type: field.TypeInt64}, {Name: "product_id", Type: field.TypeInt64}, } // OrderProductsTable holds the schema information for the "order_products" table. OrderProductsTable = &schema.Table{ Name: "order_products", Columns: OrderProductsColumns, PrimaryKey: []*schema.Column{OrderProductsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "order_product_order_fk", Columns: []*schema.Column{OrderProductsColumns[5]}, RefColumns: []*schema.Column{OrdersColumns[0]}, OnDelete: schema.Restrict, }, { Symbol: "order_product_product_fk", Columns: []*schema.Column{OrderProductsColumns[6]}, RefColumns: []*schema.Column{ProductsColumns[0]}, OnDelete: schema.Restrict, }, }, Indexes: []*schema.Index{ { Name: "order_product_order_id_product_id_unique", Unique: true, Columns: []*schema.Column{OrderProductsColumns[6], OrderProductsColumns[5]}, }, }, } // ProductsColumns holds the columns for the "products" table. ProductsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "name", Type: field.TypeString}, {Name: "description", Type: field.TypeString, Nullable: true}, {Name: "amount", Type: field.TypeInt64, Default: 0}, {Name: "price", Type: field.TypeInt64}, {Name: "category_id", Type: field.TypeInt64}, } // ProductsTable holds the schema information for the "products" table. ProductsTable = &schema.Table{ Name: "products", Columns: ProductsColumns, PrimaryKey: []*schema.Column{ProductsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "product_category_fk", Columns: []*schema.Column{ProductsColumns[7]}, RefColumns: []*schema.Column{CategoriesColumns[0]}, OnDelete: schema.Restrict, }, }, } // ProductImagesColumns holds the columns for the "product_images" table. ProductImagesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "name", Type: field.TypeString}, {Name: "product_id", Type: field.TypeInt64}, } // ProductImagesTable holds the schema information for the "product_images" table. ProductImagesTable = &schema.Table{ Name: "product_images", Columns: ProductImagesColumns, PrimaryKey: []*schema.Column{ProductImagesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "product_image_product_fk", Columns: []*schema.Column{ProductImagesColumns[4]}, RefColumns: []*schema.Column{ProductsColumns[0]}, OnDelete: schema.Cascade, }, }, Indexes: []*schema.Index{ { Name: "product_images_name_unique", Unique: true, Columns: []*schema.Column{ProductImagesColumns[4], ProductImagesColumns[3]}, }, }, } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamp"}}, {Name: "name", Type: field.TypeString}, {Name: "phone", Type: field.TypeString}, {Name: "email", Type: field.TypeString, Unique: true}, {Name: "role", Type: field.TypeEnum, Enums: []string{"ADMIN", "USER"}, Default: "USER", SchemaType: map[string]string{"postgres": "user_role"}}, {Name: "password", Type: field.TypeString}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ Name: "users", Columns: UsersColumns, PrimaryKey: []*schema.Column{UsersColumns[0]}, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ AddressesTable, CartsTable, CategoriesTable, OrdersTable, OrderProductsTable, ProductsTable, ProductImagesTable, UsersTable, } )
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.