Pilot seed 002_pilot_operations fails validation: harvest_event plot does not match its crop cycle #1
syntropicagent opened 3 weeks ago

Symptom

python3 -m services.migration migrate fails at seed:002_pilot_operations.sql:

ERROR: harvest_event c0000000-0000-0000-0000-000000000007 plot does not match its crop cycle
CONTEXT: PL/pgSQL function validate_operational_context() line 94 at RAISE

Blocks the remaining ~115 seed migrations on a fresh staging database (345/463 applied).

Analysis

The seed inserts harvest_event c0...07 with a plot that the validate_operational_context() trigger rejects because it doesn't belong to the referenced crop cycle. Either the seed's plot/crop-cycle pairing is wrong, or the trigger is stricter than the seed data intends.

Where

schemas/seeds/002_pilot_operations.sql:48

Impact

Fresh environments cannot complete seeding; staging bootstrap blocked at 345/463.

Suggested fix

Correct the plot/crop-cycle pairing in the seed row (or relax the trigger if the constraint is wrong). Verify with a fresh-database migration run.

  • OneDev commented 3 weeks ago

    State changed as pull request KI-101 is open

  • OneDev changed state to 'In Review' 3 weeks ago
    Previous Value Current Value
    Open
    In Review
  • syntropicagent commented 3 weeks ago

    Fixed on branch fix/staging-root-env-rewrap (PR #101).

    Root cause: seed 002 was written for an older farm layout (Plot A/B/C — maize/cassava/beans) and half-updated when 001_pilot_farm moved to the syntropic design. harvest_events c07-c10 referenced plots that didn't match their crop cycles; the validate_operational_context() trigger correctly rejected them.

    Fixes:

    1. seed 002: harvest_event plot_id aligned with crop_cycle.plot_id (c07/c08 -> plot 021, c09/c10 -> plot 020) + all descriptions rewritten to match the current farm story.
    2. seed 029 (second blocker found during verification): published stakeholder_feedback requires canonical consent grants (228 trigger) and the Adelphi party, but seed 105 defines parties later alphabetically. Seed 029 now creates the party + two consent grants idempotently before its feedback rows.
    3. env.py: _sops_decrypt tries both sops envelope formats — fixes runtime secret decryption regardless of which envelope a deploy produced.

    Verified: fresh throwaway database applies all 463 migrations+seeds with 0 failures; then applied the remaining 115 seeds to staging (now 463/463 there too).

  • OneDev commented 3 weeks ago

    State changed as code fixing the issue is committed (59aa5e4c)

  • OneDev changed state to 'Closed' 3 weeks ago
    Previous Value Current Value
    In Review
    Closed
1/1
Type
New Feature
Priority
Normal
Assignees
Not assigned
Issue Votes (0)
Watchers (1)
Reference
KI-1
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover