All screens
42 days

Schema Evolution

Every SQL migration under supabase/migrations, in apply order. The Supabase CLI owns the schema (R5); Prisma is types-only. The DB is the enforcement boundary — write paths flow through SECURITY DEFINER RPCs that share the gate evaluator and raise the canonical Error Contract (R2).

94

Migrations applied

7

Schema layers

0001–0150

Range

66

Objects added

Foundation(7)State machine(3)Governance(10)Readiness(11)Append-only ledgers(11)Operational(50)Concurrency(2)

Timeline

Each migration is a step in the schema's evolution. Tables, RPCs, triggers, and policies it introduces are listed beneath.

  1. 0001Set A — Foundation
    Foundation

    The core schema and the enforcement boundary: enums, core tables, RLS, and the event state-machine RPC + gate evaluator.

    • pgcrypto extension
    • Enums in lockstep with @uploz/shared-types (operational_state, node_state, severity, ack_level, dependency_type)
    • Core event tables (events, event_nodes, event_roles, …) with row-level security
    • fn_transition_event_state — the only write path for an event lifecycle
    • fn_evaluate_gates — shared by the write path and the read-only "why blocked" preview (R2)

    0001_set_a_foundation.sql

  2. 0002Set B — Operational substrate
    Foundation

    The substrate the rest of the platform builds on: resources, schedules, run-of-show, the dependency graph, comms, tasks, and instruction versioning.

    • node_resources + schedules (Resource Capacity / Schedule Conflict gate sources)
    • nuggets (run-of-show), dependencies (polymorphic graph), channels + messages
    • tasks, instruction_versions, acknowledgments, alerts, presence, Health Timeline feed
    • idempotency-key ledger
    • Extends fn_evaluate_gates (Resource Capacity + Schedule Conflict); adds fn_compute_readiness

    0002_set_b.sql

  3. 0003Node state machine
    State machine

    The single write path for node_state, mirroring the event transition RPC with optimistic locking and a data-driven legal-transition table.

    • node_state_transitions — explicit legal edges, with auto_only system-only edges (DEGRADED/OFFLINE)
    • fn_transition_node_state — authority check, SELECT … FOR UPDATE, optimistic lock (PT409)
    • Appends to state_transition_log (scope "node")
    • Raises the canonical Error Contract (PT403/PT409/PT422)

    0003_node_state_machine.sql

  4. 0004Vendor governance — instruction versioning
    Governance

    The instruction publish / supersede write path, with content-addressed versions and a conflicting-instruction blocker.

    • Unique (channel_id, content_hash) index — duplicate content is a hard DB invariant
    • fn_publish_instruction — content-addressed via md5(content)
    • fn_supersede_instruction — replace the canonical instruction on a channel
    • PT409 VERSION_CONFLICT (duplicate hash) · PT422 INSTRUCTION_CONFLICT (<24h, different author)

    0004_vendor_governance.sql

  5. 0005Readiness snapshots + activity logging
    Readiness

    Append-only per-node readiness snapshots, plus a thin activity-logging helper over activity_events.

    • readiness_checks — append-only snapshots (weighted score, gate ceiling, category breakdown, blocker count)
    • fn_snapshot_readiness — reuses fn_compute_readiness + fn_evaluate_gates per node
    • fn_log_activity — appends to activity_events

    0005_readiness_activity.sql

  6. 0006Set C — Immutable ledgers
    Append-only ledgers

    INSERT-only audit / event / override logs with immutability enforced at the DB and member-only read access.

    • audit_log, event_log, override_log (INSERT-only)
    • prevent_mutation trigger — raises on any UPDATE or DELETE
    • RLS: SELECT restricted to event members (is_event_member)

    0006_set_c_immutability.sql

  7. 0007Alert raising + escalation ladder
    Operational

    Idempotent alert raise/resolve plus the escalation ladder the worker drives on a timer.

    • escalation_log (append-only history) + active_escalations (one row per escalating alert)
    • fn_raise_alert — idempotent on (event, type, source); re-raising an OPEN alert is a no-op
    • fn_resolve_alert — marks RESOLVED, stops escalation
    • fn_due_escalations — escalations the worker should fire now

    0007_escalation.sql

  8. 0008Notifications
    Operational

    At-most-once notification delivery keyed by an idempotency key, plus Web Push subscription storage.

    • notification_log — per-delivery record keyed by idempotency_key (append-only)
    • push_subscriptions — Web Push subscriptions per user
    • fn_enqueue_notification — idempotent insert (duplicate key silently ignored)
    • RLS: users manage their own push_subscriptions

    0008_notifications.sql

  9. 0009Presence heartbeats + staleness
    Operational

    Liveness pings per source and the system path that degrades silent nodes.

    • heartbeats — current liveness ping per (source_id, source_type), upserted
    • fn_heartbeat — upsert last_ping
    • fn_stale_presence — sources older than a per-kind threshold
    • fn_mark_node_degraded — system write path to DEGRADED + raises a CRITICAL alert

    0009_presence_heartbeat.sql

  10. 0010Concurrency primitives
    Concurrency

    The dedupe + locking primitives the write-path RPCs use to stay correct under concurrent / retried requests.

    • idempotency_keys — request_hash dedupe; retries replay the stored response jsonb
    • live_locks — coarse advisory-style lock rows serializing vendor-channel writes
    • fn_acquire_lock / fn_release_lock
    • PT409 IDEMPOTENCY_CONFLICT · PT423 RESOURCE_LOCKED

    0010_concurrency.sql

  11. 0011Audit wiring
    Append-only ledgers

    Automatic audit_log triggers on the key business tables — auditing that never blocks the originating write.

    • AFTER INSERT/UPDATE triggers on events, event_roles, instruction_versions, alerts
    • Each appends an immutable audit_log row (actor, action, entity, NEW snapshot)
    • Errors swallowed (raise notice) so a failed append degrades gracefully
    • SECURITY DEFINER with a pinned search_path

    0011_audit_wiring.sql

  12. 0012Override engine
    Governance

    Governance overrides recorded into the INSERT-only override_log under per-category policy.

    • fn_apply_override — writes override_log under category policy
    • AESTHETIC / LOGISTIC: reason ≥ 20 chars · OPERATIONAL_SAFETY: second approver required
    • SECURITY / CONTENT: always rejected (PT403)
    • Unknown category → PT422 BAD_REQUEST

    0012_override_engine.sql

  13. 0013Event replay / change feed
    Append-only ledgers

    A typed change feed over the INSERT-only event_log, plus an ordered replay function per event.

    • AFTER INSERT/UPDATE triggers on events, event_nodes, alerts, instruction_versions
    • Each appends a typed event_log row (event_type, source_object_type/id, NEW snapshot)
    • fn_replay_event — ordered slice of the log for one event, optionally time-bounded
    • Errors swallowed so emitting the feed never blocks the write

    0013_event_replay.sql

  14. 0014Vendor multi-node channels
    Governance

    Multi-node vendor-channel governance: channel modes plus a sub-lead recommendation → lead forward flow.

    • channels.mode (MULTI_NODE | PER_NODE)
    • sub_lead_recommendations — drafted recommendations on a channel
    • fn_recommend_instruction (member write) / fn_forward_recommendation (authority write)
    • PT404 NOT_FOUND · PT409 VERSION_CONFLICT (already forwarded)

    0014_vendor_multinode.sql

  15. 0015Critical-path recompute
    Readiness

    Critical-path flagging over the dependency graph, mirroring the validation-engine critical-path module.

    • fn_recompute_critical_path — flags is_on_critical_path on the longest DEPENDS_ON / REQUIRES_SYNC chain
    • Downstream dependency cascade helper
    • Bounded traversal: hard depth cap + cycle guard (terminates on large / cyclic graphs)

    0015_critical_path.sql

  16. 0016Readiness trend reporting
    Readiness

    Read-only reporting helpers over the append-only readiness_checks history.

    • fn_readiness_trend — ordered time-series for one node within a trailing window
    • fn_readiness_summary — latest snapshot per node (score, ceiling, blocker_count)
    • SECURITY INVOKER + STABLE: pure SELECTs governed by existing RLS

    0016_readiness_trend.sql

  17. 0017Task fulfillment cascade
    Readiness

    Links a task to the dependency edge it satisfies and cascades readiness when fulfillment flips.

    • tasks.dependency_id — additive FK to dependencies(id)
    • AFTER UPDATE trigger — mirrors is_fulfilled to the dependency and re-snapshots touched nodes
    • fn_verify_task / fn_reopen_task — authority-gated (PT403), idempotent
    • Cascade never aborts the originating write (degrades to a notice)

    0017_task_fulfillment.sql

  18. 0018Event clusters
    Foundation

    Filename-derived entry: 0018_event_clusters.sql

      0018_event_clusters.sql

    • 0019Notification templates
      Operational

      Filename-derived entry: 0019_notification_templates.sql

        0019_notification_templates.sql

      • 0020Analytics views
        Operational

        Filename-derived entry: 0020_analytics_views.sql

          0020_analytics_views.sql

        • 0021Retention
          Operational

          Filename-derived entry: 0021_retention.sql

            0021_retention.sql

          • 0022Metrics
            Operational

            Filename-derived entry: 0022_metrics.sql

              0022_metrics.sql

            • 0023RLS refinements
              Governance

              Filename-derived entry: 0023_rls_refine.sql

                0023_rls_refine.sql

              • 0024Rate limiting
                Concurrency

                Filename-derived entry: 0024_rate_limit.sql

                  0024_rate_limit.sql

                • 0025Full-text search
                  Foundation

                  Filename-derived entry: 0025_full_text_search.sql

                    0025_full_text_search.sql

                  • 0026Performance indexes
                    Operational

                    Filename-derived entry: 0026_performance_indexes.sql

                      0026_performance_indexes.sql

                    • 0027Materialized view: node readiness
                      Readiness

                      Filename-derived entry: 0027_mv_node_readiness.sql

                        0027_mv_node_readiness.sql

                      • 0028Event export
                        Operational

                        Filename-derived entry: 0028_event_export.sql

                          0028_event_export.sql

                        • 0029Outbound webhooks
                          Operational

                          Filename-derived entry: 0029_outbound_webhooks.sql

                            0029_outbound_webhooks.sql

                          • 0030Cluster report
                            Operational

                            Filename-derived entry: 0030_cluster_report.sql

                              0030_cluster_report.sql

                            • 0031Presence location
                              Operational

                              Filename-derived entry: 0031_presence_location.sql

                                0031_presence_location.sql

                              • 0032Event templates
                                Foundation

                                Filename-derived entry: 0032_event_templates.sql

                                  0032_event_templates.sql

                                • 0033Phase 3 AI stub
                                  Operational

                                  Filename-derived entry: 0033_phase3_ai_stub.sql

                                    0033_phase3_ai_stub.sql

                                  • 0034Archive completed event
                                    State machine

                                    Filename-derived entry: 0034_archive_completed_event.sql

                                      0034_archive_completed_event.sql

                                    • 0035Silent channels
                                      Governance

                                      Filename-derived entry: 0035_silent_channels.sql

                                        0035_silent_channels.sql

                                      • 0036Event report
                                        Operational

                                        Filename-derived entry: 0036_event_report.sql

                                          0036_event_report.sql

                                        • 0037Audit search
                                          Append-only ledgers

                                          Filename-derived entry: 0037_audit_search.sql

                                            0037_audit_search.sql

                                          • 0038Ops metrics views
                                            Operational

                                            Filename-derived entry: 0038_ops_metrics_views.sql

                                              0038_ops_metrics_views.sql

                                            • 0039Alert SLA
                                              Operational

                                              Filename-derived entry: 0039_alert_sla.sql

                                                0039_alert_sla.sql

                                              • 0040fn_export_csv
                                                Operational

                                                Filename-derived entry: 0040_fn_export_csv.sql

                                                  0040_fn_export_csv.sql

                                                • 0041fn_capacity_plan
                                                  Operational

                                                  Filename-derived entry: 0041_fn_capacity_plan.sql

                                                    0041_fn_capacity_plan.sql

                                                  • 0041bUser notification preferences
                                                    Operational

                                                    Filename-derived entry: 0041_user_notification_prefs.sql

                                                      0041_user_notification_prefs.sql

                                                    • 0042Seed event templates
                                                      Foundation

                                                      Filename-derived entry: 0042_seed_event_templates.sql

                                                        0042_seed_event_templates.sql

                                                      • 0043Presence sessions
                                                        Operational

                                                        Filename-derived entry: 0043_presence_sessions.sql

                                                          0043_presence_sessions.sql

                                                        • 0044fn_staffing_suggest
                                                          Operational

                                                          Filename-derived entry: 0044_fn_staffing_suggest.sql

                                                            0044_fn_staffing_suggest.sql

                                                          • 0045fn_event_risk_score
                                                            Operational

                                                            Filename-derived entry: 0045_fn_event_risk_score.sql

                                                              0045_fn_event_risk_score.sql

                                                            • 0046fn_readiness_history
                                                              Readiness

                                                              Filename-derived entry: 0046_fn_readiness_history.sql

                                                                0046_fn_readiness_history.sql

                                                              • 0046bfn_silent_channels
                                                                Governance

                                                                Filename-derived entry: 0046_fn_silent_channels.sql

                                                                  0046_fn_silent_channels.sql

                                                                • 0046cfn_submit_feedback
                                                                  Operational

                                                                  Filename-derived entry: 0046_fn_submit_feedback.sql

                                                                    0046_fn_submit_feedback.sql

                                                                  • 0047fn_role_vacancies
                                                                    Operational

                                                                    Filename-derived entry: 0047_fn_role_vacancies.sql

                                                                      0047_fn_role_vacancies.sql

                                                                    • 0048fn_reorder_nugget
                                                                      Operational

                                                                      Filename-derived entry: 0048_fn_reorder_nugget.sql

                                                                        0048_fn_reorder_nugget.sql

                                                                      • 0049View: v_presence_now
                                                                        Operational

                                                                        Filename-derived entry: 0049_v_presence_now.sql

                                                                          0049_v_presence_now.sql

                                                                        • 0050fn_event_analytics
                                                                          Operational

                                                                          Filename-derived entry: 0050_fn_event_analytics.sql

                                                                            0050_fn_event_analytics.sql

                                                                          • 0051fn_sla_breaches
                                                                            Operational

                                                                            Filename-derived entry: 0051_fn_sla_breaches.sql

                                                                              0051_fn_sla_breaches.sql

                                                                            • 0052View: v_node_health
                                                                              Readiness

                                                                              Filename-derived entry: 0052_v_node_health.sql

                                                                                0052_v_node_health.sql

                                                                              • 0053fn_event_feedback_score
                                                                                Operational

                                                                                Filename-derived entry: 0053_fn_event_feedback_score.sql

                                                                                  0053_fn_event_feedback_score.sql

                                                                                • 0054Escalation log
                                                                                  Append-only ledgers

                                                                                  Filename-derived entry: 0054_escalation_log.sql

                                                                                    0054_escalation_log.sql

                                                                                  • 0054bfn_channel_stats
                                                                                    Operational

                                                                                    Filename-derived entry: 0054_fn_channel_stats.sql

                                                                                      0054_fn_channel_stats.sql

                                                                                    • 0054cIncidents
                                                                                      Operational

                                                                                      Filename-derived entry: 0054_incidents.sql

                                                                                        0054_incidents.sql

                                                                                      • 0055fn_export_event_json
                                                                                        Operational

                                                                                        Filename-derived entry: 0055_fn_export_event_json.sql

                                                                                          0055_fn_export_event_json.sql

                                                                                        • 0055bfn_readiness_band
                                                                                          Readiness

                                                                                          Filename-derived entry: 0055_fn_readiness_band.sql

                                                                                            0055_fn_readiness_band.sql

                                                                                          • 0055cOverride log
                                                                                            Append-only ledgers

                                                                                            Filename-derived entry: 0055_override_log.sql

                                                                                              0055_override_log.sql

                                                                                            • 0056Audit log
                                                                                              Append-only ledgers

                                                                                              Filename-derived entry: 0056_audit_log.sql

                                                                                                0056_audit_log.sql

                                                                                              • 0056bfn_incident_summary
                                                                                                Operational

                                                                                                Filename-derived entry: 0056_fn_incident_summary.sql

                                                                                                  0056_fn_incident_summary.sql

                                                                                                • 0057Event log
                                                                                                  Append-only ledgers

                                                                                                  Filename-derived entry: 0057_event_log.sql

                                                                                                    0057_event_log.sql

                                                                                                  • 0057bfn_ack_coverage
                                                                                                    Operational

                                                                                                    Filename-derived entry: 0057_fn_ack_coverage.sql

                                                                                                      0057_fn_ack_coverage.sql

                                                                                                    • 0058fn_incident_candidates
                                                                                                      Operational

                                                                                                      Filename-derived entry: 0058_fn_incident_candidates.sql

                                                                                                        0058_fn_incident_candidates.sql

                                                                                                      • 0058bfn_replay_event
                                                                                                        Append-only ledgers

                                                                                                        Filename-derived entry: 0058_fn_replay_event.sql

                                                                                                          0058_fn_replay_event.sql

                                                                                                        • 0059fn_blocker_digest
                                                                                                          Readiness

                                                                                                          Filename-derived entry: 0059_fn_blocker_digest.sql

                                                                                                            0059_fn_blocker_digest.sql

                                                                                                          • 0059bNotification log
                                                                                                            Append-only ledgers

                                                                                                            Filename-derived entry: 0059_notification_log.sql

                                                                                                              0059_notification_log.sql

                                                                                                            • 0060KPI views
                                                                                                              Operational

                                                                                                              Filename-derived entry: 0060_kpi_views.sql

                                                                                                                0060_kpi_views.sql

                                                                                                              • 0060bView: v_event_blocker_summary
                                                                                                                Readiness

                                                                                                                Filename-derived entry: 0060_v_event_blocker_summary.sql

                                                                                                                  0060_v_event_blocker_summary.sql

                                                                                                                • 0061fn_mark_event_needs_work
                                                                                                                  State machine

                                                                                                                  Filename-derived entry: 0061_fn_mark_event_needs_work.sql

                                                                                                                    0061_fn_mark_event_needs_work.sql

                                                                                                                  • 0061bPerformance indexes (batch 2)
                                                                                                                    Operational

                                                                                                                    Filename-derived entry: 0061_perf_indexes.sql

                                                                                                                      0061_perf_indexes.sql

                                                                                                                    • 0062fn_capture_global_kpis
                                                                                                                      Operational

                                                                                                                      Filename-derived entry: 0062_fn_capture_global_kpis.sql

                                                                                                                        0062_fn_capture_global_kpis.sql

                                                                                                                      • 0062bReadiness rollup view
                                                                                                                        Readiness

                                                                                                                        Filename-derived entry: 0062_readiness_rollup_view.sql

                                                                                                                          0062_readiness_rollup_view.sql

                                                                                                                        • 0063Activity indexes
                                                                                                                          Operational

                                                                                                                          Filename-derived entry: 0063_activity_indexes.sql

                                                                                                                            0063_activity_indexes.sql

                                                                                                                          • 0064fn_event_summary
                                                                                                                            Operational

                                                                                                                            Filename-derived entry: 0064_fn_event_summary.sql

                                                                                                                              0064_fn_event_summary.sql

                                                                                                                            • 0065Seed reference data
                                                                                                                              Foundation

                                                                                                                              Filename-derived entry: 0065_seed_reference.sql

                                                                                                                                0065_seed_reference.sql

                                                                                                                              • 0082fn_vendor_detail
                                                                                                                                Governance

                                                                                                                                Filename-derived entry: 0082_fn_vendor_detail.sql

                                                                                                                                  0082_fn_vendor_detail.sql

                                                                                                                                • 0083Incident view
                                                                                                                                  Operational

                                                                                                                                  Filename-derived entry: 0083_incident_view.sql

                                                                                                                                    0083_incident_view.sql

                                                                                                                                  • 0084fn_presence_rollup
                                                                                                                                    Operational

                                                                                                                                    Filename-derived entry: 0084_fn_presence_rollup.sql

                                                                                                                                      0084_fn_presence_rollup.sql

                                                                                                                                    • 0085Message indexes
                                                                                                                                      Operational

                                                                                                                                      Filename-derived entry: 0085_message_indexes.sql

                                                                                                                                        0085_message_indexes.sql

                                                                                                                                      • 0086fn_export_roles_json
                                                                                                                                        Operational

                                                                                                                                        Filename-derived entry: 0086_fn_export_roles_json.sql

                                                                                                                                          0086_fn_export_roles_json.sql

                                                                                                                                        • 0087Notification indexes
                                                                                                                                          Operational

                                                                                                                                          Filename-derived entry: 0087_notification_indexes.sql

                                                                                                                                            0087_notification_indexes.sql

                                                                                                                                          • 0088Role grants
                                                                                                                                            Governance

                                                                                                                                            Filename-derived entry: 0088_role_grants.sql

                                                                                                                                              0088_role_grants.sql

                                                                                                                                            • 0089fn_log_escalation (service role)
                                                                                                                                              Operational

                                                                                                                                              Filename-derived entry: 0089_fn_log_escalation_service_role.sql

                                                                                                                                                0089_fn_log_escalation_service_role.sql

                                                                                                                                              • 0090Quality findings
                                                                                                                                                Operational

                                                                                                                                                Filename-derived entry: 0090_quality_findings.sql

                                                                                                                                                  0090_quality_findings.sql

                                                                                                                                                • 0091Quality ledger
                                                                                                                                                  Append-only ledgers

                                                                                                                                                  Filename-derived entry: 0091_quality_ledger.sql

                                                                                                                                                    0091_quality_ledger.sql

                                                                                                                                                  • 0092fn_quality_rpcs
                                                                                                                                                    Operational

                                                                                                                                                    Filename-derived entry: 0092_fn_quality_rpcs.sql

                                                                                                                                                      0092_fn_quality_rpcs.sql

                                                                                                                                                    • 0093fn_quality_snapshot
                                                                                                                                                      Operational

                                                                                                                                                      Filename-derived entry: 0093_fn_quality_snapshot.sql

                                                                                                                                                        0093_fn_quality_snapshot.sql

                                                                                                                                                      • 0094Createrz user/group taxonomy
                                                                                                                                                        Governance

                                                                                                                                                        Filename-derived entry: 0094_createrz_user_group_taxonomy.sql

                                                                                                                                                          0094_createrz_user_group_taxonomy.sql

                                                                                                                                                        • 0095Fix auth.uid() / JWT fallback
                                                                                                                                                          Governance

                                                                                                                                                          Filename-derived entry: 0095_fix_auth_uid_jwt_fallback.sql

                                                                                                                                                            0095_fix_auth_uid_jwt_fallback.sql

                                                                                                                                                          • 0150Agent runs
                                                                                                                                                            Operational

                                                                                                                                                            Filename-derived entry: 0150_agent_runs.sql (max migration id)

                                                                                                                                                              0150_agent_runs.sql

                                                                                                                                                            Authored from the migration headers themselves (illustrative project-tracking state), not a query against live data. Migrations are applied in ascending order and never edited in place — schema changes are additive, forward-only migrations.