From 8ce8a4160dea3e5f60a135bfe3c844b9084777f5 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Date: Sun, 31 Dec 2023 12:30:45 +0200 Subject: [PATCH] examples/migration: append enum not at the end (#3877) --- .../ent/migrate/migrations/20231231102849_add_currency.sql | 2 ++ examples/migration/ent/migrate/migrations/atlas.sum | 3 ++- examples/migration/ent/migrate/schema.go | 2 +- examples/migration/ent/payment/payment.go | 3 ++- examples/migration/ent/schema/payment.go | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 examples/migration/ent/migrate/migrations/20231231102849_add_currency.sql diff --git a/examples/migration/ent/migrate/migrations/20231231102849_add_currency.sql b/examples/migration/ent/migrate/migrations/20231231102849_add_currency.sql new file mode 100644 index 000000000..41b610132 --- /dev/null +++ b/examples/migration/ent/migrate/migrations/20231231102849_add_currency.sql @@ -0,0 +1,2 @@ +-- Modify "payments" table +ALTER TABLE `payments` MODIFY COLUMN `currency` enum('USD','EUR','ILS') NOT NULL; diff --git a/examples/migration/ent/migrate/migrations/atlas.sum b/examples/migration/ent/migrate/migrations/atlas.sum index f8295fd9d..fd57b3095 100644 --- a/examples/migration/ent/migrate/migrations/atlas.sum +++ b/examples/migration/ent/migrate/migrations/atlas.sum @@ -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= diff --git a/examples/migration/ent/migrate/schema.go b/examples/migration/ent/migrate/schema.go index e682c8dc7..31cf313b7 100644 --- a/examples/migration/ent/migrate/schema.go +++ b/examples/migration/ent/migrate/schema.go @@ -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"}}, diff --git a/examples/migration/ent/payment/payment.go b/examples/migration/ent/payment/payment.go index 6e40d0109..cf8c20315 100644 --- a/examples/migration/ent/payment/payment.go +++ b/examples/migration/ent/payment/payment.go @@ -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) diff --git a/examples/migration/ent/schema/payment.go b/examples/migration/ent/schema/payment.go index 66a897b3e..26fc90ade 100644 --- a/examples/migration/ent/schema/payment.go +++ b/examples/migration/ent/schema/payment.go @@ -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").