-- The consolidated schema of the knowledge base: what a fresh database is given at once, and what every -- migration in migrations/ applied in order comes to (the test TestTheConsolidatedSchemaIsTheMigrationsApplied -- holds the two equal). Consolidated through migration 0001. create table record ( kind text not null check (kind in ('decision', 'research')), number integer not null check (number > 0), status text not null, topic text not null default '', current_version integer not null, pending_version integer, revision bigint not null default 1, search tsvector not null default ''::tsvector, primary key (kind, number) ); create index record_search on record using gin (search); create index record_topic on record (topic); create table version ( kind text not null, number integer not null, n integer not null check (n > 0), by text not null, at timestamptz not null, why text not null, insight boolean not null default false, body jsonb not null, primary key (kind, number, n), foreign key (kind, number) references record (kind, number) ); create table clause ( kind text not null, number integer not null, n integer not null check (n > 0), text text not null, status text not null, source text not null, search tsvector not null, primary key (kind, number, n), foreign key (kind, number) references record (kind, number) ); create index clause_search on clause using gin (search); create table link ( from_kind text not null, from_number integer not null, from_clause integer not null default 0, kind text not null, to_kind text not null, to_number integer not null default 0, to_clause integer not null default 0, to_path text not null default '', body jsonb not null, foreign key (from_kind, from_number) references record (kind, number) ); create index link_from on link (from_kind, from_number); create index link_to on link (to_kind, to_number); create table finding ( rule text not null, records text[] not null, says text not null, at timestamptz not null ); create table told ( topic text primary key, at timestamptz not null default now() );