-- +goose Up -- WS3 clearance reference layer. Four GLOBAL reference tables (no organization_id, outside RLS, app -- SELECT only, migrator writes), FK enforced on the candidate and requirement clearance columns. Adds -- compartment array columns to candidates and requirements for additive compartment aware scoring. The -- six component weights, the bands, and the 0.62 threshold are unchanged; this registers ModelVersion -- v1.3.0 for the new compartment match dimension. CREATE TABLE clearance_levels ( code text PRIMARY KEY, rank int NOT NULL UNIQUE, requires_polygraph boolean NOT NULL DEFAULT false, label text NOT NULL ); INSERT INTO clearance_levels (code, rank, label) VALUES ('unknown',0,'Unknown'),('none',1,'None or Public Trust'),('confidential',2,'Confidential'), ('secret',3,'Secret'),('top_secret',4,'Top Secret'),('ts_sci',5,'Top Secret SCI'); CREATE TABLE polygraph_types ( code text PRIMARY KEY, rank int NOT NULL UNIQUE, label text NOT NULL ); INSERT INTO polygraph_types (code, rank, label) VALUES ('none',0,'None'),('ci',1,'Counterintelligence'),('full_scope',2,'Full Scope'); CREATE TABLE clearance_compartments ( code text PRIMARY KEY, kind text NOT NULL CHECK (kind IN ('sci','sap')), label text NOT NULL ); -- Publicly documented SCI control systems plus generic markers. A SAP is named per program; SAP here is -- the generic marker, specific programs are added by the customer. INSERT INTO clearance_compartments (code, kind, label) VALUES ('SCI','sci','Sensitive Compartmented Information (generic)'), ('SI','sci','Special Intelligence (SIGINT)'), ('TK','sci','Talent Keyhole (overhead collection)'), ('HCS','sci','HUMINT Control System'), ('SAP','sap','Special Access Program (generic)'); -- Stub for future non rank reciprocity exceptions (agency specific). The engine uses the rank ladder -- today; this table documents and will later carry exceptions. Seeded empty. CREATE TABLE clearance_reciprocity ( held_code text NOT NULL REFERENCES clearance_levels(code), required_code text NOT NULL REFERENCES clearance_levels(code), satisfies boolean NOT NULL, source text NOT NULL DEFAULT '', PRIMARY KEY (held_code, required_code) ); ALTER TABLE candidates ADD COLUMN clearance_compartments text[] NOT NULL DEFAULT '{}'; ALTER TABLE requirements ADD COLUMN required_compartments text[] NOT NULL DEFAULT '{}'; -- FK enforce the clearance codes against the reference tables (the existing CHECK constraints already -- bound the values to exactly these codes, so the FKs are satisfiable on existing rows). ALTER TABLE candidates ADD CONSTRAINT candidates_clearance_level_fk FOREIGN KEY (clearance_level) REFERENCES clearance_levels(code); ALTER TABLE candidates ADD CONSTRAINT candidates_clearance_poly_fk FOREIGN KEY (clearance_poly) REFERENCES polygraph_types(code); ALTER TABLE requirements ADD CONSTRAINT requirements_required_level_fk FOREIGN KEY (required_level) REFERENCES clearance_levels(code); ALTER TABLE requirements ADD CONSTRAINT requirements_required_poly_fk FOREIGN KEY (required_poly) REFERENCES polygraph_types(code); GRANT SELECT ON clearance_levels, polygraph_types, clearance_compartments, clearance_reciprocity TO missionmatch_app; INSERT INTO aedt_model_versions (version, weights, band_cuts, notes) VALUES ( 'v1.3.0', '{"clearance":0.25,"skills":0.25,"certifications":0.15,"customer_experience":0.15,"experience":0.10,"location_availability":0.10}', '{"green":90,"yellow":75}', 'Adds an additive compartment dimension to the clearance component, and makes clearance levels, polygraph types, and compartments FK enforced reference data. A requirement that lists compartments is met only by a held clearance carrying them all. The level and poly logic, the binary 0 or 100 clearance score, the six weights, the bands, and the 0.62 threshold are unchanged from v1.2.0. Clearance remains a self reported indicator, never an input proxy for a protected attribute.' ) ON CONFLICT (version) DO NOTHING; -- +goose Down DELETE FROM aedt_model_versions WHERE version = 'v1.3.0'; ALTER TABLE requirements DROP CONSTRAINT requirements_required_poly_fk; ALTER TABLE requirements DROP CONSTRAINT requirements_required_level_fk; ALTER TABLE candidates DROP CONSTRAINT candidates_clearance_poly_fk; ALTER TABLE candidates DROP CONSTRAINT candidates_clearance_level_fk; ALTER TABLE requirements DROP COLUMN required_compartments; ALTER TABLE candidates DROP COLUMN clearance_compartments; DROP TABLE clearance_reciprocity; DROP TABLE clearance_compartments; DROP TABLE polygraph_types; DROP TABLE clearance_levels;