From ca50f9c2f555020a1cdea1bbc746e2bca343b4b4 Mon Sep 17 00:00:00 2001 From: Michal Krzyz Date: Mon, 21 Oct 2024 15:16:54 +0200 Subject: [PATCH] Stage --- internal/api/graphql/graph/model/models.go | 4 +- internal/app/activity/activity_handler.go | 4 +- internal/app/component/component_handler.go | 4 +- .../component_instance_handler.go | 4 +- .../component_version_handler.go | 4 +- internal/app/evidence/evidence_handler.go | 4 +- internal/app/issue/issue_handler.go | 4 +- .../app/issue_match/issue_match_handler.go | 4 +- .../issue_match_change_handler.go | 4 +- .../issue_repository_handler.go | 4 +- .../issue_variant/issue_variant_handler.go | 4 +- internal/app/service/service_handler.go | 4 +- .../support_group/support_group_handler.go | 4 +- internal/app/user/user_handler.go | 4 +- internal/database/mariadb/entity.go | 56 +++++++++---------- internal/database/mariadb/init/schema.sql | 3 - internal/database/mariadb/issue_repository.go | 2 +- internal/database/mariadb/service.go | 2 +- internal/database/mariadb/service_test.go | 4 +- internal/database/mariadb/test/fixture.go | 56 ++++++++++++++----- internal/e2e/issue_query_test.go | 2 - internal/entity/issue_repository.go | 1 - internal/entity/service.go | 1 - 23 files changed, 102 insertions(+), 81 deletions(-) diff --git a/internal/api/graphql/graph/model/models.go b/internal/api/graphql/graph/model/models.go index c79198ca..617bbc6c 100644 --- a/internal/api/graphql/graph/model/models.go +++ b/internal/api/graphql/graph/model/models.go @@ -269,7 +269,7 @@ func NewIssueRepository(repo *entity.IssueRepository) IssueRepository { URL: &repo.Url, Services: nil, IssueVariants: nil, - Metadata: getModelMetadata(repo.Metadata), + Metadata: getModelMetadata(repo.BaseIssueRepository.Metadata), } } @@ -343,7 +343,7 @@ func NewService(s *entity.Service) Service { return Service{ ID: fmt.Sprintf("%d", s.Id), Name: &s.Name, - Metadata: getModelMetadata(s.Metadata), + Metadata: getModelMetadata(s.BaseService.Metadata), } } diff --git a/internal/app/activity/activity_handler.go b/internal/app/activity/activity_handler.go index 152b7ad4..a63f92d5 100644 --- a/internal/app/activity/activity_handler.go +++ b/internal/app/activity/activity_handler.go @@ -138,7 +138,7 @@ func (a *activityHandler) CreateActivity(activity *entity.Activity) (*entity.Act }) var err error - activity.CreatedBy, err = common.GetUserId(a.database, "C1234567") + activity.CreatedBy, err = common.GetUserId(a.database, "S0000000") if err != nil { l.Error(err) return nil, NewActivityHandlerError("Internal error while creating activity (GetUserId).") @@ -165,7 +165,7 @@ func (a *activityHandler) UpdateActivity(activity *entity.Activity) (*entity.Act }) var err error - activity.UpdatedBy, err = common.GetUserId(a.database, "C1234567") + activity.UpdatedBy, err = common.GetUserId(a.database, "S0000000") if err != nil { l.Error(err) return nil, NewActivityHandlerError("Internal error while updating activity (GetUserId).") diff --git a/internal/app/component/component_handler.go b/internal/app/component/component_handler.go index cf9eba87..33fe02c3 100644 --- a/internal/app/component/component_handler.go +++ b/internal/app/component/component_handler.go @@ -116,7 +116,7 @@ func (cs *componentHandler) CreateComponent(component *entity.Component) (*entit }) var err error - component.CreatedBy, err = common.GetUserId(cs.database, "C1234567") + component.CreatedBy, err = common.GetUserId(cs.database, "S0000000") if err != nil { l.Error(err) return nil, NewUserHandlerError("Internal error while creating component (GetUserId).") @@ -152,7 +152,7 @@ func (cs *componentHandler) UpdateComponent(component *entity.Component) (*entit }) var err error - component.UpdatedBy, err = common.GetUserId(cs.database, "C1234567") + component.UpdatedBy, err = common.GetUserId(cs.database, "S0000000") if err != nil { l.Error(err) return nil, NewUserHandlerError("Internal error while updating component (GetUserId).") diff --git a/internal/app/component_instance/component_instance_handler.go b/internal/app/component_instance/component_instance_handler.go index 2981c4c4..9109897a 100644 --- a/internal/app/component_instance/component_instance_handler.go +++ b/internal/app/component_instance/component_instance_handler.go @@ -117,7 +117,7 @@ func (ci *componentInstanceHandler) CreateComponentInstance(componentInstance *e }) var err error - componentInstance.CreatedBy, err = common.GetUserId(ci.database, "C1234567") + componentInstance.CreatedBy, err = common.GetUserId(ci.database, "S0000000") if err != nil { l.Error(err) return nil, NewComponentInstanceHandlerError("Internal error while creating componentInstance (GetUserId).") @@ -144,7 +144,7 @@ func (ci *componentInstanceHandler) UpdateComponentInstance(componentInstance *e }) var err error - componentInstance.UpdatedBy, err = common.GetUserId(ci.database, "C7654321") + componentInstance.UpdatedBy, err = common.GetUserId(ci.database, "S0000000") if err != nil { l.Error(err) return nil, NewComponentInstanceHandlerError("Internal error while updating componentInstance (GetUserId).") diff --git a/internal/app/component_version/component_version_handler.go b/internal/app/component_version/component_version_handler.go index 79ed0448..789124a0 100644 --- a/internal/app/component_version/component_version_handler.go +++ b/internal/app/component_version/component_version_handler.go @@ -115,7 +115,7 @@ func (cv *componentVersionHandler) CreateComponentVersion(componentVersion *enti }) var err error - componentVersion.CreatedBy, err = common.GetUserId(cv.database, "C1234567") + componentVersion.CreatedBy, err = common.GetUserId(cv.database, "S0000000") if err != nil { l.Error(err) return nil, NewComponentVersionHandlerError("Internal error while creating componentVersion (GetUserId).") @@ -142,7 +142,7 @@ func (cv *componentVersionHandler) UpdateComponentVersion(componentVersion *enti }) var err error - componentVersion.UpdatedBy, err = common.GetUserId(cv.database, "C7654321") + componentVersion.UpdatedBy, err = common.GetUserId(cv.database, "S0000000") if err != nil { l.Error(err) return nil, NewComponentVersionHandlerError("Internal error while updating componentVersion (GetUserId).") diff --git a/internal/app/evidence/evidence_handler.go b/internal/app/evidence/evidence_handler.go index 9b658f57..a7c553de 100644 --- a/internal/app/evidence/evidence_handler.go +++ b/internal/app/evidence/evidence_handler.go @@ -110,7 +110,7 @@ func (e *evidenceHandler) CreateEvidence(evidence *entity.Evidence) (*entity.Evi }) var err error - evidence.CreatedBy, err = common.GetUserId(e.database, "C1234567") + evidence.CreatedBy, err = common.GetUserId(e.database, "S0000000") if err != nil { l.Error(err) return nil, NewEvidenceHandlerError("Internal error while creating evidence (GetUserId).") @@ -135,7 +135,7 @@ func (e *evidenceHandler) UpdateEvidence(evidence *entity.Evidence) (*entity.Evi }) var err error - evidence.UpdatedBy, err = common.GetUserId(e.database, "C7654321") + evidence.UpdatedBy, err = common.GetUserId(e.database, "S0000000") if err != nil { l.Error(err) return nil, NewEvidenceHandlerError("Internal error while updating evidence (GetUserId).") diff --git a/internal/app/issue/issue_handler.go b/internal/app/issue/issue_handler.go index 341d9133..ed0fa895 100644 --- a/internal/app/issue/issue_handler.go +++ b/internal/app/issue/issue_handler.go @@ -171,7 +171,7 @@ func (is *issueHandler) CreateIssue(issue *entity.Issue) (*entity.Issue, error) }) var err error - issue.CreatedBy, err = common.GetUserId(is.database, "C1234567") + issue.CreatedBy, err = common.GetUserId(is.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueHandlerError("Internal error while creating issue (GetUserId).") @@ -206,7 +206,7 @@ func (is *issueHandler) UpdateIssue(issue *entity.Issue) (*entity.Issue, error) }) var err error - issue.UpdatedBy, err = common.GetUserId(is.database, "C7654321") + issue.UpdatedBy, err = common.GetUserId(is.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueHandlerError("Internal error while updating issue (GetUserId).") diff --git a/internal/app/issue_match/issue_match_handler.go b/internal/app/issue_match/issue_match_handler.go index c9a02587..7fd1b18b 100644 --- a/internal/app/issue_match/issue_match_handler.go +++ b/internal/app/issue_match/issue_match_handler.go @@ -142,7 +142,7 @@ func (im *issueMatchHandler) CreateIssueMatch(issueMatch *entity.IssueMatch) (*e }) var err error - issueMatch.CreatedBy, err = common.GetUserId(im.database, "C1234567") + issueMatch.CreatedBy, err = common.GetUserId(im.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueMatchHandlerError("Internal error while retrieving effective severity (GetUserId).") @@ -183,7 +183,7 @@ func (im *issueMatchHandler) UpdateIssueMatch(issueMatch *entity.IssueMatch) (*e }) var err error - issueMatch.UpdatedBy, err = common.GetUserId(im.database, "C7654321") + issueMatch.UpdatedBy, err = common.GetUserId(im.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueMatchHandlerError("Internal error while retrieving effective severity (GetUserId).") diff --git a/internal/app/issue_match_change/issue_match_change_handler.go b/internal/app/issue_match_change/issue_match_change_handler.go index cd1dc23d..76004cc4 100644 --- a/internal/app/issue_match_change/issue_match_change_handler.go +++ b/internal/app/issue_match_change/issue_match_change_handler.go @@ -114,7 +114,7 @@ func (imc *issueMatchChangeHandler) CreateIssueMatchChange(issueMatchChange *ent }) var err error - issueMatchChange.CreatedBy, err = common.GetUserId(imc.database, "C1234567") + issueMatchChange.CreatedBy, err = common.GetUserId(imc.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueMatchChangeHandlerError("Internal error while creating issueMatchChange (GetUserId).") @@ -141,7 +141,7 @@ func (imc *issueMatchChangeHandler) UpdateIssueMatchChange(issueMatchChange *ent }) var err error - issueMatchChange.UpdatedBy, err = common.GetUserId(imc.database, "C7654321") + issueMatchChange.UpdatedBy, err = common.GetUserId(imc.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueMatchChangeHandlerError("Internal error while updating issueMatchChange (GetUserId).") diff --git a/internal/app/issue_repository/issue_repository_handler.go b/internal/app/issue_repository/issue_repository_handler.go index 138fe386..94859014 100644 --- a/internal/app/issue_repository/issue_repository_handler.go +++ b/internal/app/issue_repository/issue_repository_handler.go @@ -113,7 +113,7 @@ func (ir *issueRepositoryHandler) CreateIssueRepository(issueRepository *entity. }) var err error - issueRepository.CreatedBy, err = common.GetUserId(ir.database, "C1234567") + issueRepository.BaseIssueRepository.CreatedBy, err = common.GetUserId(ir.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueRepositoryHandlerError("Internal error while creating issueRepository (GetUserId).") @@ -150,7 +150,7 @@ func (ir *issueRepositoryHandler) UpdateIssueRepository(issueRepository *entity. }) var err error - issueRepository.UpdatedBy, err = common.GetUserId(ir.database, "C7654321") + issueRepository.BaseIssueRepository.UpdatedBy, err = common.GetUserId(ir.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueRepositoryHandlerError("Internal error while updating issueRepository (GetUserId).") diff --git a/internal/app/issue_variant/issue_variant_handler.go b/internal/app/issue_variant/issue_variant_handler.go index 460e0bf9..da6afbf1 100644 --- a/internal/app/issue_variant/issue_variant_handler.go +++ b/internal/app/issue_variant/issue_variant_handler.go @@ -179,7 +179,7 @@ func (iv *issueVariantHandler) CreateIssueVariant(issueVariant *entity.IssueVari }) var err error - issueVariant.CreatedBy, err = common.GetUserId(iv.database, "C1234567") + issueVariant.CreatedBy, err = common.GetUserId(iv.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueVariantHandlerError("Internal error while creating issueVariant (GetUserId).") @@ -216,7 +216,7 @@ func (iv *issueVariantHandler) UpdateIssueVariant(issueVariant *entity.IssueVari }) var err error - issueVariant.UpdatedBy, err = common.GetUserId(iv.database, "C7654321") + issueVariant.UpdatedBy, err = common.GetUserId(iv.database, "S0000000") if err != nil { l.Error(err) return nil, NewIssueVariantHandlerError("Internal error while updating issueVariant (GetUserId).") diff --git a/internal/app/service/service_handler.go b/internal/app/service/service_handler.go index bdfd56a9..b5a54cb0 100644 --- a/internal/app/service/service_handler.go +++ b/internal/app/service/service_handler.go @@ -136,7 +136,7 @@ func (s *serviceHandler) CreateService(service *entity.Service) (*entity.Service }) var err error - service.CreatedBy, err = common.GetUserId(s.database, "C1234567") + service.BaseService.CreatedBy, err = common.GetUserId(s.database, "S0000000") if err != nil { l.Error(err) return nil, NewServiceHandlerError("Internal error while creating service (GetUserId).") @@ -172,7 +172,7 @@ func (s *serviceHandler) UpdateService(service *entity.Service) (*entity.Service }) var err error - service.UpdatedBy, err = common.GetUserId(s.database, "C7654321") + service.BaseService.UpdatedBy, err = common.GetUserId(s.database, "S0000000") if err != nil { l.Error(err) return nil, NewServiceHandlerError("Internal error while updating service (GetUserId).") diff --git a/internal/app/support_group/support_group_handler.go b/internal/app/support_group/support_group_handler.go index 8fd867a6..a3fd1721 100644 --- a/internal/app/support_group/support_group_handler.go +++ b/internal/app/support_group/support_group_handler.go @@ -143,7 +143,7 @@ func (sg *supportGroupHandler) CreateSupportGroup(supportGroup *entity.SupportGr } var err error - supportGroup.CreatedBy, err = common.GetUserId(sg.database, "C1234567") + supportGroup.CreatedBy, err = common.GetUserId(sg.database, "S0000000") if err != nil { l.Error(err) return nil, NewSupportGroupHandlerError("Internal error while creating supportGroup (GetUserId).") @@ -181,7 +181,7 @@ func (sg *supportGroupHandler) UpdateSupportGroup(supportGroup *entity.SupportGr }) var err error - supportGroup.UpdatedBy, err = common.GetUserId(sg.database, "C7654321") + supportGroup.UpdatedBy, err = common.GetUserId(sg.database, "S0000000") if err != nil { l.Error(err) return nil, NewSupportGroupHandlerError("Internal error while updating supportGroup (GetUserId).") diff --git a/internal/app/user/user_handler.go b/internal/app/user/user_handler.go index db10b3a8..40a05a09 100644 --- a/internal/app/user/user_handler.go +++ b/internal/app/user/user_handler.go @@ -113,7 +113,7 @@ func (u *userHandler) CreateUser(user *entity.User) (*entity.User, error) { }) var err error - user.CreatedBy, err = common.GetUserId(u.database, "C1234567") + user.CreatedBy, err = common.GetUserId(u.database, "S0000000") if err != nil { l.Error(err) return nil, NewUserHandlerError("Internal error while creating user (GetUserId).") @@ -149,7 +149,7 @@ func (u *userHandler) UpdateUser(user *entity.User) (*entity.User, error) { }) var err error - user.UpdatedBy, err = common.GetUserId(u.database, "C7654321") + user.UpdatedBy, err = common.GetUserId(u.database, "S0000000") if err != nil { l.Error(err) return nil, NewUserHandlerError("Internal error while updating user (GetUserId).") diff --git a/internal/database/mariadb/entity.go b/internal/database/mariadb/entity.go index 0ef6c432..9ff2dfb0 100644 --- a/internal/database/mariadb/entity.go +++ b/internal/database/mariadb/entity.go @@ -197,7 +197,7 @@ func (ir *IssueRow) FromIssue(i *entity.Issue) { ir.CreatedBy = sql.NullInt64{Int64: i.CreatedBy, Valid: true} ir.DeletedAt = sql.NullTime{Time: i.DeletedAt, Valid: true} ir.UpdatedAt = sql.NullTime{Time: i.UpdatedAt, Valid: true} - ir.UpdatedBy = sql.NullInt64{Int64: i.UpdatedBy, Valid: false} + ir.UpdatedBy = sql.NullInt64{Int64: i.UpdatedBy, Valid: true} } type IssueMatchRow struct { @@ -251,10 +251,10 @@ func (imr *IssueMatchRow) FromIssueMatch(im *entity.IssueMatch) { imr.RemediationDate = sql.NullTime{Time: im.RemediationDate, Valid: true} imr.TargetRemediationDate = sql.NullTime{Time: im.TargetRemediationDate, Valid: true} imr.CreatedAt = sql.NullTime{Time: im.CreatedAt, Valid: true} - imr.CreatedBy = sql.NullInt64{Int64: im.CreatedBy, Valid: false} + imr.CreatedBy = sql.NullInt64{Int64: im.CreatedBy, Valid: true} imr.DeletedAt = sql.NullTime{Time: im.DeletedAt, Valid: true} imr.UpdatedAt = sql.NullTime{Time: im.UpdatedAt, Valid: true} - imr.UpdatedBy = sql.NullInt64{Int64: im.UpdatedBy, Valid: false} + imr.UpdatedBy = sql.NullInt64{Int64: im.UpdatedBy, Valid: true} } type IssueRepositoryRow struct { @@ -280,11 +280,11 @@ func (irr *IssueRepositoryRow) FromIssueRepository(ir *entity.IssueRepository) { irr.Priority = sql.NullInt64{Int64: ir.Priority, Valid: true} irr.ServiceId = sql.NullInt64{Int64: ir.ServiceId, Valid: true} irr.IssueRepositoryId = sql.NullInt64{Int64: ir.IssueRepositoryId, Valid: true} - irr.BaseIssueRepositoryRow.CreatedAt = sql.NullTime{Time: ir.CreatedAt, Valid: true} - irr.BaseIssueRepositoryRow.CreatedBy = sql.NullInt64{Int64: ir.CreatedBy, Valid: false} - irr.BaseIssueRepositoryRow.DeletedAt = sql.NullTime{Time: ir.DeletedAt, Valid: true} - irr.BaseIssueRepositoryRow.UpdatedAt = sql.NullTime{Time: ir.UpdatedAt, Valid: true} - irr.BaseIssueRepositoryRow.UpdatedBy = sql.NullInt64{Int64: ir.UpdatedBy, Valid: false} + irr.BaseIssueRepositoryRow.CreatedAt = sql.NullTime{Time: ir.BaseIssueRepository.CreatedAt, Valid: true} + irr.BaseIssueRepositoryRow.CreatedBy = sql.NullInt64{Int64: ir.BaseIssueRepository.CreatedBy, Valid: true} + irr.BaseIssueRepositoryRow.DeletedAt = sql.NullTime{Time: ir.BaseIssueRepository.DeletedAt, Valid: true} + irr.BaseIssueRepositoryRow.UpdatedAt = sql.NullTime{Time: ir.BaseIssueRepository.UpdatedAt, Valid: true} + irr.BaseIssueRepositoryRow.UpdatedBy = sql.NullInt64{Int64: ir.BaseIssueRepository.UpdatedBy, Valid: true} } func (birr *BaseIssueRepositoryRow) AsBaseIssueRepository() entity.BaseIssueRepository { @@ -390,10 +390,10 @@ func (ivr *IssueVariantRow) FromIssueVariant(iv *entity.IssueVariant) { ivr.Rating = sql.NullString{String: iv.Severity.Value, Valid: true} ivr.Description = sql.NullString{String: iv.Description, Valid: true} ivr.CreatedAt = sql.NullTime{Time: iv.CreatedAt, Valid: true} - ivr.CreatedBy = sql.NullInt64{Int64: iv.CreatedBy, Valid: false} + ivr.CreatedBy = sql.NullInt64{Int64: iv.CreatedBy, Valid: true} ivr.DeletedAt = sql.NullTime{Time: iv.DeletedAt, Valid: true} ivr.UpdatedAt = sql.NullTime{Time: iv.UpdatedAt, Valid: true} - ivr.UpdatedBy = sql.NullInt64{Int64: iv.UpdatedBy, Valid: false} + ivr.UpdatedBy = sql.NullInt64{Int64: iv.UpdatedBy, Valid: true} } type IssueVariantWithRepository struct { @@ -451,10 +451,10 @@ func (cr *ComponentRow) FromComponent(c *entity.Component) { cr.Name = sql.NullString{String: c.Name, Valid: true} cr.Type = sql.NullString{String: c.Type, Valid: true} cr.CreatedAt = sql.NullTime{Time: c.CreatedAt, Valid: true} - cr.CreatedBy = sql.NullInt64{Int64: c.CreatedBy, Valid: false} + cr.CreatedBy = sql.NullInt64{Int64: c.CreatedBy, Valid: true} cr.DeletedAt = sql.NullTime{Time: c.DeletedAt, Valid: true} cr.UpdatedAt = sql.NullTime{Time: c.UpdatedAt, Valid: true} - cr.UpdatedBy = sql.NullInt64{Int64: c.UpdatedBy, Valid: false} + cr.UpdatedBy = sql.NullInt64{Int64: c.UpdatedBy, Valid: true} } type ComponentVersionRow struct { @@ -488,10 +488,10 @@ func (cvr *ComponentVersionRow) FromComponentVersion(cv *entity.ComponentVersion cvr.Version = sql.NullString{String: cv.Version, Valid: true} cvr.ComponentId = sql.NullInt64{Int64: cv.ComponentId, Valid: true} cvr.CreatedAt = sql.NullTime{Time: cv.CreatedAt, Valid: true} - cvr.CreatedBy = sql.NullInt64{Int64: cv.CreatedBy, Valid: false} + cvr.CreatedBy = sql.NullInt64{Int64: cv.CreatedBy, Valid: true} cvr.DeletedAt = sql.NullTime{Time: cv.DeletedAt, Valid: true} cvr.UpdatedAt = sql.NullTime{Time: cv.UpdatedAt, Valid: true} - cvr.UpdatedBy = sql.NullInt64{Int64: cv.UpdatedBy, Valid: false} + cvr.UpdatedBy = sql.NullInt64{Int64: cv.UpdatedBy, Valid: true} } type SupportGroupRow struct { @@ -522,10 +522,10 @@ func (sgr *SupportGroupRow) FromSupportGroup(sg *entity.SupportGroup) { sgr.Id = sql.NullInt64{Int64: sg.Id, Valid: true} sgr.Name = sql.NullString{String: sg.Name, Valid: true} sgr.CreatedAt = sql.NullTime{Time: sg.CreatedAt, Valid: true} - sgr.CreatedBy = sql.NullInt64{Int64: sg.CreatedBy, Valid: false} + sgr.CreatedBy = sql.NullInt64{Int64: sg.CreatedBy, Valid: true} sgr.DeletedAt = sql.NullTime{Time: sg.DeletedAt, Valid: true} sgr.UpdatedAt = sql.NullTime{Time: sg.UpdatedAt, Valid: true} - sgr.UpdatedBy = sql.NullInt64{Int64: sg.UpdatedBy, Valid: false} + sgr.UpdatedBy = sql.NullInt64{Int64: sg.UpdatedBy, Valid: true} } type ServiceRow struct { @@ -592,10 +592,10 @@ func (sr *ServiceRow) FromService(s *entity.Service) { sr.Id = sql.NullInt64{Int64: s.Id, Valid: true} sr.Name = sql.NullString{String: s.Name, Valid: true} sr.BaseServiceRow.CreatedAt = sql.NullTime{Time: s.BaseService.CreatedAt, Valid: true} - sr.BaseServiceRow.CreatedBy = sql.NullInt64{Int64: s.BaseService.CreatedBy, Valid: false} + sr.BaseServiceRow.CreatedBy = sql.NullInt64{Int64: s.BaseService.CreatedBy, Valid: true} sr.BaseServiceRow.DeletedAt = sql.NullTime{Time: s.BaseService.DeletedAt, Valid: true} sr.BaseServiceRow.UpdatedAt = sql.NullTime{Time: s.BaseService.UpdatedAt, Valid: true} - sr.BaseServiceRow.UpdatedBy = sql.NullInt64{Int64: s.BaseService.UpdatedBy, Valid: false} + sr.BaseServiceRow.UpdatedBy = sql.NullInt64{Int64: s.BaseService.UpdatedBy, Valid: true} } type ActivityRow struct { @@ -628,10 +628,10 @@ func (ar *ActivityRow) FromActivity(a *entity.Activity) { ar.Id = sql.NullInt64{Int64: a.Id, Valid: true} ar.Status = sql.NullString{String: a.Status.String(), Valid: true} ar.CreatedAt = sql.NullTime{Time: a.CreatedAt, Valid: true} - ar.CreatedBy = sql.NullInt64{Int64: a.CreatedBy, Valid: false} + ar.CreatedBy = sql.NullInt64{Int64: a.CreatedBy, Valid: true} ar.DeletedAt = sql.NullTime{Time: a.DeletedAt, Valid: true} ar.UpdatedAt = sql.NullTime{Time: a.UpdatedAt, Valid: true} - ar.UpdatedBy = sql.NullInt64{Int64: a.UpdatedBy, Valid: false} + ar.UpdatedBy = sql.NullInt64{Int64: a.UpdatedBy, Valid: true} } type ComponentInstanceRow struct { @@ -673,10 +673,10 @@ func (cir *ComponentInstanceRow) FromComponentInstance(ci *entity.ComponentInsta cir.ComponentVersionId = sql.NullInt64{Int64: ci.ComponentVersionId, Valid: true} cir.ServiceId = sql.NullInt64{Int64: ci.ServiceId, Valid: true} cir.CreatedAt = sql.NullTime{Time: ci.CreatedAt, Valid: true} - cir.CreatedBy = sql.NullInt64{Int64: ci.CreatedBy, Valid: false} + cir.CreatedBy = sql.NullInt64{Int64: ci.CreatedBy, Valid: true} cir.DeletedAt = sql.NullTime{Time: ci.DeletedAt, Valid: true} cir.UpdatedAt = sql.NullTime{Time: ci.UpdatedAt, Valid: true} - cir.UpdatedBy = sql.NullInt64{Int64: ci.UpdatedBy, Valid: false} + cir.UpdatedBy = sql.NullInt64{Int64: ci.UpdatedBy, Valid: true} } type UserRow struct { @@ -713,10 +713,10 @@ func (ur *UserRow) FromUser(u *entity.User) { ur.UniqueUserID = sql.NullString{String: u.UniqueUserID, Valid: true} ur.Type = sql.NullInt64{Int64: int64(u.Type), Valid: true} ur.CreatedAt = sql.NullTime{Time: u.CreatedAt, Valid: true} - ur.CreatedBy = sql.NullInt64{Int64: u.CreatedBy, Valid: false} + ur.CreatedBy = sql.NullInt64{Int64: u.CreatedBy, Valid: true} ur.DeletedAt = sql.NullTime{Time: u.DeletedAt, Valid: true} ur.UpdatedAt = sql.NullTime{Time: u.UpdatedAt, Valid: true} - ur.UpdatedBy = sql.NullInt64{Int64: u.UpdatedBy, Valid: false} + ur.UpdatedBy = sql.NullInt64{Int64: u.UpdatedBy, Valid: true} } type EvidenceRow struct { @@ -768,10 +768,10 @@ func (er *EvidenceRow) FromEvidence(e *entity.Evidence) { er.UserId = sql.NullInt64{Int64: e.UserId, Valid: true} er.ActivityId = sql.NullInt64{Int64: e.ActivityId, Valid: true} er.CreatedAt = sql.NullTime{Time: e.CreatedAt, Valid: true} - er.CreatedBy = sql.NullInt64{Int64: e.CreatedBy, Valid: false} + er.CreatedBy = sql.NullInt64{Int64: e.CreatedBy, Valid: true} er.DeletedAt = sql.NullTime{Time: e.DeletedAt, Valid: true} er.UpdatedAt = sql.NullTime{Time: e.UpdatedAt, Valid: true} - er.UpdatedBy = sql.NullInt64{Int64: e.UpdatedBy, Valid: false} + er.UpdatedBy = sql.NullInt64{Int64: e.UpdatedBy, Valid: true} } type IssueMatchChangeRow struct { @@ -808,10 +808,10 @@ func (imcr *IssueMatchChangeRow) FromIssueMatchChange(imc *entity.IssueMatchChan imcr.ActivityId = sql.NullInt64{Int64: imc.ActivityId, Valid: true} imcr.Action = sql.NullString{String: imc.Action, Valid: true} imcr.CreatedAt = sql.NullTime{Time: imc.CreatedAt, Valid: true} - imcr.CreatedBy = sql.NullInt64{Int64: imc.CreatedBy, Valid: false} + imcr.CreatedBy = sql.NullInt64{Int64: imc.CreatedBy, Valid: true} imcr.DeletedAt = sql.NullTime{Time: imc.DeletedAt, Valid: true} imcr.UpdatedAt = sql.NullTime{Time: imc.UpdatedAt, Valid: true} - imcr.UpdatedBy = sql.NullInt64{Int64: imc.UpdatedBy, Valid: false} + imcr.UpdatedBy = sql.NullInt64{Int64: imc.UpdatedBy, Valid: true} } type OwnerRow struct { diff --git a/internal/database/mariadb/init/schema.sql b/internal/database/mariadb/init/schema.sql index de7e676f..da7259b3 100644 --- a/internal/database/mariadb/init/schema.sql +++ b/internal/database/mariadb/init/schema.sql @@ -439,9 +439,6 @@ create table if not exists IssueRepositoryService issuerepositoryservice_service_id int unsigned not null, issuerepositoryservice_issue_repository_id int unsigned not null, issuerepositoryservice_priority int unsigned not null, - issuerepositoryservice_created_at timestamp default current_timestamp() not null, - issuerepositoryservice_deleted_at timestamp null, - issuerepositoryservice_updated_at timestamp default current_timestamp() not null on update current_timestamp(), primary key (issuerepositoryservice_service_id, issuerepositoryservice_issue_repository_id), constraint fk_issue_repository_service foreign key (issuerepositoryservice_issue_repository_id) references IssueRepository (issuerepository_id) diff --git a/internal/database/mariadb/issue_repository.go b/internal/database/mariadb/issue_repository.go index ee466909..34ee34b1 100644 --- a/internal/database/mariadb/issue_repository.go +++ b/internal/database/mariadb/issue_repository.go @@ -46,7 +46,7 @@ func (s *SqlDatabase) getIssueRepositoryUpdateFields(issueRepository *entity.Iss if issueRepository.Url != "" { fl = append(fl, "issuerepository_url = :issuerepository_url") } - if issueRepository.UpdatedBy != 0 { + if issueRepository.BaseIssueRepository.UpdatedBy != 0 { fl = append(fl, "issuerepository_updated_by = :issuerepository_updated_by") } return strings.Join(fl, ", ") diff --git a/internal/database/mariadb/service.go b/internal/database/mariadb/service.go index 7c45a222..458d970a 100644 --- a/internal/database/mariadb/service.go +++ b/internal/database/mariadb/service.go @@ -115,7 +115,7 @@ func (s *SqlDatabase) getServiceUpdateFields(service *entity.Service) string { if service.Name != "" { fl = append(fl, "service_name = :service_name") } - if service.UpdatedBy != 0 { + if service.BaseService.UpdatedBy != 0 { fl = append(fl, "service_updated_by = :service_updated_by") } return strings.Join(fl, ", ") diff --git a/internal/database/mariadb/service_test.go b/internal/database/mariadb/service_test.go index 3dee040b..d4a8df2e 100644 --- a/internal/database/mariadb/service_test.go +++ b/internal/database/mariadb/service_test.go @@ -716,7 +716,9 @@ var _ = Describe("Service", Label("database", "Service"), func() { seedCollection = seeder.SeedDbWithNFakeData(10) newIssueRepositoryRow = test.NewFakeIssueRepository() newIssueRepository = newIssueRepositoryRow.AsIssueRepository() - issueRepository, _ = db.CreateIssueRepository(&newIssueRepository) + var err error + issueRepository, err = db.CreateIssueRepository(&newIssueRepository) + Expect(err).To(BeNil()) }) It("can add issue repository correctly", func() { service := seedCollection.ServiceRows[0].AsService() diff --git a/internal/database/mariadb/test/fixture.go b/internal/database/mariadb/test/fixture.go index fd80a613..85724d82 100644 --- a/internal/database/mariadb/test/fixture.go +++ b/internal/database/mariadb/test/fixture.go @@ -418,8 +418,10 @@ func (s *DatabaseSeeder) SeedIssueRepositories() []mariadb.BaseIssueRepositoryRo i := 0 for _, name := range variants { row := mariadb.BaseIssueRepositoryRow{ - Name: sql.NullString{String: name, Valid: true}, - Url: sql.NullString{String: gofakeit.URL(), Valid: true}, + Name: sql.NullString{String: name, Valid: true}, + Url: sql.NullString{String: gofakeit.URL(), Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } id, err := s.InsertFakeBaseIssueRepository(row) if err != nil { @@ -1124,6 +1126,8 @@ func NewFakeIssueMatch() mariadb.IssueMatchRow { Rating: sql.NullString{String: rating, Valid: true}, RemediationDate: sql.NullTime{Time: gofakeit.Date(), Valid: true}, TargetRemediationDate: sql.NullTime{Time: gofakeit.Date(), Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } @@ -1133,6 +1137,7 @@ func NewFakeIssue() mariadb.IssueRow { Description: sql.NullString{String: gofakeit.HackerPhrase(), Valid: true}, Type: sql.NullString{String: gofakeit.RandomString(entity.AllIssueTypes), Valid: true}, CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } @@ -1154,21 +1159,27 @@ func NewFakeIssueVariant(repos []mariadb.BaseIssueRepositoryRow, disc []mariadb. Int64: disc[rand.Intn(len(disc))].Id.Int64, Valid: true, }, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } func NewFakeIssueRepository() mariadb.IssueRepositoryRow { return mariadb.IssueRepositoryRow{ BaseIssueRepositoryRow: mariadb.BaseIssueRepositoryRow{ - Name: sql.NullString{String: gofakeit.AppName(), Valid: true}, - Url: sql.NullString{String: gofakeit.URL(), Valid: true}, + Name: sql.NullString{String: gofakeit.AppName(), Valid: true}, + Url: sql.NullString{String: gofakeit.URL(), Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, }, } } func NewFakeBaseService() mariadb.BaseServiceRow { return mariadb.BaseServiceRow{ - Name: sql.NullString{String: gofakeit.AppName(), Valid: true}, + Name: sql.NullString{String: gofakeit.AppName(), Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } @@ -1183,7 +1194,9 @@ func NewFakeService() mariadb.ServiceRow { func NewFakeSupportGroup() mariadb.SupportGroupRow { return mariadb.SupportGroupRow{ - Name: sql.NullString{String: gofakeit.AppName(), Valid: true}, + Name: sql.NullString{String: gofakeit.AppName(), Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } @@ -1191,14 +1204,18 @@ func NewFakeComponent() mariadb.ComponentRow { types := []string{"containerImage", "virtualMachineImage", "repository"} name := fmt.Sprintf("%s-%d", gofakeit.AppName(), gofakeit.Number(0, 99999)) return mariadb.ComponentRow{ - Name: sql.NullString{String: name, Valid: true}, - Type: sql.NullString{String: gofakeit.RandomString(types), Valid: true}, + Name: sql.NullString{String: name, Valid: true}, + Type: sql.NullString{String: gofakeit.RandomString(types), Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } func NewFakeComponentVersion() mariadb.ComponentVersionRow { return mariadb.ComponentVersionRow{ - Version: sql.NullString{String: gofakeit.AppVersion(), Valid: true}, + Version: sql.NullString{String: gofakeit.AppVersion(), Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } @@ -1208,8 +1225,10 @@ func NewFakeComponentInstance() mariadb.ComponentInstanceRow { n = n * -1 } return mariadb.ComponentInstanceRow{ - CCRN: sql.NullString{String: gofakeit.UUID(), Valid: true}, - Count: sql.NullInt16{Int16: n, Valid: true}, + CCRN: sql.NullString{String: gofakeit.UUID(), Valid: true}, + Count: sql.NullInt16{Int16: n, Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } @@ -1232,6 +1251,7 @@ func NewFakeUser() mariadb.UserRow { UniqueUserID: sql.NullString{String: uniqueUserId, Valid: true}, Type: sql.NullInt64{Int64: getNextUserType(), Valid: true}, CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } @@ -1250,7 +1270,9 @@ func NewFakeSupportGroupUser() mariadb.SupportGroupUserRow { func NewFakeActivity() mariadb.ActivityRow { status := []string{"open", "closed", "in_progress"} return mariadb.ActivityRow{ - Status: sql.NullString{String: gofakeit.RandomString(status), Valid: true}, + Status: sql.NullString{String: gofakeit.RandomString(status), Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } @@ -1277,9 +1299,11 @@ func NewFakeEvidence() mariadb.EvidenceRow { String: gofakeit.RandomString(types), Valid: true, }, - Vector: sql.NullString{String: v, Valid: true}, - Rating: sql.NullString{String: rating, Valid: true}, - RAAEnd: sql.NullTime{Time: gofakeit.Date(), Valid: true}, + Vector: sql.NullString{String: v, Valid: true}, + Rating: sql.NullString{String: rating, Valid: true}, + RAAEnd: sql.NullTime{Time: gofakeit.Date(), Valid: true}, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } @@ -1297,6 +1321,8 @@ func NewFakeIssueMatchChange() mariadb.IssueMatchChangeRow { String: gofakeit.RandomString(entity.AllIssueMatchChangeActions), Valid: true, }, + CreatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, + UpdatedBy: sql.NullInt64{Int64: e2e_common.SystemUserId, Valid: true}, } } diff --git a/internal/e2e/issue_query_test.go b/internal/e2e/issue_query_test.go index aa6f24c6..c905542f 100644 --- a/internal/e2e/issue_query_test.go +++ b/internal/e2e/issue_query_test.go @@ -14,7 +14,6 @@ import ( "github.com/cloudoperators/heureka/internal/api/graphql/graph/model" "github.com/cloudoperators/heureka/internal/database/mariadb" "github.com/cloudoperators/heureka/internal/database/mariadb/test" - "github.com/cloudoperators/heureka/internal/e2e/common" "github.com/cloudoperators/heureka/internal/entity" testentity "github.com/cloudoperators/heureka/internal/entity/test" "github.com/cloudoperators/heureka/internal/server" @@ -251,7 +250,6 @@ var _ = Describe("Creating Issue via API", Label("e2e", "Issues"), func() { "primaryName": issue.PrimaryName, "description": issue.Description, "type": issue.Type.String(), - "metadata": map[string]string{"created_by": fmt.Sprintf("%d", e2e_common.SystemUserId)}, }) req.Header.Set("Cache-Control", "no-cache") diff --git a/internal/entity/issue_repository.go b/internal/entity/issue_repository.go index 3d259e3e..cef0b830 100644 --- a/internal/entity/issue_repository.go +++ b/internal/entity/issue_repository.go @@ -39,7 +39,6 @@ type IssueRepositoryAggregations struct { } type IssueRepository struct { - Metadata BaseIssueRepository IssueRepositoryService } diff --git a/internal/entity/service.go b/internal/entity/service.go index 5735bfa3..865d6804 100644 --- a/internal/entity/service.go +++ b/internal/entity/service.go @@ -34,7 +34,6 @@ type ServiceFilter struct { } type Service struct { - Metadata BaseService IssueRepositoryService }