···
469
+
create table if not exists label_definitions (
471
+
id integer primary key autoincrement,
473
+
rkey text not null,
474
+
at_uri text generated always as ('at://' || did || '/' || 'sh.tangled.label.definition' || '/' || rkey) stored,
477
+
name text not null,
478
+
value_type text not null check (value_type in (
484
+
value_format text not null default "any",
485
+
value_enum text, -- comma separated list
486
+
scope text not null,
488
+
multiple integer not null default 0,
489
+
created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
496
+
-- ops are flattened, a record may contain several additions and deletions, but the table will include one row per add/del
497
+
create table if not exists label_ops (
499
+
id integer primary key autoincrement,
501
+
rkey text not null,
502
+
at_uri text generated always as ('at://' || did || '/' || 'sh.tangled.label.op' || '/' || rkey) stored,
505
+
subject text not null,
506
+
operation text not null check (operation in ("add", "del")),
507
+
operand_key text not null,
508
+
operand_value text not null,
509
+
-- we need two time values: performed is declared by the user, indexed is calculated by the av
510
+
performed text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
511
+
indexed text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
514
+
-- traditionally (did, rkey) pair should be unique, but not in this case
515
+
-- operand_key should reference a label definition
516
+
foreign key (operand_key) references label_definitions (at_uri) on delete cascade,
517
+
unique (did, rkey, subject, operand_key, operand_value)
520
+
create table if not exists repo_labels (
522
+
id integer primary key autoincrement,
524
+
-- repo identifiers
525
+
repo_at text not null,
527
+
-- label to subscribe to
528
+
label_at text not null,
530
+
unique (repo_at, label_at),
531
+
foreign key (label_at) references label_definitions (at_uri)
create table if not exists migrations (
id integer primary key autoincrement,