Skip to content

refactor: migrate WorkflowDefinitionVersion to generic VersionSnapshot[WorkflowDefinition] #1131

@Aureliolo

Description

@Aureliolo

Context

Follow-up from #1113 (versioning infrastructure evaluation). The generic VersionSnapshot[T] infrastructure from #1076 is a strict superset of the bespoke WorkflowDefinitionVersion system. Migration is favorable:

Aspect Bespoke Generic Verdict
Content hash None SHA-256 dedup Generic wins
Schema Flattened fields snapshot JSON blob Generic simpler
created_by On version model Already on WorkflowDefinition No data loss
Repository methods 5 7 (incl. content_hash lookup) Generic richer
Concurrent writes Not handled INSERT OR IGNORE + retry Generic safer

Scope

Delete (bespoke files)

  • src/synthorg/engine/workflow/version.py -- WorkflowDefinitionVersion model
  • src/synthorg/persistence/workflow_version_repo.py -- WorkflowVersionRepository protocol
  • src/synthorg/persistence/sqlite/workflow_version_repo.py -- SQLiteWorkflowVersionRepository

Create/Modify

  1. src/synthorg/persistence/sqlite/backend.py -- Add SQLiteVersionRepository[WorkflowDefinition] factory
  2. Schema migration -- New table with generic columns (entity_id, version, content_hash, snapshot, saved_by, saved_at), backfill from old table
  3. src/synthorg/api/controllers/workflows.py -- Use VersioningService[WorkflowDefinition].snapshot_if_changed()
  4. src/synthorg/api/controllers/workflow_versions.py -- Use VersionRepository[WorkflowDefinition]
  5. src/synthorg/api/controllers/_workflow_helpers.py -- Remove build_version_snapshot()
  6. src/synthorg/engine/workflow/diff.py -- Operate on VersionSnapshot[WorkflowDefinition]
  7. Update all tests referencing old types

Benefits

  • Content-addressable deduplication (skip no-change saves)
  • Single implementation for all versioned entities
  • Concurrent-write conflict resolution
  • Consistent schema across versioned types

Metadata

Metadata

Assignees

No one assigned

    Labels

    prio:mediumShould do, but not blockingscope:medium1-3 days of worktype:refactorCode restructuring, cleanupv0.7Minor version v0.7

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions