Fix enum null.String support, add mysql support
This commit is contained in:
parent
d891bcb9f0
commit
0d09921d4c
3 changed files with 40 additions and 4 deletions
|
@ -158,19 +158,26 @@ func randDate(s *Seed) time.Time {
|
|||
// If canBeNull is true:
|
||||
// The value has the possibility of being null or non-zero at random.
|
||||
func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bool) error {
|
||||
|
||||
kind := field.Kind()
|
||||
typ := field.Type()
|
||||
|
||||
if strings.HasPrefix(fieldType, "enum") {
|
||||
enum, err := randEnumValue(fieldType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
field.Set(reflect.ValueOf(enum))
|
||||
if kind == reflect.Struct {
|
||||
val := null.NewString(enum, rand.Intn(1) == 0)
|
||||
field.Set(reflect.ValueOf(val))
|
||||
} else {
|
||||
field.Set(reflect.ValueOf(enum))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
kind := field.Kind()
|
||||
typ := field.Type()
|
||||
|
||||
var value interface{}
|
||||
var isNull bool
|
||||
|
||||
|
|
20
testdata/mysql_test_schema.sql
vendored
20
testdata/mysql_test_schema.sql
vendored
|
@ -1,3 +1,23 @@
|
|||
CREATE TABLE event_one (
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name VARCHAR(255),
|
||||
day enum('monday','tuesday','wednesday')
|
||||
);
|
||||
|
||||
CREATE TABLE event_two (
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name VARCHAR(255),
|
||||
face enum('happy','sad','bitter')
|
||||
);
|
||||
|
||||
CREATE TABLE event_three (
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name VARCHAR(255),
|
||||
face enum('happy','sad','bitter'),
|
||||
mood enum('happy','sad','bitter'),
|
||||
day enum('monday','tuesday','wednesday')
|
||||
);
|
||||
|
||||
CREATE TABLE magic (
|
||||
id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
|
||||
id_two int NOT NULL,
|
||||
|
|
9
testdata/postgres_test_schema.sql
vendored
9
testdata/postgres_test_schema.sql
vendored
|
@ -13,6 +13,15 @@ CREATE TABLE event_two (
|
|||
day workday NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE event_three (
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name VARCHAR(255),
|
||||
day workday NOT NULL,
|
||||
face faceyface NOT NULL,
|
||||
thing workday NULL,
|
||||
stuff faceyface NULL
|
||||
);
|
||||
|
||||
CREATE TABLE facey (
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name VARCHAR(255),
|
||||
|
|
Loading…
Reference in a new issue