审查视图

pkg/infrastructure/pg/init.go 1.8 KB
tangxvhui authored
1 2 3 4
package pg

import (
	"fmt"
Your Name authored
5
tangxvhui authored
6
	"github.com/go-pg/pg/v10"
tangxvhui authored
7
	"github.com/go-pg/pg/v10/orm"
郑周 authored
8
	"github.com/linmadan/egglib-go/persistent/pg/comment"
tangxvhui authored
9 10
	"github.com/linmadan/egglib-go/persistent/pg/hooks"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
tangxvhui authored
11 12
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
tangxvhui authored
13 14 15 16 17
)

var DB *pg.DB

func init() {
18
tangxvhui authored
19 20 21 22 23 24 25 26 27 28 29
	DB = pg.Connect(&pg.Options{
		User:     constant.POSTGRESQL_USER,
		Password: constant.POSTGRESQL_PASSWORD,
		Database: constant.POSTGRESQL_DB_NAME,
		Addr:     fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT),
	})
	if !constant.DISABLE_SQL_GENERATE_PRINT {
		DB.AddQueryHook(hooks.SqlGeneratePrintHook{
			Logger: log.Logger,
		})
	}
tangxvhui authored
30 31 32 33 34
	if !constant.DISABLE_CREATE_TABLE {
		tables := []interface{}{
			&models.Company{},
			&models.Department{},
			&models.User{},
tangxvhui authored
35
			&models.ReceivedMessage{},
郑周 authored
36 37
			&models.Role{},
			&models.RoleUser{},
庄敏学 authored
38
			&models.Position{},
郑周 authored
39 40 41 42 43
			&models.EvaluationRule{},
			&models.EvaluationTemplate{},
			&models.EvaluationCycle{},
			&models.EvaluationCycleTemplate{},
			&models.EvaluationProject{},
郑周 authored
44
			&models.NodeTask{},
Your Name authored
45 46
			&models.StaffAssess{},
			&models.StaffAssessTask{},
Your Name authored
47
			&models.StaffAssessContent{},
48
			&models.StaffAssessCache{},
tangxvhui authored
49 50 51
			&models.EvaluationItemUsed{},
			&models.SummaryEvaluation{},
			&models.SummaryEvaluationValue{},
郑周 authored
52
			&models.Permission{},
tangxvhui authored
53
			&models.LogSms{},
tangxvhui authored
54
			&models.MessagePersonal{},
tangxvhui authored
55 56
			&models.Task{},
			&models.TaskStage{},
tangxvhui authored
57
			&models.TaskIgnore{},
tangxvhui authored
58 59 60 61 62 63 64 65 66 67
		}
		for _, model := range tables {
			err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
				Temp:          false,
				IfNotExists:   true,
				FKConstraints: true,
			})
			if err != nil {
				panic(err)
			}
68 69 70 71
			comment.AddComments(DB, model)
		}
	}
tangxvhui authored
72
}