Fix enum null.String support, add mysql support

This commit is contained in:
Patrick O'brien 2016-11-12 15:58:41 +10:00
parent d891bcb9f0
commit 0d09921d4c
3 changed files with 40 additions and 4 deletions

View file

@ -158,19 +158,26 @@ func randDate(s *Seed) time.Time {
// If canBeNull is true: // If canBeNull is true:
// The value has the possibility of being null or non-zero at random. // 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 { func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bool) error {
kind := field.Kind()
typ := field.Type()
if strings.HasPrefix(fieldType, "enum") { if strings.HasPrefix(fieldType, "enum") {
enum, err := randEnumValue(fieldType) enum, err := randEnumValue(fieldType)
if err != nil { if err != nil {
return err 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 return nil
} }
kind := field.Kind()
typ := field.Type()
var value interface{} var value interface{}
var isNull bool var isNull bool

View file

@ -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 ( CREATE TABLE magic (
id int PRIMARY KEY NOT NULL AUTO_INCREMENT, id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
id_two int NOT NULL, id_two int NOT NULL,

View file

@ -13,6 +13,15 @@ CREATE TABLE event_two (
day workday NOT NULL 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 ( CREATE TABLE facey (
id serial PRIMARY KEY NOT NULL, id serial PRIMARY KEY NOT NULL,
name VARCHAR(255), name VARCHAR(255),