-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit.go
50 lines (40 loc) · 1.29 KB
/
init.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
package main
import (
"github.com/Chingu-cohorts/ChinguDevelopersNetwork/models"
"github.com/Chingu-cohorts/ChinguDevelopersNetwork/utils"
colorable "github.com/mattn/go-colorable"
"github.com/sirupsen/logrus"
)
func init() {
// To use cool colors in windows
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
logrus.SetOutput(colorable.NewColorableStdout())
// When initializing the application, we must run the migrations
db := utils.InitDB()
defer db.Close()
db.AutoMigrate(&models.Cohort{}, &models.User{}, &models.Project{}, &models.Aptitude{}, &models.Post{}, &models.Comment{})
// Load cohorts from file
cohorts, err := utils.LoadCohortSeed("cohorts.json")
if err != nil {
logrus.Panic("Could not read the cohorts file")
}
// Iterate over cohorts to save them
for _, cohort := range cohorts.Cohorts {
db.Create(&cohort)
logrus.WithFields(logrus.Fields{
"cohort": &cohort,
}).Info("Saving cohort")
}
// Load aptitudes from file
aptitudes, err := utils.LoadAptitudeSeed("aptitudes.json")
if err != nil {
logrus.Panic("Could not read the aptitudes file")
}
// Iterate over aptitudes to save them
for _, aptitude := range aptitudes.Aptitudes {
db.Create(&aptitude)
logrus.WithFields(logrus.Fields{
"aptitude": &aptitude,
}).Info("Saving aptitude")
}
}