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 ( // CurrencyRatesColumns holds the columns for the "currency_rates" table. CurrencyRatesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "symbol", Type: field.TypeString}, {Name: "rate", Type: field.TypeString}, {Name: "expired_at", Type: field.TypeTime, Nullable: true}, } // CurrencyRatesTable holds the schema information for the "currency_rates" table. CurrencyRatesTable = &schema.Table{ Name: "currency_rates", Columns: CurrencyRatesColumns, PrimaryKey: []*schema.Column{CurrencyRatesColumns[0]}, Indexes: []*schema.Index{ { Name: "currencyrate_symbol", Unique: false, Columns: []*schema.Column{CurrencyRatesColumns[3]}, }, }, } // IcosColumns holds the columns for the "icos" table. IcosColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "round_id", Type: field.TypeInt32}, {Name: "round_name", Type: field.TypeString}, {Name: "price", Type: field.TypeString}, {Name: "num_token", Type: field.TypeString}, {Name: "num_sub", Type: field.TypeInt32}, {Name: "price_gap", Type: field.TypeString}, {Name: "ended_at", Type: field.TypeTime, Nullable: true}, } // IcosTable holds the schema information for the "icos" table. IcosTable = &schema.Table{ Name: "icos", Columns: IcosColumns, PrimaryKey: []*schema.Column{IcosColumns[0]}, } // IcoCouponsColumns holds the columns for the "ico_coupons" table. IcoCouponsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "user_id", Type: field.TypeString}, {Name: "coupon", Type: field.TypeString}, {Name: "reward", Type: field.TypeString}, {Name: "cashback", Type: field.TypeString}, {Name: "deleted_at", Type: field.TypeTime, Nullable: true}, } // IcoCouponsTable holds the schema information for the "ico_coupons" table. IcoCouponsTable = &schema.Table{ Name: "ico_coupons", Columns: IcoCouponsColumns, PrimaryKey: []*schema.Column{IcoCouponsColumns[0]}, Indexes: []*schema.Index{ { Name: "icocoupon_coupon", Unique: true, Columns: []*schema.Column{IcoCouponsColumns[4]}, }, }, } // IcoHistoriesColumns holds the columns for the "ico_histories" table. IcoHistoriesColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "round_id", Type: field.TypeInt32}, {Name: "user_id", Type: field.TypeString}, {Name: "price", Type: field.TypeString}, {Name: "num_token", Type: field.TypeString}, {Name: "sub_round", Type: field.TypeInt32}, {Name: "type", Type: field.TypeString, Nullable: true}, } // IcoHistoriesTable holds the schema information for the "ico_histories" table. IcoHistoriesTable = &schema.Table{ Name: "ico_histories", Columns: IcoHistoriesColumns, PrimaryKey: []*schema.Column{IcoHistoriesColumns[0]}, } // IcoRoundsColumns holds the columns for the "ico_rounds" table. IcoRoundsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "round_id", Type: field.TypeInt32}, {Name: "sub_round", Type: field.TypeInt32}, {Name: "price", Type: field.TypeString}, {Name: "num_token", Type: field.TypeString}, {Name: "bought_token", Type: field.TypeString}, {Name: "start_at", Type: field.TypeTime, Nullable: true}, {Name: "end_at", Type: field.TypeTime, Nullable: true}, {Name: "is_close", Type: field.TypeBool, Default: false}, } // IcoRoundsTable holds the schema information for the "ico_rounds" table. IcoRoundsTable = &schema.Table{ Name: "ico_rounds", Columns: IcoRoundsColumns, PrimaryKey: []*schema.Column{IcoRoundsColumns[0]}, } // TransactionsColumns holds the columns for the "transactions" table. TransactionsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "trans_type", Type: field.TypeString}, {Name: "source", Type: field.TypeString}, {Name: "src_symbol", Type: field.TypeString}, {Name: "src_amount", Type: field.TypeString}, {Name: "destination", Type: field.TypeString}, {Name: "dest_symbol", Type: field.TypeString}, {Name: "dest_amount", Type: field.TypeString}, {Name: "rate", Type: field.TypeString}, {Name: "source_service", Type: field.TypeString}, {Name: "source_id", Type: field.TypeString}, {Name: "status", Type: field.TypeString}, } // TransactionsTable holds the schema information for the "transactions" table. TransactionsTable = &schema.Table{ Name: "transactions", Columns: TransactionsColumns, PrimaryKey: []*schema.Column{TransactionsColumns[0]}, } // UserWalletsColumns holds the columns for the "user_wallets" table. UserWalletsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "user_id", Type: field.TypeString}, {Name: "type", Type: field.TypeString}, {Name: "symbol", Type: field.TypeString}, {Name: "is_active", Type: field.TypeBool}, {Name: "balance", Type: field.TypeString, SchemaType: map[string]string{"postgres": "numeric"}}, } // UserWalletsTable holds the schema information for the "user_wallets" table. UserWalletsTable = &schema.Table{ Name: "user_wallets", Columns: UserWalletsColumns, PrimaryKey: []*schema.Column{UserWalletsColumns[0]}, Indexes: []*schema.Index{ { Name: "userwallet_user_id_symbol_type", Unique: true, Columns: []*schema.Column{UserWalletsColumns[3], UserWalletsColumns[5], UserWalletsColumns[4]}, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ CurrencyRatesTable, IcosTable, IcoCouponsTable, IcoHistoriesTable, IcoRoundsTable, TransactionsTable, UserWalletsTable, } )
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.