Skip to content

Commit

Permalink
feat(authN): Add to all DB entries 'Modified_by'... (#81)
Browse files Browse the repository at this point in the history
Add metadata for componentInstance, componentVersion
  • Loading branch information
michalkrzyz committed Oct 1, 2024
1 parent d6d5698 commit b8d5d0a
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 123 deletions.
234 changes: 129 additions & 105 deletions internal/api/graphql/graph/generated.go

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions internal/api/graphql/graph/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ func NewIssueVariant(issueVariant *entity.IssueVariant) IssueVariant {
func NewIssueVariantEdge(issueVariant *entity.IssueVariant) IssueVariantEdge {
iv := NewIssueVariant(issueVariant)
issueVariantEdge := IssueVariantEdge{
Node: &iv,
Cursor: &iv.ID,
Metadata: getModelMetadata(issueVariant.Metadata),
Node: &iv,
Cursor: &iv.ID,
Metadata: getModelMetadata(issueVariant.Metadata),
}
return issueVariantEdge
}
Expand Down Expand Up @@ -441,6 +441,7 @@ func NewComponentVersion(componentVersion *entity.ComponentVersion) ComponentVer
ID: fmt.Sprintf("%d", componentVersion.Id),
Version: &componentVersion.Version,
ComponentID: util.Ptr(fmt.Sprintf("%d", componentVersion.ComponentId)),
Metadata: getModelMetadata(componentVersion.Metadata),
}
}

