-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_faked_data.go
83 lines (79 loc) · 2.34 KB
/
create_faked_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package gomonolith
import (
"fmt"
abtestmodel "github.com/sergeyglazyrindev/go-monolith/blueprint/abtest/models"
"github.com/sergeyglazyrindev/go-monolith/blueprint/approval/models"
logmodel "github.com/sergeyglazyrindev/go-monolith/blueprint/logging/models"
"github.com/sergeyglazyrindev/go-monolith/core"
"strconv"
"time"
)
type CreateFakedDataCommand struct {
}
func (c CreateFakedDataCommand) Proceed(subaction string, args []string) error {
database := core.NewDatabaseInstance()
for i := range core.GenerateNumberSequence(1, 100) {
userModel := &core.User{
Email: fmt.Sprintf("admin_%[email protected]", i),
Username: "admin_" + strconv.Itoa(i),
FirstName: "firstname_" + strconv.Itoa(i),
LastName: "lastname_" + strconv.Itoa(i),
}
database.Db.Create(&userModel)
oneTimeAction := &core.OneTimeAction{
User: *userModel,
ExpiresOn: time.Now(),
Code: strconv.Itoa(i),
}
database.Db.Create(&oneTimeAction)
session := &core.Session{
User: userModel,
LoginTime: time.Now(),
LastLogin: time.Now(),
}
database.Db.Create(&session)
}
var contentTypes []*core.ContentType
database.Db.Find(&contentTypes)
for _, contentType := range contentTypes {
logModel := logmodel.Log{
Username: "admin",
ContentTypeID: contentType.ID,
}
database.Db.Create(&logModel)
approvalModel := models.Approval{
ContentTypeID: contentType.ID,
ModelPK: uint(1),
ColumnName: "Email",
OldValue: "[email protected]",
NewValue: "[email protected]",
NewValueDescription: "changing email",
ChangedBy: "superuser",
ChangeDate: time.Now(),
}
database.Db.Create(&approvalModel)
abTestModel := abtestmodel.ABTest{
Name: "test_1",
ContentTypeID: contentType.ID,
}
database.Db.Create(&abTestModel)
for i := range core.GenerateNumberSequence(0, 100) {
abTestValueModel := abtestmodel.ABTestValue{
ABTest: abTestModel,
Value: strconv.Itoa(i),
}
database.Db.Create(&abTestValueModel)
}
}
for i := range core.GenerateNumberSequence(1, 20) {
groupModel := core.UserGroup{
GroupName: fmt.Sprintf("Group name %d", i),
}
database.Db.Create(&groupModel)
}
database.Close()
return nil
}
func (c CreateFakedDataCommand) GetHelpText() string {
return "Create fake data for testing go-monolith"
}