-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathseed.go
107 lines (89 loc) · 1.81 KB
/
seed.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"github.com/gopheracademy/congo/models"
"github.com/jinzhu/gorm"
)
func createTenants(db gorm.DB) error {
var err error
var count int
err = db.Model(&models.Tenant{}).Count(&count).Error
if err != nil {
return err
}
if count == 0 {
var name string
name = "GopherAcademy, LLC"
tenant := models.Tenant{}
tenant.Name = name
err = db.Create(&tenant).Error
tenant2 := models.Tenant{}
name = "SomeOther Tenant"
tenant2 = models.Tenant{}
tenant2.Name = name
err = db.Create(&tenant2).Error
}
return err
}
func createSeries(db gorm.DB) error {
var err error
var count int
err = db.Model(&models.Series{}).Count(&count).Error
if err != nil {
return err
}
if count == 0 {
var name string
name = "GopherCon"
series := models.Series{}
series.Name = name
series.TenantID = 1
err = db.Create(&series).Error
}
return err
}
func createEvents(db gorm.DB) error {
var err error
var count int
err = db.Model(&models.Event{}).Count(&count).Error
if err != nil {
return err
}
if count == 0 {
var name string
name = "GopherCon 2016"
event := models.Event{}
event.Name = name
event.TenantID = 1
err = db.Create(&event).Error
}
return err
}
func createUsers(db gorm.DB) error {
var err error
var count int
err = db.Model(&models.User{}).Count(&count).Error
if err != nil {
return err
}
if count == 0 {
var firstname string
var lastname string
var password string
var email string
var validated bool
firstname = "Brian"
lastname = "Ketelsen"
password = "GopherCon"
email = "[email protected]"
validated = true
user := models.User{}
user.FirstName = firstname
user.LastName = lastname
user.Password = password
user.Email = email
user.Validated = &validated
user.TenantID = 1
err = db.Create(&user).Error
}
return err
}