proofchain/packages/infra/schema/60_worker_credentials.sql
caelum0x bac8f9e662 feat: Wave C+D — agent multi-skill verification engine + infra data layer
- agent: 6 auto-collecting registries (parsers/checks/risk/scoring/tools/pipelines);
  15 doc parsers, 12 check packs, 6 risk models, scoring dimensions + reconciler,
  ~15 Claude tools, 8 pipelines (financing/underwriting/dpp/compliance/grading/esg) + routes; 380 tests
- infra: BaseRepository + ~35 typed repositories, 56 composed schema modules,
  storage/queue/notifications/cache/events adapters; 203 tests
- pnpm -r typecheck/build/test all green

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-31 23:48:46 +03:00

45 lines
2.3 KiB
SQL

-- =============================================================================
-- Workforce — Worker credentials read model. Populated by the @proofchain/api
-- indexer from the WorkerCredential (soulbound ERC721) contract. Non-transferable
-- identity/qualification credentials bound to a worker address. Conventions
-- mirror 00_core.sql (hex CHECKs, RLS, idempotent DDL).
-- =============================================================================
create table if not exists worker_credentials (
id text primary key,
token_id text,
worker text not null check (worker ~ '^0x[0-9a-f]{40}$'),
issuer text check (issuer is null or issuer ~ '^0x[0-9a-f]{40}$'),
credential_type text not null default 'identity'
check (credential_type in ('identity', 'license', 'certification',
'membership', 'clearance')),
title text,
status text not null default 'active'
check (status in ('active', 'suspended', 'revoked', 'expired')),
issued_at timestamptz,
expiry_date timestamptz,
uri text,
metadata jsonb not null default '{}'::jsonb,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index if not exists worker_credentials_worker_idx on worker_credentials (worker);
create index if not exists worker_credentials_issuer_idx on worker_credentials (issuer);
create index if not exists worker_credentials_type_idx on worker_credentials (credential_type);
create index if not exists worker_credentials_status_idx on worker_credentials (status);
do $$
declare
t text;
tables text[] := array['worker_credentials'];
begin
foreach t in array tables loop
execute format('drop trigger if exists %I_set_updated_at on %I', t, t);
execute format('create trigger %I_set_updated_at before update on %I for each row execute function set_updated_at()', t, t);
execute format('alter table %I enable row level security', t);
execute format('drop policy if exists %I_read_all on %I', t, t);
execute format('create policy %I_read_all on %I for select to anon, authenticated using (true)', t, t);
end loop;
end
$$;