Initial v1 code layout

The destination of the wayfinder map: directory and module structure, the
domain model as real schema files, permission boundaries expressed as code,
and typed seams where the undecided parts land.

Satisfies the four structural requirements earlier resolutions handed to a
layout that did not exist:

  - a single database entry point (#11) — the pool is not exported
  - a scheduler entry point with actor context and no request (#13)
  - an entitlement assertion helper (#20, #34) — its call sites are the
    paid-feature list
  - an enumerated list of privileged RLS bypasses (#33) — three of them

Seams carry real types and throw with the ticket that owns them, so the
skeleton wires up and fails only where a decision is genuinely missing.

Verified: tsc --noEmit clean; drizzle-kit generate produces RLS on 18 tables
and 6 policies calling the release-level functions.

Resolves #35

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Christian
2026-08-03 17:20:47 -04:00
commit da74362d00
46 changed files with 9927 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
-- Custom migration, hand-authored. Drizzle cannot diff a SQL function.
--
-- Fixed by #14 decision 1: ONE function collapses the four inputs #12 named
-- into a release level, and ONE lookup answers whether a class is open at it.
-- Nothing else in the system encodes lifecycle.
--
-- ── WHY plpgsql AND WHY FIRST ────────────────────────────────────────────
-- The RLS policies are emitted by Drizzle in the same migration as the tables
-- they guard, so the functions those policies call must already exist. But the
-- functions read `solicitation`, `participation` and `release_matrix`, which
-- that same later migration creates.
--
-- `LANGUAGE sql` validates the body at CREATE time and would fail here.
-- plpgsql defers validation to first call, which is exactly the property
-- needed to break the cycle. Signatures use `text` rather than the
-- `release_level` enum for the same reason — the enum does not exist yet.
-- ─────────────────────────────────────────────────────────────────────────
-- The four inputs: audience membership, stage, participation state, acknowledgement.
CREATE FUNCTION release_level_for_solicitation(p_solicitation uuid)
RETURNS text
LANGUAGE plpgsql STABLE AS $$
DECLARE
v_level text;
BEGIN
SELECT CASE
WHEN p.id IS NULL THEN 'none'
WHEN s.stage = 'awarded' THEN 'awarded'
WHEN s.stage = 'finalists' THEN 'finalist'
WHEN s.stage = 'evaluating' THEN 'evaluating'
-- The deadline is the moment the whole field opens at once (#14 decision 2).
-- Before it, no response content is readable by anyone but its author, which
-- is what makes bid shopping structurally impossible rather than discouraged.
WHEN s.responses_due_at IS NOT NULL AND now() >= s.responses_due_at THEN 'open'
WHEN p.state = 'submitted' THEN 'submitted'
WHEN p.acknowledged_at IS NOT NULL OR NOT s.acknowledgement_required
THEN 'acknowledged'
ELSE 'invited'
END
INTO v_level
FROM solicitation s
LEFT JOIN participation p
ON p.solicitation_id = s.id
AND p.vendor_org_id = nullif(current_setting('app.org_id', true), '')::uuid
WHERE s.id = p_solicitation;
RETURN coalesce(v_level, 'none');
END;
$$;
-- The issuer reaches their own event at the level its stage implies, without
-- being a participant in it. Everyone else gets 'none' — including a dual-role
-- org's issuing side looking at its own vendor side (#11 decision 2).
CREATE FUNCTION release_level_for_response(p_response uuid)
RETURNS text
LANGUAGE plpgsql STABLE AS $$
DECLARE
v_level text;
BEGIN
SELECT CASE
WHEN current_setting('app.capability', true) = 'issuer'
AND s.issuer_org_id = nullif(current_setting('app.org_id', true), '')::uuid
THEN release_level_for_solicitation(s.id)
WHEN current_setting('app.capability', true) = 'vendor'
AND r.vendor_org_id = nullif(current_setting('app.org_id', true), '')::uuid
THEN release_level_for_solicitation(s.id)
ELSE 'none'
END
INTO v_level
FROM response r
JOIN solicitation s ON s.id = r.solicitation_id
WHERE r.id = p_response;
RETURN coalesce(v_level, 'none');
END;
$$;
-- Reads the CURRENT matrix version. A past release is reconstructed by reading
-- an older version, which is why the matrix is versioned rather than updated.
CREATE FUNCTION class_released(p_level text, p_class text)
RETURNS boolean
LANGUAGE plpgsql STABLE AS $$
DECLARE
v_released boolean;
BEGIN
SELECT released = 'true'
INTO v_released
FROM release_matrix
WHERE class = p_class::disclosure_class
AND level = p_level::release_level
ORDER BY version DESC
LIMIT 1;
RETURN coalesce(v_released, false);
END;
$$;

445
migrations/0001_initial.sql Normal file
View File

@@ -0,0 +1,445 @@
CREATE TYPE "public"."capability" AS ENUM('issuer', 'vendor');--> statement-breakpoint
CREATE TYPE "public"."category_change_kind" AS ENUM('split', 'merge', 'retire', 'remap');--> statement-breakpoint
CREATE TYPE "public"."grant_provenance" AS ENUM('manual', 'split_event', 'merge_event');--> statement-breakpoint
CREATE TYPE "public"."amendment_class" AS ENUM('substantive', 'clarification');--> statement-breakpoint
CREATE TYPE "public"."confirmation_state" AS ENUM('unconfirmed', 'confirmed', 'corrected');--> statement-breakpoint
CREATE TYPE "public"."requirement_kind" AS ENUM('mandatory_gate', 'scored_criterion', 'certification_form', 'compliance_schedule', 'pricing', 'narrative');--> statement-breakpoint
CREATE TYPE "public"."solicitation_stage" AS ENUM('draft', 'open', 'evaluating', 'finalists', 'awarded', 'cancelled');--> statement-breakpoint
CREATE TYPE "public"."coverage" AS ENUM('answered', 'not_answered', 'indeterminate');--> statement-breakpoint
CREATE TYPE "public"."participation_state" AS ENUM('invited', 'opened', 'acknowledged', 'intends_to_bid', 'submitted', 'withdrawn');--> statement-breakpoint
CREATE TYPE "public"."disclosure_class" AS ENUM('vendor_identity', 'participation_signal', 'scenario_quantity', 'answer_text', 'exception_text', 'price_quote', 'derived_cost', 'vault_document', 'own_scoring');--> statement-breakpoint
CREATE TYPE "public"."release_level" AS ENUM('none', 'invited', 'acknowledged', 'submitted', 'open', 'evaluating', 'finalist', 'awarded');--> statement-breakpoint
CREATE TYPE "public"."expiry_state" AS ENUM('current', 'expiring_soon', 'expired');--> statement-breakpoint
CREATE TYPE "public"."tier" AS ENUM('base', 'pro', 'enterprise');--> statement-breakpoint
CREATE TYPE "public"."sweep_finding_kind" AS ENUM('asserted_obligation', 'uncovered_span');--> statement-breakpoint
CREATE TABLE "actor" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"email" text NOT NULL,
"display_name" text NOT NULL,
CONSTRAINT "actor_email_unique" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE "membership" (
"actor_id" uuid NOT NULL,
"org_id" uuid NOT NULL,
CONSTRAINT "membership_actor_id_org_id_pk" PRIMARY KEY("actor_id","org_id")
);
--> statement-breakpoint
CREATE TABLE "org_capability" (
"org_id" uuid NOT NULL,
"capability" "capability" NOT NULL,
"granted_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "org_capability_org_id_capability_pk" PRIMARY KEY("org_id","capability")
);
--> statement-breakpoint
CREATE TABLE "organization" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"legal_name" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "roster_entry" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"retailer_org_id" uuid NOT NULL,
"name" text NOT NULL,
"contact_email" text,
"duns" text,
"claimed_vendor_org_id" uuid,
"claimed_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "roster_entry_retailer_org_id_name_unique" UNIQUE("retailer_org_id","name")
);
--> statement-breakpoint
CREATE TABLE "category_change_event" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"kind" "category_change_kind" NOT NULL,
"retailer_org_id" uuid,
"from_ids" uuid[] NOT NULL,
"to_ids" uuid[] NOT NULL,
"rows_written" integer DEFAULT 0 NOT NULL,
"performed_by" uuid NOT NULL,
"performed_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "eligibility" (
"retailer_org_id" uuid NOT NULL,
"vendor_org_id" uuid NOT NULL,
"local_category_id" uuid NOT NULL,
"provenance" "grant_provenance" DEFAULT 'manual' NOT NULL,
"provenance_event_id" uuid,
"granted_at" timestamp with time zone DEFAULT now() NOT NULL,
"revoked_at" timestamp with time zone,
CONSTRAINT "eligibility_retailer_org_id_vendor_org_id_local_category_id_pk" PRIMARY KEY("retailer_org_id","vendor_org_id","local_category_id")
);
--> statement-breakpoint
CREATE TABLE "local_category" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"retailer_org_id" uuid NOT NULL,
"label" text NOT NULL,
"spine_leaf_id" uuid,
"valid_from" timestamp with time zone DEFAULT now() NOT NULL,
"valid_to" timestamp with time zone,
"superseded_by" uuid[] DEFAULT '{}' NOT NULL
);
--> statement-breakpoint
CREATE TABLE "spine_node" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"label" text NOT NULL,
"group_id" uuid,
"unspsc_families" text[] DEFAULT '{}' NOT NULL,
"valid_from" timestamp with time zone DEFAULT now() NOT NULL,
"valid_to" timestamp with time zone,
"superseded_by" uuid[] DEFAULT '{}' NOT NULL
);
--> statement-breakpoint
CREATE TABLE "criterion" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"label" text NOT NULL,
"max_points" numeric(8, 2) NOT NULL,
"weight" numeric(8, 2) NOT NULL,
"scale_anchors" jsonb DEFAULT '[]'::jsonb NOT NULL
);
--> statement-breakpoint
ALTER TABLE "criterion" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "criterion_requirement" (
"criterion_id" uuid NOT NULL,
"requirement_id" uuid NOT NULL,
"authored_by" uuid NOT NULL,
"frozen_at" timestamp with time zone,
CONSTRAINT "criterion_requirement_criterion_id_requirement_id_pk" PRIMARY KEY("criterion_id","requirement_id")
);
--> statement-breakpoint
ALTER TABLE "criterion_requirement" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "evaluation_scenario" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"declared_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "price_line" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"label" text NOT NULL,
"unit" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "requirement" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"ordinal" integer NOT NULL,
"kind" "requirement_kind" NOT NULL,
"text" text NOT NULL,
"response_obligation" text,
"provenance_document_id" uuid,
"provenance_page" integer,
"provenance_span" jsonb,
"confirmation_state" "confirmation_state" DEFAULT 'unconfirmed' NOT NULL,
"confirmed_by" uuid,
"confirmed_at" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "requirement" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "scenario_quantity" (
"scenario_id" uuid NOT NULL,
"price_line_id" uuid NOT NULL,
"quantity" numeric(14, 3) NOT NULL,
CONSTRAINT "scenario_quantity_scenario_id_price_line_id_pk" PRIMARY KEY("scenario_id","price_line_id")
);
--> statement-breakpoint
ALTER TABLE "scenario_quantity" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "solicitation" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"issuer_org_id" uuid NOT NULL,
"local_category_id" uuid NOT NULL,
"title" text NOT NULL,
"stage" "solicitation_stage" DEFAULT 'draft' NOT NULL,
"issued_at" timestamp with time zone,
"responses_due_at" timestamp with time zone,
"acknowledgement_required" boolean DEFAULT false NOT NULL,
"volume_band" text
);
--> statement-breakpoint
ALTER TABLE "solicitation" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "solicitation_amendment" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"class" "amendment_class" NOT NULL,
"summary" text NOT NULL,
"requirement_ids" uuid[] DEFAULT '{}' NOT NULL,
"deadline_extended_to" timestamp with time zone,
"authored_by" uuid NOT NULL,
"authored_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "solicitation_document" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"kind" text NOT NULL,
"blob_ref" text NOT NULL,
"sha256" text NOT NULL
);
--> statement-breakpoint
ALTER TABLE "solicitation_document" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "answer" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"response_id" uuid NOT NULL,
"requirement_id" uuid NOT NULL,
"coverage" "coverage" NOT NULL,
"text" text,
"provenance_document_id" uuid,
"provenance_page" integer,
"provenance_span" jsonb,
"vendor_attested" boolean DEFAULT false NOT NULL,
"reopened_by_amendment_id" uuid
);
--> statement-breakpoint
ALTER TABLE "answer" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "derived_cost" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"response_id" uuid NOT NULL,
"scenario_id" uuid NOT NULL,
"amount" numeric(16, 2) NOT NULL,
"computed_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "derived_cost" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "exception" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"response_id" uuid NOT NULL,
"requirement_id" uuid,
"text" text NOT NULL,
"price_delta" numeric(14, 2)
);
--> statement-breakpoint
ALTER TABLE "exception" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "participation" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"vendor_org_id" uuid NOT NULL,
"state" "participation_state" DEFAULT 'invited' NOT NULL,
"acknowledged_at" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "participation" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "price_quote" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"response_id" uuid NOT NULL,
"price_line_id" uuid NOT NULL,
"rate_structure" jsonb NOT NULL
);
--> statement-breakpoint
ALTER TABLE "price_quote" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "response" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"vendor_org_id" uuid NOT NULL,
"submitted_at" timestamp with time zone,
"attested_by" uuid,
"attested_at" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "response" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "response_document" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"response_id" uuid NOT NULL,
"blob_ref" text NOT NULL,
"sha256" text NOT NULL
);
--> statement-breakpoint
ALTER TABLE "response_document" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "gate_result" (
"response_id" uuid NOT NULL,
"requirement_id" uuid NOT NULL,
"passed" boolean NOT NULL,
"computed_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "gate_result" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "rubric_amendment" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"reason" text NOT NULL,
"voided_score_ids" uuid[] DEFAULT '{}' NOT NULL,
"authored_by" uuid NOT NULL,
"authored_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "score" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"response_id" uuid NOT NULL,
"criterion_id" uuid NOT NULL,
"points" numeric(8, 2) NOT NULL,
"committed_by" uuid NOT NULL,
"committed_at" timestamp with time zone DEFAULT now() NOT NULL,
"derived_from_suggestion_id" uuid,
"voided_by_amendment_id" uuid
);
--> statement-breakpoint
ALTER TABLE "score" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "suggestion" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"response_id" uuid NOT NULL,
"criterion_id" uuid NOT NULL,
"proposed_points" numeric(8, 2),
"anchor_matched" text,
"citations" jsonb DEFAULT '[]'::jsonb NOT NULL,
"confidence" numeric(4, 3),
"model_version" text NOT NULL,
"no_evidence_found" boolean DEFAULT false NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "suggestion" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "export_event" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"actor_id" uuid NOT NULL,
"org_id" uuid NOT NULL,
"capability" text NOT NULL,
"solicitation_id" uuid NOT NULL,
"classes" text[] NOT NULL,
"row_count" integer NOT NULL,
"at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "release_matrix" (
"version" integer NOT NULL,
"class" "disclosure_class" NOT NULL,
"level" "release_level" NOT NULL,
"released" text NOT NULL,
"effective_from" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "release_matrix_version_class_level_pk" PRIMARY KEY("version","class","level")
);
--> statement-breakpoint
CREATE TABLE "document_type" (
"id" text PRIMARY KEY NOT NULL,
"label" text NOT NULL,
"expiry_rule" text
);
--> statement-breakpoint
CREATE TABLE "retailer_acceptance" (
"document_id" uuid NOT NULL,
"retailer_org_id" uuid NOT NULL,
"accepted_at" timestamp with time zone DEFAULT now() NOT NULL,
"vendor_disclosed_name" text,
CONSTRAINT "retailer_acceptance_document_id_retailer_org_id_pk" PRIMARY KEY("document_id","retailer_org_id")
);
--> statement-breakpoint
ALTER TABLE "retailer_acceptance" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "vault_document" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"vendor_org_id" uuid NOT NULL,
"type_id" text NOT NULL,
"blob_ref" text NOT NULL,
"sha256" text NOT NULL,
"expires_at" timestamp with time zone,
"expiry_state" "expiry_state" DEFAULT 'current' NOT NULL,
"expiry_computed_at" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "vault_document" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "entitlement" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"beneficiary_org_id" uuid NOT NULL,
"payer_org_id" uuid NOT NULL,
"tier" "tier" NOT NULL,
"seats" integer,
"started_at" timestamp with time zone DEFAULT now() NOT NULL,
"lapsed_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "confirmation_event" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"requirement_id" uuid NOT NULL,
"confirmed_by" uuid NOT NULL,
"corrected" text,
"at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sweep_finding" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"document_id" uuid NOT NULL,
"kind" "sweep_finding_kind" NOT NULL,
"page" integer NOT NULL,
"span" jsonb NOT NULL,
"quoted_text" text NOT NULL,
"resolved_by_requirement_id" uuid,
"dismissed_by" uuid,
"dismissed_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "vendor_omission_report" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"solicitation_id" uuid NOT NULL,
"vendor_org_id" uuid NOT NULL,
"body" text NOT NULL,
"reported_at" timestamp with time zone DEFAULT now() NOT NULL,
"acted_on_at" timestamp with time zone,
"acted_on_by" uuid
);
--> statement-breakpoint
ALTER TABLE "membership" ADD CONSTRAINT "membership_actor_id_actor_id_fk" FOREIGN KEY ("actor_id") REFERENCES "public"."actor"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "membership" ADD CONSTRAINT "membership_org_id_organization_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "org_capability" ADD CONSTRAINT "org_capability_org_id_organization_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "roster_entry" ADD CONSTRAINT "roster_entry_retailer_org_id_organization_id_fk" FOREIGN KEY ("retailer_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "roster_entry" ADD CONSTRAINT "roster_entry_claimed_vendor_org_id_organization_id_fk" FOREIGN KEY ("claimed_vendor_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "category_change_event" ADD CONSTRAINT "category_change_event_retailer_org_id_organization_id_fk" FOREIGN KEY ("retailer_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "eligibility" ADD CONSTRAINT "eligibility_retailer_org_id_organization_id_fk" FOREIGN KEY ("retailer_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "eligibility" ADD CONSTRAINT "eligibility_vendor_org_id_organization_id_fk" FOREIGN KEY ("vendor_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "eligibility" ADD CONSTRAINT "eligibility_local_category_id_local_category_id_fk" FOREIGN KEY ("local_category_id") REFERENCES "public"."local_category"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "local_category" ADD CONSTRAINT "local_category_retailer_org_id_organization_id_fk" FOREIGN KEY ("retailer_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "local_category" ADD CONSTRAINT "local_category_spine_leaf_id_spine_node_id_fk" FOREIGN KEY ("spine_leaf_id") REFERENCES "public"."spine_node"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "criterion" ADD CONSTRAINT "criterion_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "criterion_requirement" ADD CONSTRAINT "criterion_requirement_criterion_id_criterion_id_fk" FOREIGN KEY ("criterion_id") REFERENCES "public"."criterion"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "criterion_requirement" ADD CONSTRAINT "criterion_requirement_requirement_id_requirement_id_fk" FOREIGN KEY ("requirement_id") REFERENCES "public"."requirement"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "evaluation_scenario" ADD CONSTRAINT "evaluation_scenario_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "price_line" ADD CONSTRAINT "price_line_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "requirement" ADD CONSTRAINT "requirement_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "requirement" ADD CONSTRAINT "requirement_provenance_document_id_solicitation_document_id_fk" FOREIGN KEY ("provenance_document_id") REFERENCES "public"."solicitation_document"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "scenario_quantity" ADD CONSTRAINT "scenario_quantity_scenario_id_evaluation_scenario_id_fk" FOREIGN KEY ("scenario_id") REFERENCES "public"."evaluation_scenario"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "scenario_quantity" ADD CONSTRAINT "scenario_quantity_price_line_id_price_line_id_fk" FOREIGN KEY ("price_line_id") REFERENCES "public"."price_line"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "solicitation" ADD CONSTRAINT "solicitation_issuer_org_id_organization_id_fk" FOREIGN KEY ("issuer_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "solicitation" ADD CONSTRAINT "solicitation_local_category_id_local_category_id_fk" FOREIGN KEY ("local_category_id") REFERENCES "public"."local_category"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "solicitation_amendment" ADD CONSTRAINT "solicitation_amendment_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "solicitation_document" ADD CONSTRAINT "solicitation_document_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "answer" ADD CONSTRAINT "answer_response_id_response_id_fk" FOREIGN KEY ("response_id") REFERENCES "public"."response"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "answer" ADD CONSTRAINT "answer_requirement_id_requirement_id_fk" FOREIGN KEY ("requirement_id") REFERENCES "public"."requirement"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "answer" ADD CONSTRAINT "answer_provenance_document_id_response_document_id_fk" FOREIGN KEY ("provenance_document_id") REFERENCES "public"."response_document"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "derived_cost" ADD CONSTRAINT "derived_cost_response_id_response_id_fk" FOREIGN KEY ("response_id") REFERENCES "public"."response"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "derived_cost" ADD CONSTRAINT "derived_cost_scenario_id_evaluation_scenario_id_fk" FOREIGN KEY ("scenario_id") REFERENCES "public"."evaluation_scenario"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "exception" ADD CONSTRAINT "exception_response_id_response_id_fk" FOREIGN KEY ("response_id") REFERENCES "public"."response"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "exception" ADD CONSTRAINT "exception_requirement_id_requirement_id_fk" FOREIGN KEY ("requirement_id") REFERENCES "public"."requirement"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "participation" ADD CONSTRAINT "participation_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "participation" ADD CONSTRAINT "participation_vendor_org_id_organization_id_fk" FOREIGN KEY ("vendor_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "price_quote" ADD CONSTRAINT "price_quote_response_id_response_id_fk" FOREIGN KEY ("response_id") REFERENCES "public"."response"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "price_quote" ADD CONSTRAINT "price_quote_price_line_id_price_line_id_fk" FOREIGN KEY ("price_line_id") REFERENCES "public"."price_line"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "response" ADD CONSTRAINT "response_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "response" ADD CONSTRAINT "response_vendor_org_id_organization_id_fk" FOREIGN KEY ("vendor_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "response_document" ADD CONSTRAINT "response_document_response_id_response_id_fk" FOREIGN KEY ("response_id") REFERENCES "public"."response"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "gate_result" ADD CONSTRAINT "gate_result_response_id_response_id_fk" FOREIGN KEY ("response_id") REFERENCES "public"."response"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "gate_result" ADD CONSTRAINT "gate_result_requirement_id_requirement_id_fk" FOREIGN KEY ("requirement_id") REFERENCES "public"."requirement"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "score" ADD CONSTRAINT "score_response_id_response_id_fk" FOREIGN KEY ("response_id") REFERENCES "public"."response"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "score" ADD CONSTRAINT "score_criterion_id_criterion_id_fk" FOREIGN KEY ("criterion_id") REFERENCES "public"."criterion"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "score" ADD CONSTRAINT "score_derived_from_suggestion_id_suggestion_id_fk" FOREIGN KEY ("derived_from_suggestion_id") REFERENCES "public"."suggestion"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "suggestion" ADD CONSTRAINT "suggestion_response_id_response_id_fk" FOREIGN KEY ("response_id") REFERENCES "public"."response"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "suggestion" ADD CONSTRAINT "suggestion_criterion_id_criterion_id_fk" FOREIGN KEY ("criterion_id") REFERENCES "public"."criterion"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "retailer_acceptance" ADD CONSTRAINT "retailer_acceptance_document_id_vault_document_id_fk" FOREIGN KEY ("document_id") REFERENCES "public"."vault_document"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "retailer_acceptance" ADD CONSTRAINT "retailer_acceptance_retailer_org_id_organization_id_fk" FOREIGN KEY ("retailer_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "vault_document" ADD CONSTRAINT "vault_document_vendor_org_id_organization_id_fk" FOREIGN KEY ("vendor_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "vault_document" ADD CONSTRAINT "vault_document_type_id_document_type_id_fk" FOREIGN KEY ("type_id") REFERENCES "public"."document_type"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "entitlement" ADD CONSTRAINT "entitlement_beneficiary_org_id_organization_id_fk" FOREIGN KEY ("beneficiary_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "entitlement" ADD CONSTRAINT "entitlement_payer_org_id_organization_id_fk" FOREIGN KEY ("payer_org_id") REFERENCES "public"."organization"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "confirmation_event" ADD CONSTRAINT "confirmation_event_requirement_id_requirement_id_fk" FOREIGN KEY ("requirement_id") REFERENCES "public"."requirement"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sweep_finding" ADD CONSTRAINT "sweep_finding_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sweep_finding" ADD CONSTRAINT "sweep_finding_document_id_solicitation_document_id_fk" FOREIGN KEY ("document_id") REFERENCES "public"."solicitation_document"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sweep_finding" ADD CONSTRAINT "sweep_finding_resolved_by_requirement_id_requirement_id_fk" FOREIGN KEY ("resolved_by_requirement_id") REFERENCES "public"."requirement"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "vendor_omission_report" ADD CONSTRAINT "vendor_omission_report_solicitation_id_solicitation_id_fk" FOREIGN KEY ("solicitation_id") REFERENCES "public"."solicitation"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE POLICY "scenario_quantity_read" ON "scenario_quantity" AS PERMISSIVE FOR SELECT TO public USING (class_released(release_level_for_solicitation(
(SELECT solicitation_id FROM evaluation_scenario WHERE id = scenario_id)
), 'scenario_quantity'));--> statement-breakpoint
CREATE POLICY "answer_read" ON "answer" AS PERMISSIVE FOR SELECT TO public USING (class_released(release_level_for_response(response_id), 'answer_text'));--> statement-breakpoint
CREATE POLICY "derived_cost_read" ON "derived_cost" AS PERMISSIVE FOR SELECT TO public USING (class_released(release_level_for_response(response_id), 'derived_cost'));--> statement-breakpoint
CREATE POLICY "exception_read" ON "exception" AS PERMISSIVE FOR SELECT TO public USING (class_released(release_level_for_response(response_id), 'exception_text'));--> statement-breakpoint
CREATE POLICY "price_quote_read" ON "price_quote" AS PERMISSIVE FOR SELECT TO public USING (class_released(release_level_for_response(response_id), 'price_quote'));--> statement-breakpoint
CREATE POLICY "score_read" ON "score" AS PERMISSIVE FOR SELECT TO public USING (class_released(release_level_for_response(response_id), 'own_scoring'));

View File

@@ -0,0 +1,35 @@
-- Release matrix, version 1. Fixed by #14.
--
-- A rule change is a NEW VERSION, never an UPDATE. Without the version history
-- a past release cannot be reconstructed when an award is protested — the one
-- thing the function form of these rules costs.
--
-- Mirrored in src/release/matrix.ts, which the evaluation surface renders its
-- dimmed cells from. The screen and the policy must not be able to disagree.
INSERT INTO release_matrix (version, class, level, released) VALUES
-- Non-content pre-bid signal: who opened, who acknowledged, who intends to
-- bid. This is what #12 actually promised the retailer, and it is the reason
-- sealing response content costs them nothing they were counting on.
(1, 'vendor_identity', 'invited', 'true'),
(1, 'participation_signal', 'invited', 'true'),
-- Exact quantities behind the acknowledgement gate. The coarse volume band
-- stays in the teaser (#14 decision 4).
(1, 'scenario_quantity', 'acknowledged', 'true'),
-- Sealed until the deadline, then the whole field at once.
(1, 'answer_text', 'open', 'true'),
(1, 'exception_text', 'open', 'true'),
(1, 'vault_document', 'open', 'true'),
(1, 'price_quote', 'open', 'true'),
(1, 'derived_cost', 'open', 'true'),
-- A vendor's own scoring, released to them at award. They never see anything
-- of the field — no count, no identities, no rank including their own.
(1, 'own_scoring', 'awarded', 'true');
-- TWO-ENVELOPE, deferred not declined: moving price_quote and derived_cost to a
-- level reached only after scoring locks is a version bump here plus an
-- irreversible lock transition. That is the point of choosing a matrix over
-- lifecycle logic written inline in each policy.

View File

@@ -0,0 +1,18 @@
{
"id": "7df8b799-6a58-4fb1-9143-d9a3530a8672",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {},
"enums": {},
"schemas": {},
"views": {},
"sequences": {},
"roles": {},
"policies": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,27 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1785791975838,
"tag": "0000_release_level_functions",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1785792002292,
"tag": "0001_initial",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1785792003081,
"tag": "0002_seed_release_matrix",
"breakpoints": true
}
]
}