Skip to content

refactor(persistence): Primitive obsession in entities — raw strings for domain concepts that have value-object wrappers #45

@jaybarden1

Description

@jaybarden1

Problem

Several entity fields use raw string for domain concepts that have strongly-typed wrappers already defined in Persistence/ValueObjects/ with registered converters in SqliteTypeConverters:

Entity Field Should be
SyncRuleEntity RemotePath (string) RemotePath
SyncedItemEntity RemotePath (string) RemotePath
SyncedItemEntity LocalPath (string) LocalPath
SyncJobEntity RemotePath (string) RemotePath
SyncJobEntity LocalPath (string) LocalPath
SyncConflictEntity RemoteItemId (string) OneDriveItemId

Also: SyncConflictEntity.State, SyncJobEntity.Status, and SyncJobEntity.JobType are raw strings with values like "Pending" / "Resolved" / "Download" / "Upload". These should be enums (SyncConflictState, SyncJobStatus, SyncJobType) with HasConversion<string>() in the entity configurations. This removes the private string constants scattered in SyncRepository.cs (lines 12–14).

Additionally: FileClassificationRuleEntity.Id and SyncedItemClassificationEntity.Id use raw string as primary key with no strongly-typed wrapper. Define FileClassificationRuleId and SyncedItemClassificationId wrappers and update entity, configuration, and IFileClassificationRuleRepository.DeleteAsync signature.

Required fix

For each entity:

  1. Change the property type to the wrapper
  2. Add HasConversion(SqliteTypeConverters.XxxConverter) in the entity's IEntityTypeConfiguration class
  3. Update all repository methods that query or filter on these fields

For the enum cases:

  1. Define the enums in the Persistence/Entities/ folder
  2. Apply HasConversion<string>() in entity configs
  3. Remove the private string constants from SyncRepository

Rule reference

@.claude/rules/onedrive-persistence.md — Strongly-typed domain value types + EF Core value converter registration

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions