Feat v0.3.0 workflow schema (#14)
All checks were successful
All checks were successful
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #14.
This commit is contained in:
@@ -152,26 +152,38 @@ func (s *WorkflowStore) CreateStage(ctx context.Context, st *models.WorkflowStag
|
||||
st.ID = store.NewID()
|
||||
st.CreatedAt = time.Now().UTC()
|
||||
formTpl := jsonOrEmpty(st.FormTemplate)
|
||||
transRules := jsonOrEmpty(st.TransitionRules)
|
||||
stageConfig := jsonOrEmpty(st.StageConfig)
|
||||
branchRules := jsonOrEmpty(st.BranchRules)
|
||||
stageMode := st.StageMode
|
||||
if stageMode == "" {
|
||||
stageMode = models.StageModeCustom
|
||||
stageMode = models.StageModeForm
|
||||
}
|
||||
audience := st.Audience
|
||||
if audience == "" {
|
||||
audience = models.AudienceTeam
|
||||
}
|
||||
stageType := st.StageType
|
||||
if stageType == "" {
|
||||
stageType = models.StageTypeSimple
|
||||
}
|
||||
_, err := DB.ExecContext(ctx, `
|
||||
INSERT INTO workflow_stages (id, workflow_id, ordinal, name, persona_id, assignment_team_id,
|
||||
form_template, stage_mode, history_mode, auto_transition, transition_rules,
|
||||
INSERT INTO workflow_stages (id, workflow_id, ordinal, name, assignment_team_id,
|
||||
form_template, stage_mode, audience, stage_type,
|
||||
auto_transition, stage_config, branch_rules, starlark_hook,
|
||||
surface_pkg_id, sla_seconds, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
st.ID, st.WorkflowID, st.Ordinal, st.Name, st.PersonaID, st.AssignmentTeamID,
|
||||
formTpl, stageMode, st.HistoryMode, boolToInt(st.AutoTransition), transRules,
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
st.ID, st.WorkflowID, st.Ordinal, st.Name, st.AssignmentTeamID,
|
||||
formTpl, stageMode, audience, stageType,
|
||||
boolToInt(st.AutoTransition), stageConfig, branchRules, st.StarlarkHook,
|
||||
st.SurfacePkgID, st.SLASeconds, st.CreatedAt.Format(time.RFC3339))
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *WorkflowStore) ListStages(ctx context.Context, workflowID string) ([]models.WorkflowStage, error) {
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT id, workflow_id, ordinal, name, persona_id, assignment_team_id,
|
||||
form_template, stage_mode, history_mode, auto_transition, transition_rules,
|
||||
SELECT id, workflow_id, ordinal, name, assignment_team_id,
|
||||
form_template, stage_mode, audience, stage_type,
|
||||
auto_transition, stage_config, branch_rules, starlark_hook,
|
||||
surface_pkg_id, sla_seconds, created_at
|
||||
FROM workflow_stages WHERE workflow_id = ?
|
||||
ORDER BY ordinal ASC`, workflowID)
|
||||
@@ -182,16 +194,17 @@ func (s *WorkflowStore) ListStages(ctx context.Context, workflowID string) ([]mo
|
||||
var result []models.WorkflowStage
|
||||
for rows.Next() {
|
||||
var stg models.WorkflowStage
|
||||
var formTpl, transRules string
|
||||
var formTpl, stageConfig, branchRules string
|
||||
var autoTrans int
|
||||
if err := rows.Scan(&stg.ID, &stg.WorkflowID, &stg.Ordinal, &stg.Name,
|
||||
&stg.PersonaID, &stg.AssignmentTeamID, &formTpl, &stg.StageMode,
|
||||
&stg.HistoryMode, &autoTrans, &transRules,
|
||||
&stg.AssignmentTeamID, &formTpl, &stg.StageMode, &stg.Audience, &stg.StageType,
|
||||
&autoTrans, &stageConfig, &branchRules, &stg.StarlarkHook,
|
||||
&stg.SurfacePkgID, &stg.SLASeconds, st(&stg.CreatedAt)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stg.FormTemplate = json.RawMessage(formTpl)
|
||||
stg.TransitionRules = json.RawMessage(transRules)
|
||||
stg.StageConfig = json.RawMessage(stageConfig)
|
||||
stg.BranchRules = json.RawMessage(branchRules)
|
||||
stg.AutoTransition = autoTrans != 0
|
||||
result = append(result, stg)
|
||||
}
|
||||
@@ -200,19 +213,30 @@ func (s *WorkflowStore) ListStages(ctx context.Context, workflowID string) ([]mo
|
||||
|
||||
func (s *WorkflowStore) UpdateStage(ctx context.Context, st *models.WorkflowStage) error {
|
||||
formTpl := jsonOrEmpty(st.FormTemplate)
|
||||
transRules := jsonOrEmpty(st.TransitionRules)
|
||||
stageConfig := jsonOrEmpty(st.StageConfig)
|
||||
branchRules := jsonOrEmpty(st.BranchRules)
|
||||
stageMode := st.StageMode
|
||||
if stageMode == "" {
|
||||
stageMode = models.StageModeCustom
|
||||
stageMode = models.StageModeForm
|
||||
}
|
||||
audience := st.Audience
|
||||
if audience == "" {
|
||||
audience = models.AudienceTeam
|
||||
}
|
||||
stageType := st.StageType
|
||||
if stageType == "" {
|
||||
stageType = models.StageTypeSimple
|
||||
}
|
||||
_, err := DB.ExecContext(ctx, `
|
||||
UPDATE workflow_stages
|
||||
SET ordinal = ?, name = ?, persona_id = ?, assignment_team_id = ?,
|
||||
form_template = ?, stage_mode = ?, history_mode = ?, auto_transition = ?,
|
||||
transition_rules = ?, surface_pkg_id = ?, sla_seconds = ?
|
||||
SET ordinal = ?, name = ?, assignment_team_id = ?,
|
||||
form_template = ?, stage_mode = ?, audience = ?, stage_type = ?,
|
||||
auto_transition = ?, stage_config = ?, branch_rules = ?, starlark_hook = ?,
|
||||
surface_pkg_id = ?, sla_seconds = ?
|
||||
WHERE id = ?`,
|
||||
st.Ordinal, st.Name, st.PersonaID, st.AssignmentTeamID,
|
||||
formTpl, stageMode, st.HistoryMode, boolToInt(st.AutoTransition), transRules,
|
||||
st.Ordinal, st.Name, st.AssignmentTeamID,
|
||||
formTpl, stageMode, audience, stageType,
|
||||
boolToInt(st.AutoTransition), stageConfig, branchRules, st.StarlarkHook,
|
||||
st.SurfacePkgID, st.SLASeconds, st.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user