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 ( // OrdersColumns holds the columns for the "orders" table. OrdersColumns = []*schema.Column{ {Name: "order_id", Type: field.TypeInt64, Increment: true}, {Name: "order_no", Type: field.TypeString, Nullable: true}, {Name: "tx_id", Type: field.TypeInt64}, {Name: "order_status", Type: field.TypeEnum, Enums: []string{"pending", "processing", "shipped", "delivered", "cancelled"}}, {Name: "delivered_address", Type: field.TypeString, Nullable: true}, {Name: "shipping_cost", Type: field.TypeFloat64, Nullable: true}, {Name: "total_amount", Type: field.TypeFloat64, Nullable: true}, {Name: "placed_user_id", Type: field.TypeInt64}, {Name: "placed_at", Type: field.TypeTime, Nullable: true}, {Name: "shipped_address", Type: field.TypeString, Nullable: true}, {Name: "shipped_at", Type: field.TypeTime, Nullable: true}, {Name: "payment_id", Type: field.TypeInt64, Nullable: true}, {Name: "transaction_tx_order", Type: field.TypeInt64, Nullable: true}, } // 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: "orders_transactions_txOrder", Columns: []*schema.Column{OrdersColumns[12]}, RefColumns: []*schema.Column{TransactionsColumns[0]}, OnDelete: schema.SetNull, }, }, } // TransactionsColumns holds the columns for the "transactions" table. TransactionsColumns = []*schema.Column{ {Name: "tx_id", Type: field.TypeInt64, Increment: true}, {Name: "tx_no", Type: field.TypeString}, {Name: "tx_type", Type: field.TypeEnum, Enums: []string{"buy", "sell"}}, {Name: "user_id", Type: field.TypeInt64}, {Name: "quantity", Type: field.TypeInt}, {Name: "tx_status", Type: field.TypeEnum, Enums: []string{"pending", "completed", "cancelled"}}, {Name: "tx_date", Type: field.TypeTime, Nullable: true}, {Name: "tx_amount", Type: field.TypeFloat64, Nullable: true}, {Name: "payment_id", Type: field.TypeInt64, Nullable: true}, {Name: "order_transaction", Type: field.TypeInt64, Nullable: true}, } // TransactionsTable holds the schema information for the "transactions" table. TransactionsTable = &schema.Table{ Name: "transactions", Columns: TransactionsColumns, PrimaryKey: []*schema.Column{TransactionsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "transactions_orders_transaction", Columns: []*schema.Column{TransactionsColumns[9]}, RefColumns: []*schema.Column{OrdersColumns[0]}, OnDelete: schema.SetNull, }, }, } // TxItemsColumns holds the columns for the "tx_items" table. TxItemsColumns = []*schema.Column{ {Name: "tx_item_id", Type: field.TypeInt64, Increment: true}, {Name: "tx_type", Type: field.TypeEnum, Enums: []string{"buy", "sell"}}, {Name: "tx_id", Type: field.TypeInt64}, {Name: "book_id", Type: field.TypeInt64}, {Name: "quantity", Type: field.TypeInt}, {Name: "price", Type: field.TypeFloat64}, {Name: "isbn", Type: field.TypeString}, {Name: "title", Type: field.TypeString}, {Name: "author", Type: field.TypeString}, {Name: "publisher_id", Type: field.TypeInt64, Nullable: true}, {Name: "image_url", Type: field.TypeString, Nullable: true}, {Name: "order_tx_items", Type: field.TypeInt64, Nullable: true}, {Name: "transaction_tx_items", Type: field.TypeInt64, Nullable: true}, } // TxItemsTable holds the schema information for the "tx_items" table. TxItemsTable = &schema.Table{ Name: "tx_items", Columns: TxItemsColumns, PrimaryKey: []*schema.Column{TxItemsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "tx_items_orders_txItems", Columns: []*schema.Column{TxItemsColumns[11]}, RefColumns: []*schema.Column{OrdersColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "tx_items_transactions_txItems", Columns: []*schema.Column{TxItemsColumns[12]}, RefColumns: []*schema.Column{TransactionsColumns[0]}, OnDelete: schema.SetNull, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ OrdersTable, TransactionsTable, TxItemsTable, } )
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.