Expand All @@ -463,6 +464,7 @@ func NewComponentInstance(componentInstance *entity.ComponentInstance) Component
Count: &count,
ComponentVersionID: util.Ptr(fmt.Sprintf("%d", componentInstance.ComponentVersionId)),
ServiceID: util.Ptr(fmt.Sprintf("%d", componentInstance.ServiceId)),
Metadata: getModelMetadata(componentInstance.Metadata),
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/api/graphql/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ query ($filter: ComponentInstanceFilter, $first: Int, $after: String) {
id
name
}
createdAt
updatedAt
metadata {
created_at
updated_at
}
issueMatches {
totalCount
edges {
Expand Down Expand Up @@ -57,4 +59,4 @@ query ($filter: ComponentInstanceFilter, $first: Int, $after: String) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
componentInstance {
id
count
createdAt
updatedAt
metadata {
created_at
updated_at
}
ccrn
}
}
Expand Down
5 changes: 2 additions & 3 deletions internal/api/graphql/graph/schema/component_instance.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ type ComponentInstance implements Node {
issueMatches(filter: IssueMatchFilter, first: Int, after: String): IssueMatchConnection
serviceId: String
service: Service
createdAt: DateTime
updatedAt: DateTime
metadata: Metadata
}

input ComponentInstanceInput {
Expand All @@ -34,4 +33,4 @@ type ComponentInstanceEdge implements Edge {

input ComponentInstanceFilter {
issueMatchId: [String],
}
}
3 changes: 2 additions & 1 deletion internal/api/graphql/graph/schema/component_version.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type ComponentVersion implements Node {
component: Component
issues(first: Int, after: String): IssueConnection
componentInstances(first: Int, after: String): ComponentInstanceConnection
metadata: Metadata
}

input ComponentVersionInput {
Expand All @@ -29,4 +30,4 @@ type ComponentVersionEdge implements Edge {
input ComponentVersionFilter {
issueId: [String],
version: [String],
}
}
2 changes: 2 additions & 0 deletions internal/app/component_instance/component_instance_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (ci *componentInstanceHandler) ListComponentInstances(filter *entity.Compon
}

func (ci *componentInstanceHandler) CreateComponentInstance(componentInstance *entity.ComponentInstance) (*entity.ComponentInstance, error) {
componentInstance.CreatedBy = "Creator"
l := logrus.WithFields(logrus.Fields{
"event": CreateComponentInstanceEventName,
"object": componentInstance,
Expand All @@ -131,6 +132,7 @@ func (ci *componentInstanceHandler) CreateComponentInstance(componentInstance *e
}

func (ci *componentInstanceHandler) UpdateComponentInstance(componentInstance *entity.ComponentInstance) (*entity.ComponentInstance, error) {
componentInstance.UpdatedBy = "Updater"
l := logrus.WithFields(logrus.Fields{
"event": UpdateComponentInstanceEventName,
"object": componentInstance,
Expand Down
2 changes: 2 additions & 0 deletions internal/app/component_version/component_version_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (cv *componentVersionHandler) ListComponentVersions(filter *entity.Componen
}

func (cv *componentVersionHandler) CreateComponentVersion(componentVersion *entity.ComponentVersion) (*entity.ComponentVersion, error) {
componentVersion.CreatedBy = "Creator"
l := logrus.WithFields(logrus.Fields{
"event": CreateComponentVersionEventName,
"object": componentVersion,
Expand All @@ -129,6 +130,7 @@ func (cv *componentVersionHandler) CreateComponentVersion(componentVersion *enti
}

func (cv *componentVersionHandler) UpdateComponentVersion(componentVersion *entity.ComponentVersion) (*entity.ComponentVersion, error) {
componentVersion.UpdatedBy = "Updater"
l := logrus.WithFields(logrus.Fields{
"event": UpdateComponentVersionEventName,
"object": componentVersion,
Expand Down
10 changes: 8 additions & 2 deletions internal/database/mariadb/component_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (s *SqlDatabase) getComponentInstanceUpdateFields(componentInstance *entity
if componentInstance.ServiceId != 0 {
fl = append(fl, "componentinstance_service_id = :componentinstance_service_id")
}
if componentInstance.UpdatedBy != "" {
fl = append(fl, "componentinstance_updated_by = :componentinstance_updated_by")
}

return strings.Join(fl, ", ")
}

Expand Down Expand Up @@ -208,12 +212,14 @@ func (s *SqlDatabase) CreateComponentInstance(componentInstance *entity.Componen
componentinstance_ccrn,
componentinstance_count,
componentinstance_component_version_id,
componentinstance_service_id
componentinstance_service_id,
componentinstance_created_by
) VALUES (
:componentinstance_ccrn,
:componentinstance_count,
:componentinstance_component_version_id,
:componentinstance_service_id
:componentinstance_service_id,
:componentinstance_created_by
)
`

Expand Down
9 changes: 7 additions & 2 deletions internal/database/mariadb/component_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (s *SqlDatabase) getComponentVersionUpdateFields(componentVersion *entity.C
if componentVersion.ComponentId != 0 {
fl = append(fl, "componentversion_component_id = :componentversion_component_id")
}
if componentVersion.UpdatedBy != "" {
fl = append(fl, "componentversion_updated_by = :componentversion_updated_by")
}
return strings.Join(fl, ", ")
}

Expand Down Expand Up @@ -201,10 +204,12 @@ func (s *SqlDatabase) CreateComponentVersion(componentVersion *entity.ComponentV
query := `
INSERT INTO ComponentVersion (
componentversion_component_id,
componentversion_version
componentversion_version,
componentversion_created_by
) VALUES (
:componentversion_component_id,
:componentversion_version
:componentversion_version,
:componentversion_created_by
)
`

Expand Down
12 changes: 12 additions & 0 deletions internal/database/mariadb/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,10 @@ type ComponentVersionRow struct {
Version sql.NullString `db:"componentversion_version" json:"version"`
ComponentId sql.NullInt64 `db:"componentversion_component_id"`
CreatedAt sql.NullTime `db:"componentversion_created_at" json:"created_at"`
CreatedBy sql.NullString `db:"componentversion_created_by" json:"created_by"`
DeletedAt sql.NullTime `db:"componentversion_deleted_at" json:"deleted_at,omitempty"`
UpdatedAt sql.NullTime `db:"componentversion_updated_at" json:"updated_at"`
UpdatedBy sql.NullString `db:"componentversion_updated_by" json:"updated_by"`
}

func (cvr *ComponentVersionRow) AsComponentVersion() entity.ComponentVersion {
Expand All @@ -457,8 +459,10 @@ func (cvr *ComponentVersionRow) AsComponentVersion() entity.ComponentVersion {
ComponentId: GetInt64Value(cvr.ComponentId),
Metadata: entity.Metadata{
CreatedAt: GetTimeValue(cvr.CreatedAt),
CreatedBy: GetStringValue(cvr.CreatedBy),
DeletedAt: GetTimeValue(cvr.DeletedAt),
UpdatedAt: GetTimeValue(cvr.UpdatedAt),
UpdatedBy: GetStringValue(cvr.UpdatedBy),
},
}
}
Expand All @@ -468,8 +472,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.NullString{String: 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.NullString{String: cv.UpdatedBy, Valid: true}
}

type SupportGroupRow struct {
Expand Down Expand Up @@ -605,8 +611,10 @@ type ComponentInstanceRow struct {
ComponentVersionId sql.NullInt64 `db:"componentinstance_component_version_id"`
ServiceId sql.NullInt64 `db:"componentinstance_service_id"`
CreatedAt sql.NullTime `db:"componentinstance_created_at" json:"created_at"`
CreatedBy sql.NullString `db:"componentinstance_created_by" json:"created_by"`
DeletedAt sql.NullTime `db:"componentinstance_deleted_at" json:"deleted_at,omitempty"`
UpdatedAt sql.NullTime `db:"componentinstance_updated_at" json:"updated_at"`
UpdatedBy sql.NullString `db:"componentinstance_updated_by" json:"udpated_by"`
}

func (cir *ComponentInstanceRow) AsComponentInstance() entity.ComponentInstance {
Expand All @@ -620,8 +628,10 @@ func (cir *ComponentInstanceRow) AsComponentInstance() entity.ComponentInstance
ServiceId: GetInt64Value(cir.ServiceId),
Metadata: entity.Metadata{
CreatedAt: GetTimeValue(cir.CreatedAt),
CreatedBy: GetStringValue(cir.CreatedBy),
DeletedAt: GetTimeValue(cir.DeletedAt),
UpdatedAt: GetTimeValue(cir.UpdatedAt),
UpdatedBy: GetStringValue(cir.UpdatedBy),
},
}
}
Expand All @@ -633,8 +643,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.NullString{String: 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.NullString{String: ci.UpdatedBy, Valid: true}
}

type UserRow struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/database/mariadb/init/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ create table if not exists ComponentVersion
componentversion_version varchar(256) not null,
componentversion_component_id int unsigned not null,
componentversion_created_at timestamp default current_timestamp() not null,
componentversion_created_by varchar(256) null,
componentversion_deleted_at timestamp null,
componentversion_updated_at timestamp default current_timestamp() not null on update current_timestamp(),
componentversion_updated_by varchar(256) null,
constraint id_UNIQUE
unique (componentversion_id),
constraint version_component_unique
Expand Down Expand Up @@ -108,8 +110,10 @@ create table if not exists ComponentInstance
componentinstance_component_version_id int unsigned not null,
componentinstance_service_id int unsigned not null,
componentinstance_created_at timestamp default current_timestamp() not null,
componentinstance_created_by varchar(256) null,
componentinstance_deleted_at timestamp null,
componentinstance_updated_at timestamp default current_timestamp() not null on update current_timestamp(),
componentinstance_updated_by varchar(256) null,
constraint id_UNIQUE
unique (componentinstance_id),
constraint name_service_unique
Expand Down

0 comments on commit b8d5d0a

Please sign in to comment.