mirror of
https://github.com/ent/ent.git
synced 2026-03-05 19:35:23 +03:00
examples/migration: append enum not at the end (#3877)
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
-- Modify "payments" table
|
||||
ALTER TABLE `payments` MODIFY COLUMN `currency` enum('USD','EUR','ILS') NOT NULL;
|
||||
@@ -1,4 +1,4 @@
|
||||
h1:BZ/m+1lip4UqNLaufWxuuYirZn+gqq4srr3X5JpGuOY=
|
||||
h1:vFJjF6gKF6Kigs+rBWkamXcvdrlazHp0ZragMtOCVRM=
|
||||
20221114082343_create_users.sql h1:EeOPKbOeYUHO830P1MCXKUsxT3wLk/hSgcpT9GzlGZQ=
|
||||
20221114090322_add_age.sql h1:weRCTqS5cqKyrvIjGXk7Bn24YUXo0nhLNWD0EZBcaoQ=
|
||||
20221114101516_add_name.sql h1:leQgI2JN3URZyujlNzX3gI53MSiTA02MKI/G9cnMu6I=
|
||||
@@ -8,3 +8,4 @@ h1:BZ/m+1lip4UqNLaufWxuuYirZn+gqq4srr3X5JpGuOY=
|
||||
20231231083716_add_card_number.sql h1:sBxY6RlbqEsE8hx6Q/hSuNXfBGvVmZ0OYiZcP8uDNOc=
|
||||
20231231091550_add_pet_name.sql h1:80NyHhZ/ZC4Um0j0NLzUpf1UBj4GKvMu678EqkJsFuU=
|
||||
20231231101555_add_payment.sql h1:Je16hh6fEWuL5/nbQN5v+MNkC8ruhtTgEcEgkh+Gyyg=
|
||||
20231231102849_add_currency.sql h1:Dzm4fDibgEV841whj7Y1TMeat6Qt5d7kQojBXNIh2nY=
|
||||
|
||||
@@ -37,7 +37,7 @@ var (
|
||||
PaymentsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "amount", Type: field.TypeFloat64},
|
||||
{Name: "currency", Type: field.TypeEnum, Enums: []string{"USD", "ILS"}},
|
||||
{Name: "currency", Type: field.TypeEnum, Enums: []string{"USD", "EUR", "ILS"}},
|
||||
{Name: "time", Type: field.TypeTime},
|
||||
{Name: "description", Type: field.TypeString},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"pending", "completed", "failed"}},
|
||||
|
||||
@@ -75,6 +75,7 @@ type Currency string
|
||||
// Currency values.
|
||||
const (
|
||||
CurrencyUSD Currency = "USD"
|
||||
CurrencyEUR Currency = "EUR"
|
||||
CurrencyILS Currency = "ILS"
|
||||
)
|
||||
|
||||
@@ -85,7 +86,7 @@ func (c Currency) String() string {
|
||||
// CurrencyValidator is a validator for the "currency" field enum values. It is called by the builders before save.
|
||||
func CurrencyValidator(c Currency) error {
|
||||
switch c {
|
||||
case CurrencyUSD, CurrencyILS:
|
||||
case CurrencyUSD, CurrencyEUR, CurrencyILS:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("payment: invalid enum value for currency field: %q", c)
|
||||
|
||||
@@ -25,7 +25,7 @@ func (Payment) Fields() []ent.Field {
|
||||
field.Float("amount").
|
||||
Positive(),
|
||||
field.Enum("currency").
|
||||
Values("USD", "ILS"),
|
||||
Values("USD", "EUR", "ILS"),
|
||||
field.Time("time"),
|
||||
field.String("description"),
|
||||
field.Enum("status").
|
||||
|
||||
Reference in New Issue
Block a user