MSP-3428 CRUD application_group, service -> application_group
This commit is contained in:
1 parent
7108122102
commit
bef400d0d9
26 files changed
+559
-395
No files matched your search
@@ -13,10 +13,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
insertDomain = "INSERT INTO %s.domain (id, name, description, system_id) VALUES (%d, '%s', '%s', %d) RETURNING id;"
|
||||
insertService = "INSERT INTO %s.service (id, name, description, domain_id) VALUES (%d, '%s', '%s', %d) RETURNING id;"
|
||||
insertApp = "INSERT INTO %s.application (id, name, description, service_id, type) VALUES (%d, '%s', '%s', %d, '%s') RETURNING id;"
|
||||
insertToken = "INSERT INTO %s.token (token, app_id, expire_time) VALUES ('%s', %d, %d);"
|
||||
insertDomain = "INSERT INTO %s.domain (id, name, description, system_id) VALUES (%d, '%s', '%s', %d) RETURNING id;"
|
||||
insertApplicationGroup = "INSERT INTO %s.application_group (id, name, description, domain_id) VALUES (%d, '%s', '%s', %d) RETURNING id;"
|
||||
insertApp = "INSERT INTO %s.application (id, name, description, application_group_id, type) VALUES (%d, '%s', '%s', %d, '%s') RETURNING id;"
|
||||
insertToken = "INSERT INTO %s.token (token, app_id, expire_time) VALUES ('%s', %d, %d);"
|
||||
|
||||
setSeqQuery = "SELECT setval('%s.%s_id_seq' :: regclass, %d);"
|
||||
|
||||
@@ -35,9 +35,9 @@ type initializeMigration struct {
|
||||
}
|
||||
|
||||
type identity struct {
|
||||
domainId int
|
||||
appId int
|
||||
serviceId int
|
||||
domainId int
|
||||
appId int
|
||||
applicationGroupId int
|
||||
}
|
||||
|
||||
func (i *initializeMigration) SetParams(migrationDir string, schema string) {
|
||||
@@ -52,14 +52,14 @@ func (i *initializeMigration) Up(tx *sql.Tx) error {
|
||||
return errors.WithMessage(err, "read file")
|
||||
}
|
||||
|
||||
list := make([]domain.DomainWithService, 0)
|
||||
list := make([]domain.DomainWithApplicationGroup, 0)
|
||||
err = json.Unmarshal(bytes, &list)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "json unmarshal")
|
||||
}
|
||||
|
||||
lastDomainId := 0
|
||||
lastServiceId := 0
|
||||
lastApplicationGroupId := 0
|
||||
lastAppId := 0
|
||||
for _, domainInfo := range list {
|
||||
last, err := i.insert(tx, domainInfo)
|
||||
@@ -69,8 +69,8 @@ func (i *initializeMigration) Up(tx *sql.Tx) error {
|
||||
if last.domainId > lastDomainId {
|
||||
lastDomainId = last.domainId
|
||||
}
|
||||
if last.serviceId > lastServiceId {
|
||||
lastServiceId = last.serviceId
|
||||
if last.applicationGroupId > lastApplicationGroupId {
|
||||
lastApplicationGroupId = last.applicationGroupId
|
||||
}
|
||||
if last.appId > lastAppId {
|
||||
lastAppId = last.appId
|
||||
@@ -82,9 +82,9 @@ func (i *initializeMigration) Up(tx *sql.Tx) error {
|
||||
return errors.WithMessage(err, "set domain")
|
||||
}
|
||||
|
||||
err = i.setSeq(tx, "service", lastServiceId)
|
||||
err = i.setSeq(tx, "application_group", lastApplicationGroupId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "set service")
|
||||
return errors.WithMessage(err, "set application group")
|
||||
}
|
||||
|
||||
err = i.setSeq(tx, "application", lastAppId)
|
||||
@@ -99,22 +99,22 @@ func (i *initializeMigration) Down(tx *sql.Tx) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *initializeMigration) insert(tx *sql.Tx, domainInfo domain.DomainWithService) (*identity, error) {
|
||||
func (i *initializeMigration) insert(tx *sql.Tx, domainInfo domain.DomainWithApplicationGroup) (*identity, error) {
|
||||
domainId, err := i.insertNode(tx, insertDomain, true, i.schema, domainInfo.Id, domainInfo.Name, domainInfo.Description, 1)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "insert domain")
|
||||
}
|
||||
|
||||
serviceId := 0
|
||||
applicationGroupId := 0
|
||||
appId := 0
|
||||
for _, service := range domainInfo.Services {
|
||||
serviceId, err = i.insertNode(tx, insertService, true, i.schema, service.Id, service.Name, service.Description, domainId)
|
||||
for _, applicationGroup := range domainInfo.ApplicationGroup {
|
||||
applicationGroupId, err = i.insertNode(tx, insertApplicationGroup, true, i.schema, applicationGroup.Id, applicationGroup.Name, applicationGroup.Description, domainId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "insert service")
|
||||
return nil, errors.WithMessage(err, "insert application group")
|
||||
}
|
||||
|
||||
for _, app := range service.Apps {
|
||||
appId, err = i.insertNode(tx, insertApp, true, i.schema, app.Id, app.Name, app.Description, serviceId, app.Type)
|
||||
for _, app := range applicationGroup.Apps {
|
||||
appId, err = i.insertNode(tx, insertApp, true, i.schema, app.Id, app.Name, app.Description, applicationGroupId, app.Type)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "insert application")
|
||||
}
|
||||
@@ -129,9 +129,9 @@ func (i *initializeMigration) insert(tx *sql.Tx, domainInfo domain.DomainWithSer
|
||||
}
|
||||
|
||||
return &identity{
|
||||
domainId: domainId,
|
||||
appId: appId,
|
||||
serviceId: serviceId,
|
||||
domainId: domainId,
|
||||
appId: appId,
|
||||
applicationGroupId: applicationGroupId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE service RENAME TO application_group;
|
||||
|
||||
ALTER TABLE application RENAME COLUMN service_id TO application_group_id;
|
||||
|
||||
ALTER TABLE application RENAME CONSTRAINT UQ_name_service_id TO UQ_name_application_group_id;
|
||||
|
||||
ALTER TABLE application RENAME CONSTRAINT FK_service_id__domain_id TO FK_application_group_id__domain_id;
|
||||
|
||||
ALTER TRIGGER modify_service ON application_group RENAME TO modify_application_group;
|
||||
-- +goose Down
|
||||
Reference in new issue
Block a user