Simplify database schema

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-03-11 09:03:13 +01:00
parent 1070bba627
commit c2bf3a42ed
26 changed files with 538 additions and 4144 deletions

View File

@@ -225,13 +225,6 @@ type Control implements Node {
description: String!
state: ControlState!
stateTransisions(
first: Int
after: CursorKey
last: Int
before: CursorKey
): ControlStateTransitionConnection! @goField(forceResolver: true)
tasks(
first: Int
after: CursorKey
@@ -243,25 +236,6 @@ type Control implements Node {
updatedAt: Datetime!
}
type ControlStateTransitionConnection {
edges: [ControlStateTransitionEdge!]!
pageInfo: PageInfo!
}
type ControlStateTransitionEdge {
cursor: CursorKey!
node: ControlStateTransition!
}
type ControlStateTransition {
id: ID!
fromState: ControlState
toState: ControlState!
reason: String
createdAt: Datetime!
updatedAt: Datetime!
}
type TaskConnection {
edges: [TaskEdge!]!
pageInfo: PageInfo!
@@ -274,17 +248,11 @@ type TaskEdge {
type Task implements Node {
id: ID!
version: Int!
name: String!
description: String!
state: TaskState!
stateTransisions(
first: Int
after: CursorKey
last: Int
before: CursorKey
): TaskStateTransitionConnection! @goField(forceResolver: true)
evidences(
first: Int
after: CursorKey
@@ -296,25 +264,6 @@ type Task implements Node {
updatedAt: Datetime!
}
type TaskStateTransitionConnection {
edges: [TaskStateTransitionEdge!]!
pageInfo: PageInfo!
}
type TaskStateTransitionEdge {
cursor: CursorKey!
node: TaskStateTransition!
}
type TaskStateTransition {
id: ID!
fromState: TaskState
toState: TaskState!
reason: String
createdAt: Datetime!
updatedAt: Datetime!
}
type EvidenceConnection {
edges: [EvidenceEdge!]!
pageInfo: PageInfo!
@@ -333,32 +282,6 @@ type Evidence implements Node {
state: EvidenceState!
filename: String!
stateTransisions(
first: Int
after: CursorKey
last: Int
before: CursorKey
): EvidenceStateTransitionConnection! @goField(forceResolver: true)
createdAt: Datetime!
updatedAt: Datetime!
}
type EvidenceStateTransitionConnection {
edges: [EvidenceStateTransitionEdge!]!
pageInfo: PageInfo!
}
type EvidenceStateTransitionEdge {
cursor: CursorKey!
node: EvidenceStateTransition!
}
type EvidenceStateTransition {
id: ID!
fromState: EvidenceState
toState: EvidenceState!
reason: String
createdAt: Datetime!
updatedAt: Datetime!
}
@@ -402,8 +325,8 @@ type Mutation {
deleteOrganization(
input: DeleteOrganizationInput!
): DeleteOrganizationPayload!
updateTaskState(input: UpdateTaskStateInput!): UpdateTaskStatePayload!
createTask(input: CreateTaskInput!): CreateTaskPayload!
updateTask(input: UpdateTaskInput!): UpdateTaskPayload!
deleteTask(input: DeleteTaskInput!): DeleteTaskPayload!
createFramework(input: CreateFrameworkInput!): CreateFrameworkPayload!
createControl(input: CreateControlInput!): CreateControlPayload!
@@ -534,15 +457,6 @@ type DeleteOrganizationPayload {
deletedOrganizationId: ID!
}
input UpdateTaskStateInput {
taskId: ID!
state: TaskState!
}
type UpdateTaskStatePayload {
task: Task!
}
input CreateTaskInput {
controlId: ID!
name: String!
@@ -700,3 +614,15 @@ type PolicyEdge {
cursor: CursorKey!
node: Policy!
}
input UpdateTaskInput {
taskId: ID!
expectedVersion: Int!
name: String
description: String
state: TaskState
}
type UpdateTaskPayload {
task: Task!
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,58 +0,0 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package types
import (
"github.com/getprobo/probo/pkg/page"
"github.com/getprobo/probo/pkg/probo/coredata"
)
func NewControlStateTransitionConnection(
p *page.Page[*coredata.ControlStateTransition],
) *ControlStateTransitionConnection {
var edges = make([]*ControlStateTransitionEdge, len(p.Data))
for i := range edges {
edges[i] = NewControlStateTransitionEdge(p.Data[i])
}
return &ControlStateTransitionConnection{
Edges: edges,
PageInfo: NewPageInfo(p),
}
}
func NewControlStateTransitionEdge(cst *coredata.ControlStateTransition) *ControlStateTransitionEdge {
return &ControlStateTransitionEdge{
Cursor: cst.CursorKey(),
Node: NewControlStateTransition(cst),
}
}
func NewControlStateTransition(cst *coredata.ControlStateTransition) *ControlStateTransition {
var fromState *coredata.ControlState
if cst.FromState != nil {
fromState = cst.FromState
}
return &ControlStateTransition{
ID: cst.ID,
FromState: fromState,
ToState: cst.ToState,
Reason: cst.Reason,
CreatedAt: cst.CreatedAt,
UpdatedAt: cst.UpdatedAt,
}
}

View File

@@ -1,58 +0,0 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package types
import (
"github.com/getprobo/probo/pkg/page"
"github.com/getprobo/probo/pkg/probo/coredata"
)
func NewEvidenceStateTransitionConnection(
p *page.Page[*coredata.EvidenceStateTransition],
) *EvidenceStateTransitionConnection {
var edges = make([]*EvidenceStateTransitionEdge, len(p.Data))
for i := range edges {
edges[i] = NewEvidenceStateTransitionEdge(p.Data[i])
}
return &EvidenceStateTransitionConnection{
Edges: edges,
PageInfo: NewPageInfo(p),
}
}
func NewEvidenceStateTransitionEdge(est *coredata.EvidenceStateTransition) *EvidenceStateTransitionEdge {
return &EvidenceStateTransitionEdge{
Cursor: est.CursorKey(),
Node: NewEvidenceStateTransition(est),
}
}
func NewEvidenceStateTransition(est *coredata.EvidenceStateTransition) *EvidenceStateTransition {
var fromState *coredata.EvidenceState
if est.FromState != nil {
fromState = est.FromState
}
return &EvidenceStateTransition{
ID: est.ID,
FromState: fromState,
ToState: est.ToState,
Reason: est.Reason,
CreatedAt: est.CreatedAt,
UpdatedAt: est.UpdatedAt,
}
}

View File

@@ -47,5 +47,6 @@ func NewTask(t *coredata.Task) *Task {
State: t.State,
CreatedAt: t.CreatedAt,
UpdatedAt: t.UpdatedAt,
Version: t.Version,
}
}

View File

@@ -1,58 +0,0 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package types
import (
"github.com/getprobo/probo/pkg/page"
"github.com/getprobo/probo/pkg/probo/coredata"
)
func NewTaskStateTransitionConnection(
p *page.Page[*coredata.TaskStateTransition],
) *TaskStateTransitionConnection {
var edges = make([]*TaskStateTransitionEdge, len(p.Data))
for i := range edges {
edges[i] = NewTaskStateTransitionEdge(p.Data[i])
}
return &TaskStateTransitionConnection{
Edges: edges,
PageInfo: NewPageInfo(p),
}
}
func NewTaskStateTransitionEdge(tst *coredata.TaskStateTransition) *TaskStateTransitionEdge {
return &TaskStateTransitionEdge{
Cursor: tst.CursorKey(),
Node: NewTaskStateTransition(tst),
}
}
func NewTaskStateTransition(tst *coredata.TaskStateTransition) *TaskStateTransition {
var fromState *coredata.TaskState
if tst.FromState != nil {
fromState = tst.FromState
}
return &TaskStateTransition{
ID: tst.ID,
FromState: fromState,
ToState: tst.ToState,
Reason: tst.Reason,
CreatedAt: tst.CreatedAt,
UpdatedAt: tst.UpdatedAt,
}
}

View File

@@ -17,16 +17,15 @@ type Node interface {
}
type Control struct {
ID gid.GID `json:"id"`
Version int `json:"version"`
Category string `json:"category"`
Name string `json:"name"`
Description string `json:"description"`
State coredata.ControlState `json:"state"`
StateTransisions *ControlStateTransitionConnection `json:"stateTransisions"`
Tasks *TaskConnection `json:"tasks"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID gid.GID `json:"id"`
Version int `json:"version"`
Category string `json:"category"`
Name string `json:"name"`
Description string `json:"description"`
State coredata.ControlState `json:"state"`
Tasks *TaskConnection `json:"tasks"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (Control) IsNode() {}
@@ -42,25 +41,6 @@ type ControlEdge struct {
Node *Control `json:"node"`
}
type ControlStateTransition struct {
ID gid.GID `json:"id"`
FromState *coredata.ControlState `json:"fromState,omitempty"`
ToState coredata.ControlState `json:"toState"`
Reason *string `json:"reason,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type ControlStateTransitionConnection struct {
Edges []*ControlStateTransitionEdge `json:"edges"`
PageInfo *PageInfo `json:"pageInfo"`
}
type ControlStateTransitionEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *ControlStateTransition `json:"node"`
}
type CreateControlInput struct {
FrameworkID gid.GID `json:"frameworkId"`
Name string `json:"name"`
@@ -191,15 +171,14 @@ type DeleteVendorPayload struct {
}
type Evidence struct {
ID gid.GID `json:"id"`
FileURL string `json:"fileUrl"`
MimeType string `json:"mimeType"`
Size int `json:"size"`
State coredata.EvidenceState `json:"state"`
Filename string `json:"filename"`
StateTransisions *EvidenceStateTransitionConnection `json:"stateTransisions"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID gid.GID `json:"id"`
FileURL string `json:"fileUrl"`
MimeType string `json:"mimeType"`
Size int `json:"size"`
State coredata.EvidenceState `json:"state"`
Filename string `json:"filename"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (Evidence) IsNode() {}
@@ -215,25 +194,6 @@ type EvidenceEdge struct {
Node *Evidence `json:"node"`
}
type EvidenceStateTransition struct {
ID gid.GID `json:"id"`
FromState *coredata.EvidenceState `json:"fromState,omitempty"`
ToState coredata.EvidenceState `json:"toState"`
Reason *string `json:"reason,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type EvidenceStateTransitionConnection struct {
Edges []*EvidenceStateTransitionEdge `json:"edges"`
PageInfo *PageInfo `json:"pageInfo"`
}
type EvidenceStateTransitionEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *EvidenceStateTransition `json:"node"`
}
type Framework struct {
ID gid.GID `json:"id"`
Version int `json:"version"`
@@ -350,14 +310,14 @@ type Session struct {
}
type Task struct {
ID gid.GID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
State coredata.TaskState `json:"state"`
StateTransisions *TaskStateTransitionConnection `json:"stateTransisions"`
Evidences *EvidenceConnection `json:"evidences"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID gid.GID `json:"id"`
Version int `json:"version"`
Name string `json:"name"`
Description string `json:"description"`
State coredata.TaskState `json:"state"`
Evidences *EvidenceConnection `json:"evidences"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (Task) IsNode() {}
@@ -373,25 +333,6 @@ type TaskEdge struct {
Node *Task `json:"node"`
}
type TaskStateTransition struct {
ID gid.GID `json:"id"`
FromState *coredata.TaskState `json:"fromState,omitempty"`
ToState coredata.TaskState `json:"toState"`
Reason *string `json:"reason,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type TaskStateTransitionConnection struct {
Edges []*TaskStateTransitionEdge `json:"edges"`
PageInfo *PageInfo `json:"pageInfo"`
}
type TaskStateTransitionEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *TaskStateTransition `json:"node"`
}
type UpdateControlInput struct {
ID gid.GID `json:"id"`
ExpectedVersion int `json:"expectedVersion"`
@@ -443,6 +384,18 @@ type UpdatePolicyPayload struct {
Policy *Policy `json:"policy"`
}
type UpdateTaskInput struct {
TaskID gid.GID `json:"taskId"`
ExpectedVersion int `json:"expectedVersion"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
State *coredata.TaskState `json:"state,omitempty"`
}
type UpdateTaskPayload struct {
Task *Task `json:"task"`
}
type UpdateTaskStateInput struct {
TaskID gid.GID `json:"taskId"`
State coredata.TaskState `json:"state"`

View File

@@ -18,19 +18,6 @@ import (
"github.com/vektah/gqlparser/v2/gqlerror"
)
// StateTransisions is the resolver for the stateTransisions field.
func (r *controlResolver) StateTransisions(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.ControlStateTransitionConnection, error) {
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
cursor := types.NewCursor(first, after, last, before)
page, err := svc.ListControlStateTransitions(ctx, obj.ID, cursor)
if err != nil {
return nil, fmt.Errorf("cannot list control tasks: %w", err)
}
return types.NewControlStateTransitionConnection(page), nil
}
// Tasks is the resolver for the tasks field.
func (r *controlResolver) Tasks(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.TaskConnection, error) {
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
@@ -56,19 +43,6 @@ func (r *evidenceResolver) FileURL(ctx context.Context, obj *types.Evidence) (st
return *fileURL, nil
}
// StateTransisions is the resolver for the stateTransisions field.
func (r *evidenceResolver) StateTransisions(ctx context.Context, obj *types.Evidence, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.EvidenceStateTransitionConnection, error) {
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
cursor := types.NewCursor(first, after, last, before)
page, err := svc.ListEvidenceStateTransitions(ctx, obj.ID, cursor)
if err != nil {
return nil, fmt.Errorf("cannot list evidence state transitions: %w", err)
}
return types.NewEvidenceStateTransitionConnection(page), nil
}
// Controls is the resolver for the controls field.
func (r *frameworkResolver) Controls(ctx context.Context, obj *types.Framework, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.ControlConnection, error) {
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
@@ -226,24 +200,6 @@ func (r *mutationResolver) DeleteOrganization(ctx context.Context, input types.D
panic(fmt.Errorf("not implemented: DeleteOrganization - deleteOrganization"))
}
// UpdateTaskState is the resolver for the updateTaskState field.
func (r *mutationResolver) UpdateTaskState(ctx context.Context, input types.UpdateTaskStateInput) (*types.UpdateTaskStatePayload, error) {
svc := r.proboSvc.WithTenant(input.TaskID.TenantID())
task, err := svc.UpdateTaskState(ctx, probo.UpdateTaskStateRequest{
TaskID: input.TaskID,
State: input.State,
Reason: nil,
})
if err != nil {
return nil, fmt.Errorf("cannot update task state: %w", err)
}
return &types.UpdateTaskStatePayload{
Task: types.NewTask(task),
}, nil
}
// CreateTask is the resolver for the createTask field.
func (r *mutationResolver) CreateTask(ctx context.Context, input types.CreateTaskInput) (*types.CreateTaskPayload, error) {
svc := r.proboSvc.WithTenant(input.ControlID.TenantID())
@@ -262,6 +218,26 @@ func (r *mutationResolver) CreateTask(ctx context.Context, input types.CreateTas
}, nil
}
// UpdateTask is the resolver for the updateTask field.
func (r *mutationResolver) UpdateTask(ctx context.Context, input types.UpdateTaskInput) (*types.UpdateTaskPayload, error) {
svc := r.proboSvc.WithTenant(input.TaskID.TenantID())
task, err := svc.UpdateTask(ctx, probo.UpdateTaskRequest{
ID: input.TaskID,
ExpectedVersion: input.ExpectedVersion,
Name: input.Name,
Description: input.Description,
State: input.State,
})
if err != nil {
return nil, fmt.Errorf("cannot update task: %w", err)
}
return &types.UpdateTaskPayload{
Task: types.NewTask(task),
}, nil
}
// DeleteTask is the resolver for the deleteTask field.
func (r *mutationResolver) DeleteTask(ctx context.Context, input types.DeleteTaskInput) (*types.DeleteTaskPayload, error) {
svc := r.proboSvc.WithTenant(input.TaskID.TenantID())
@@ -589,19 +565,6 @@ func (r *queryResolver) Viewer(ctx context.Context) (*types.User, error) {
return types.NewUser(user), nil
}
// StateTransisions is the resolver for the stateTransisions field.
func (r *taskResolver) StateTransisions(ctx context.Context, obj *types.Task, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.TaskStateTransitionConnection, error) {
svc := r.proboSvc.WithTenant(obj.ID.TenantID())
cursor := types.NewCursor(first, after, last, before)
page, err := svc.ListTaskStateTransitions(ctx, obj.ID, cursor)
if err != nil {
return nil, fmt.Errorf("cannot list control tasks: %w", err)
}
return types.NewTaskStateTransitionConnection(page), nil
}
// Evidences is the resolver for the evidences field.
func (r *taskResolver) Evidences(ctx context.Context, obj *types.Task, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.EvidenceConnection, error) {
svc := r.proboSvc.WithTenant(obj.ID.TenantID())