veza/veza-backend-api/migrations/rollback
senke d4fbf2bf84
Some checks failed
Veza CI / Backend (Go) (push) Failing after 0s
Veza CI / Frontend (Web) (push) Failing after 0s
Veza CI / Rust (Stream Server) (push) Failing after 0s
Security Scan / Secret Scanning (gitleaks) (push) Failing after 0s
Veza CI / Notify on failure (push) Failing after 0s
feat(marketplace): seller transfer state machine matrix — v1.0.7 item B day 1
Day-1 foundation for item B (async Stripe Connect reversal worker).
No worker code, no runtime enforcement yet — just the authoritative
state machine that day 2's code will route through. Before writing
the worker we want a single place where the legal transitions are
defined and tested, so the worker's behavior can be argued against
the matrix rather than implicitly codified across call sites.

transfer_transitions.go:
  * SellerTransferStatus constants (Pending, Completed, Failed,
    ReversalPending [new], Reversed [new], PermanentlyFailed).
  * AllowedTransferTransitions map: pending → {completed, failed};
    completed → {reversal_pending}; failed → {completed,
    permanently_failed}; reversal_pending → {reversed,
    permanently_failed}; reversed and permanently_failed as dead ends.
  * CanTransitionTransferStatus(from, to) — same-state always OK
    (idempotent bumps of retry_count / next_retry_at); unknown from
    fails conservatively (typos in call sites become visible).

transfer_transitions_test.go:
  * TestTransferStateTransitions iterates the full 6×6 matrix (36
    pairs) and asserts every pair against the expected outcome.
  * TestTransferStateTransitions_TerminalStatesHaveNoOutgoing
    double-locks Reversed + PermanentlyFailed as dead ends at the
    map level (not just at the caller level).
  * TestTransferStateTransitions_MatrixKeysAreAccountedFor keeps the
    canonical status list in sync with the map; a new status added
    to one but not the other fails the test.
  * TestCanTransitionTransferStatus_UnknownFromIsConservative
    documents the "unknown from → always false" policy so a future
    reader sees the intent.

Migration 982 adds a partial composite index on (status,
next_retry_at) WHERE status='reversal_pending', sibling to the
existing idx_seller_transfers_retry (scoped to failed). Two parallel
partial indexes cost less than widening the existing one (which
would need a table-level lock) and keep the worker query planner-
friendly.

Day 2 routes processSellerTransfers, TransferRetryWorker,
reverseSellerAccounting, admin_transfer_handler through
CanTransitionTransferStatus at every Status mutation, and writes
StripeReversalWorker. Day 3 exercises the end-to-end flow
(refund → reversal_pending → worker → reversed) in a smoke probe.

Checkpoint: ping user at end of day 1 before day 2 per discipline
agreed upfront.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 14:13:02 +02:00
..
076_create_gear_items_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
077_create_live_streams_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
078_add_missing_indexes_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
082_create_api_keys_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
125_follow_counts_triggers_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
129_playlist_editorial_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
132_quiet_hours_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
133_notification_grouping_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
134_weekly_digest_prefs_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
900_triggers_and_functions_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
910_create_audit_logs_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
920_add_performance_indexes_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
930_add_missing_foreign_keys_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
931_add_refresh_tokens_updated_at_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
940_performance_indexes_v0951_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
941_notification_prefs_defaults_v0105_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
942_create_co_listening_sessions_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
943_create_track_stems_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
944_create_data_exports_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
945_creator_analytics_v0110_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
946_advanced_analytics_v0111_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
947_moderation_advanced_v0112_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
948_marketplace_complete_v0120_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
949_subscription_plans_v0121_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
950_distribution_platforms_v0122_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
951_education_courses_v0123_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
960_performance_indexes_v0124_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
970_password_login_history_v0130_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
971_security_advanced_v0133_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
972_seller_kyc_v0135_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
973_support_tickets_v0135_down.sql chore: cleanup old e2e tests, playwright configs, reorganize down migrations 2026-03-18 11:35:26 +01:00
980_void_unpaid_subscriptions_down.sql chore(release): v1.0.6.2 — subscription payment-gate bypass hotfix 2026-04-17 12:21:53 +02:00
981_seller_transfers_stripe_reversal_id_down.sql refactor(connect): persist stripe_transfer_id on create + retry — v1.0.7 item A 2026-04-17 13:08:39 +02:00
982_seller_transfers_reversal_pending_index_down.sql feat(marketplace): seller transfer state machine matrix — v1.0.7 item B day 1 2026-04-17 14:13:02 +02:00