Skip to content

Establish a current-version convention for postData and audit post.ts / posts.ts against it #185

Description

@bbornino

postData is keyed by (slug, locale, version), and sync-post writes one row per version (frontmatter version field, default ""). No query in the codebase today has an explicit, documented way to pick "the current version" when more than one exists for the same slug+locale:

Right now this is latent rather than actively broken, since no real content currently has a non-empty version. But if Playful Programming's post-rewrite/versioning feature ever populates a real non-empty version for live, current content, both of the above will silently return the wrong row (or duplicate rows) for affected posts.

Proposal

Decide on one real convention for "the current version of a post" — options to consider:

  • An explicit isCurrent/isLatest boolean column on postData.
  • "Max version wins" (requires version to be orderable, which a free-text frontmatter field currently isn't).
  • Something else sync-post already knows at write time that could be persisted instead of inferred at query time.

Once decided:

  • Update post.ts to select the current version explicitly instead of data[0].
  • Update posts.ts to use the same convention instead of the version = "" stopgap.
  • Add a migration if the convention requires a new column.
  • Add test coverage for a post with multiple versions to lock in the expected behavior on both endpoints.

Context

Surfaced while building #83 (GET /content/posts) — see the "Open design question" section on PR #184 for the specific stopgap this issue is meant to replace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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