Skip to content

feat: add UserContract as a first-party primitive for ownership FK refs #19

Description

@stackbilt-admin

Problem

recipe.contract.ts and pantry.contract.ts both include comments noting "user ref omitted, no UserContract yet." The ref() FK primitive exists in the package but cannot be used for user ownership links until a canonical UserContract is defined and exported.

This affects every entity in the FoodFiles schema — all top-level resources are user-scoped. Without UserContract, contracts that model ownership relationships must either:

  • Leave the FK untyped (losing referential integrity at the contract layer)
  • Define a one-off local user shape, fragmenting the contract graph

Acceptance Criteria

  • UserContract is exported from @stackbilt/contracts (or a @stackbilt/contracts/user sub-path)
  • UserContract includes at minimum: id (uuid), email (string), created_at (timestamp)
  • ref(UserContract) resolves correctly in generateSQL to a FK column (user_id UUID REFERENCES users(id))
  • ref(UserContract) in generateRoutes / typed output preserves the userId field in the inferred TypeScript surface type
  • Existing contracts that omit the user ref (recipe, pantry, organization) can be updated to use ref(UserContract) without a breaking schema change
  • A migration snippet is documented for adding the FK column to tables that predate this contract

Context

FoodFiles is the phase-0 consumer. All seven of its entity contracts need a user_id FK once UserContract is available. This is a blocking primitive for making contracts the authoritative source-of-truth for the FoodFiles data model.

Ref: CONTRACT-3 gap analysis (phase-0 integration audit)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    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