Skip to content
Permalink
Browse files

feat: generate fake data for new models

  • Loading branch information...
moul committed Mar 16, 2019
1 parent cc45129 commit 989e1ed13d6a98652cf3451808f985ad8cf82cd2
Showing with 576 additions and 391 deletions.
  1. +1 −0 entity/entity.go
  2. +507 −357 entity/entity.pb.go
  3. +28 −24 entity/entity.proto
  4. +2 −0 go.mod
  5. +4 −0 go.sum
  6. +29 −8 server/svc.go
  7. +3 −0 sql/cmd_sql_dump.go
  8. +2 −2 sql/sql.go
@@ -43,6 +43,7 @@ func ForeignKeys() [][3]string {
return [][3]string{
{"Achievement", "author_id", "tournament_member(id)"},
{"Achievement", "level_validation_id", "level_validation(id)"},
{"AuthMethod", "user_id", "user(id)"},
{"Coupon", "tournament_id", "tournament(id)"},
{"CouponValidation", "author_id", "tournament_member(id)"},
{"CouponValidation", "coupon_id", "coupon(id)"},

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -66,11 +66,11 @@ message TournamentMember {
TournamentTeam tournament_team = 202 [(gogoproto.moretags) = "gorm:\"foreignkey:TournamentTeamID\""];
string tournament_team_id = 203 [(gogoproto.customname) = "TournamentTeamID", (gogoproto.moretags) = "sql:\"not null\" gorm:\"index\""];

repeated Coupon coupons = 204;
repeated Achievement achievements = 205;
repeated WhoswhoAttempt sent_whoswho_attempts = 206;
repeated WhoswhoAttempt received_whoswho_attempts = 207;
repeated InventoryItem items = 208;
repeated Coupon coupons = 204 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated Achievement achievements = 205 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated WhoswhoAttempt sent_whoswho_attempts = 206 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated WhoswhoAttempt received_whoswho_attempts = 207 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated InventoryItem items = 208 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message AuthMethod {
@@ -104,7 +104,8 @@ message AuthMethod {
// associations
//

repeated User users = 200;
User user = 200 [(gogoproto.moretags) = "gorm:\"foreignkey:UserID\""];
string user_id = 201 [(gogoproto.customname) = "UserID", (gogoproto.moretags) = "sql:\"not null\" gorm:\"index\""];
}

// User defines a User Account / Profile
@@ -125,11 +126,11 @@ message User {
// associations
//

repeated UserSession sessions = 200;
repeated TournamentMember tournament_memberships = 201;
repeated Notification notifications = 202;
repeated AuthMethod auth_methods = 203;
repeated Team teams = 204;
repeated UserSession sessions = 200 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated TournamentMember tournament_memberships = 201 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated Notification notifications = 202 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated AuthMethod auth_methods = 203 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated Team teams = 204 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message UserSession {
@@ -164,8 +165,8 @@ message Team {
// associations
//

repeated TournamentTeam tournament_teams = 200;
repeated WhoswhoAttempt received_whoswho_attempts = 201;
repeated TournamentTeam tournament_teams = 200 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated WhoswhoAttempt received_whoswho_attempts = 201 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message Level {
@@ -186,6 +187,8 @@ message Level {
//
// associations
//

repeated LevelVersion versions = 200 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message LevelVersion {
@@ -205,7 +208,8 @@ message LevelVersion {
string changelog = 101;
bool is_draft = 102;
bool is_latest = 103;
string source_url = 104;
string source_url = 104 [(gogoproto.customname) = "SourceURL"];
Driver driver = 105;

//
// associations
@@ -214,7 +218,7 @@ message LevelVersion {
Level level = 200 [(gogoproto.moretags) = "gorm:\"foreignkey:LevelID\""];
string level_id = 201 [(gogoproto.customname) = "LevelID", (gogoproto.moretags) = "sql:\"not null\" gorm:\"index\""];

repeated LevelFlavor flavors = 202;
repeated LevelFlavor flavors = 202 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message Tournament {
@@ -246,8 +250,8 @@ message Tournament {
// associations
//

repeated TournamentTeam teams = 200;
repeated Coupon coupons = 201;
repeated TournamentTeam teams = 200 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated Coupon coupons = 201 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message TournamentTeam {
@@ -274,8 +278,8 @@ message TournamentTeam {
Team team = 202 [(gogoproto.moretags) = "gorm:\"foreignkey:TeamID\""];
string team_id = 203 [(gogoproto.customname) = "TeamID", (gogoproto.moretags) = "sql:\"not null\" gorm:\"index\""];

repeated LevelSubscription level_subscriptions = 205;
repeated TournamentMember members = 206;
repeated LevelSubscription level_subscriptions = 205 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated TournamentMember members = 206 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message WhoswhoAttempt {
@@ -344,7 +348,7 @@ message LevelSubscription {
LevelFlavor level_flavor = 202 [(gogoproto.moretags) = "gorm:\"foreignkey:LevelFlavorID\""];
string level_flavor_id = 203 [(gogoproto.customname) = "LevelFlavorID", (gogoproto.moretags) = "sql:\"not null\" gorm:\"index\""];

repeated LevelValidation validations = 204;
repeated LevelValidation validations = 204 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message InventoryItem {
@@ -382,8 +386,8 @@ message LevelFlavor {
Level level = 200 [(gogoproto.moretags) = "gorm:\"foreignkey:LevelID\""];
string level_id = 201 [(gogoproto.customname) = "LevelID", (gogoproto.moretags) = "sql:\"not null\" gorm:\"index\""];

repeated LevelInstance instances = 202;
repeated LevelSubscription subscriptions = 203;
repeated LevelInstance instances = 202 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
repeated LevelSubscription subscriptions = 203 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message LevelInstance {
@@ -433,7 +437,7 @@ message Hypervisor {
// associations
//

repeated LevelInstance level_instances = 200;
repeated LevelInstance level_instances = 200 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message Event {
@@ -488,7 +492,7 @@ message Coupon {
Tournament tournament = 200 [(gogoproto.moretags) = "gorm:\"foreignkey:TournamentID\""];
string tournament_id = 201 [(gogoproto.customname) = "TournamentID", (gogoproto.moretags) = "gorm:\"index\""];

repeated CouponValidation validations = 202;
repeated CouponValidation validations = 202 [(gogoproto.moretags) = "gorm:\"PRELOAD:false\""];
}

message CouponValidation {
2 go.mod
@@ -4,6 +4,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/go-winio v0.4.11 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/brianvoe/gofakeit v3.17.0+incompatible // indirect
github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/distribution v2.7.1+incompatible // indirect
@@ -24,6 +25,7 @@ require (
github.com/jinzhu/now v0.0.0-20181116074157-8ec929ed50c3 // indirect
github.com/lib/pq v1.0.0 // indirect
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/moul/gofakeit v3.12.0+incompatible
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/pkg/errors v0.8.1
4 go.sum
@@ -11,6 +11,8 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/ajg/form v0.0.0-20160822230020-523a5da1a92f/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/brianvoe/gofakeit v3.17.0+incompatible h1:C1+30+c0GtjgGDtRC+iePZeP1WMiwsWCELNJhmc7aIc=
github.com/brianvoe/gofakeit v3.17.0+incompatible/go.mod h1:kfwdRA90vvNhPutZWfH7WPaDzUjz+CZFqG+rPkOjGOc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk=
@@ -317,6 +319,8 @@ github.com/mitchellh/mapstructure v1.0.0/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/monoculum/formam v0.0.0-20180901015400-4e68be1d79ba/go.mod h1:RKgILGEJq24YyJ2ban8EO0RUVSJlF1pGsEvoLEACr/Q=
github.com/moul/gofakeit v3.12.0+incompatible h1:TsfUkTAS0r2Zhu1mywTrO5yDwvTt3Yo9Zbi+RoKLjXs=
github.com/moul/gofakeit v3.12.0+incompatible/go.mod h1:2rbDJJeXhTT7dyI0OU5tm8aQ0tHTO5ga8/Pv6a/SuU4=
github.com/nicksnyder/go-i18n v1.10.0/go.mod h1:HrK7VCrbOvQoUAQ7Vpy7i87N7JZZZ7R2xBGjv0j365Q=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -5,6 +5,7 @@ import (

jwt "github.com/dgrijalva/jwt-go"
"github.com/jinzhu/gorm"
"github.com/moul/gofakeit"
"github.com/pkg/errors"

"pathwar.pw/entity"
@@ -45,14 +46,34 @@ func (s *svc) UserSession(ctx context.Context, _ *Void) (*entity.UserSession, er
}

func (s *svc) GenerateFakeData(ctx context.Context, _ *Void) (*Void, error) {
if err := s.db.Create(&entity.Level{
Name: "level1",
Description: "description 1",
Author: "author 1",
Locale: "fr_FR",
IsDraft: false,
}).Error; err != nil {
return nil, err
levels := []*entity.Level{}
for i := 0; i < 5; i++ {
level := &entity.Level{
Name: gofakeit.HipsterWord(),
Description: gofakeit.HipsterSentence(10),
Author: gofakeit.Name(),
Locale: "fr_FR",
IsDraft: false,
Versions: []*entity.LevelVersion{},
}
for i := 0; i < 2; i++ {
version := &entity.LevelVersion{
Driver: entity.LevelVersion_Docker,
Version: gofakeit.IPv4Address(),
Changelog: gofakeit.HipsterSentence(5),
IsDraft: false,
IsLatest: i == 0,
SourceURL: gofakeit.URL(),
}
level.Versions = append(level.Versions, version)
}
levels = append(levels, level)
}

for _, level := range levels {
if err := s.db.Set("gorm:association_autoupdate", true).Create(level).Error; err != nil {
return nil, err
}
}
return &Void{}, nil
}
@@ -48,6 +48,9 @@ func DoDump(db *gorm.DB) (*entity.Dump, error) {
if err := db.Find(&dump.Levels).Error; err != nil {
return nil, err
}
if err := db.Find(&dump.LevelVersions).Error; err != nil {
return nil, err
}
if err := db.Find(&dump.UserSessions).Error; err != nil {
return nil, err
}
@@ -29,8 +29,8 @@ func FromOpts(opts *Options) (*gorm.DB, error) {
log.SetOutput(os.Stderr)

db.SetLogger(zapgorm.New(zap.L().Named("vendor.gorm")))
db = db.Set("gorm:auto_preload", true)
db = db.Set("gorm:association_autoupdate", true)
db = db.Set("gorm:auto_preload", false)
db = db.Set("gorm:association_autoupdate", false)
db.BlockGlobalUpdate(true)
db.SingularTable(true)
db.LogMode(true)

0 comments on commit 989e1ed

Please sign in to comment.
You can’t perform that action at this time.