···466466 primary key (did, rkey)467467 );468468469469+ create table if not exists label_definitions (470470+ -- identifiers471471+ id integer primary key autoincrement,472472+ did text not null,473473+ rkey text not null,474474+ at_uri text generated always as ('at://' || did || '/' || 'sh.tangled.label.definition' || '/' || rkey) stored,475475+476476+ -- content477477+ name text not null,478478+ value_type text not null check (value_type in (479479+ "null",480480+ "boolean",481481+ "integer",482482+ "string"483483+ )),484484+ value_format text not null default "any",485485+ value_enum text, -- comma separated list486486+ scope text not null,487487+ color text,488488+ multiple integer not null default 0,489489+ created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),490490+491491+ -- constraints492492+ unique (did, rkey)493493+ unique (at_uri)494494+ );495495+496496+ -- ops are flattened, a record may contain several additions and deletions, but the table will include one row per add/del497497+ create table if not exists label_ops (498498+ -- identifiers499499+ id integer primary key autoincrement,500500+ did text not null,501501+ rkey text not null,502502+ at_uri text generated always as ('at://' || did || '/' || 'sh.tangled.label.op' || '/' || rkey) stored,503503+504504+ -- content505505+ subject text not null,506506+ operation text not null check (operation in ("add", "del")),507507+ operand_key text not null,508508+ operand_value text not null,509509+ -- we need two time values: performed is declared by the user, indexed is calculated by the av510510+ performed text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),511511+ indexed text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),512512+513513+ -- constraints514514+ -- traditionally (did, rkey) pair should be unique, but not in this case515515+ -- operand_key should reference a label definition516516+ foreign key (operand_key) references label_definitions (at_uri) on delete cascade,517517+ unique (did, rkey, subject, operand_key, operand_value)518518+ );519519+520520+ create table if not exists repo_labels (521521+ -- identifiers522522+ id integer primary key autoincrement,523523+524524+ -- repo identifiers525525+ repo_at text not null,526526+527527+ -- label to subscribe to528528+ label_at text not null,529529+530530+ unique (repo_at, label_at),531531+ foreign key (label_at) references label_definitions (at_uri)532532+ );533533+469534 create table if not exists migrations (470535 id integer primary key autoincrement,471536 name text unique