Skip to content

Fix customer source field inconsistency between mutations and validator #40

Closed

Description

@larryro

Summary

The source field has inconsistent required/optional status between customer mutations and the document validator.

Context

Identified during PR #37 review (CodeRabbit comment #2652223411).

Current State

Mutations (source is optional):

  • createCustomer - source is optional
  • findOrCreateCustomer - source is optional
  • updateCustomer - source is optional

Mutation (source is required):

  • bulkCreateCustomers - source is required

Document Validator:

export const customerValidator = v.object({
  // ...
  source: customerSourceValidator,  // Required
  // ...
});

Problem

Customers can be created without a source value through most mutations, but the document validator marks source as required. This creates a mismatch where documents may fail validation when retrieved.

Proposed Solutions

Option 1: Make source optional in validator

source: v.optional(customerSourceValidator),

This matches the current mutation behavior but loses type safety.

Option 2: Make source required in all mutations + migration

  1. Update all mutations to require source
  2. Add migration to backfill source for existing records
  3. Keep validator as-is

Recommended Approach

Option 2 is preferred for data consistency, but requires a data migration strategy.

Affected Files

  • services/platform/convex/model/customers/validators.ts
  • services/platform/convex/model/customers/create_customer.ts
  • services/platform/convex/model/customers/find_or_create_customer.ts
  • services/platform/convex/model/customers/update_customer.ts

Activity

  1. added 2 commits that reference this issue on Dec 30, 2025
    4839806
    1f175d5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions