···
create table if not exists migrations (
id integer primary key autoincrement,
···
+
create table if not exists label_definitions (
+
id integer primary key autoincrement,
+
at_uri text generated always as ('at://' || did || '/' || 'sh.tangled.label.definition' || '/' || rkey) stored,
+
value_type text not null check (value_type in (
+
value_format text not null default "any",
+
value_enum text, -- comma separated list
+
multiple integer not null default 0,
+
created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
+
-- ops are flattened, a record may contain several additions and deletions, but the table will include one row per add/del
+
create table if not exists label_ops (
+
id integer primary key autoincrement,
+
at_uri text generated always as ('at://' || did || '/' || 'sh.tangled.label.op' || '/' || rkey) stored,
+
operation text not null check (operation in ("add", "del")),
+
operand_key text not null,
+
operand_value text not null,
+
-- we need two time values: performed is declared by the user, indexed is calculated by the av
+
performed text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
+
indexed text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
+
-- traditionally (did, rkey) pair should be unique, but not in this case
+
-- operand_key should reference a label definition
+
foreign key (operand_key) references label_definitions (at_uri) on delete cascade,
+
unique (did, rkey, subject, operand_key, operand_value)
+
create table if not exists repo_labels (
+
id integer primary key autoincrement,
+
-- label to subscribe to
+
label_at text not null,
+
unique (repo_at, label_at),
+
foreign key (label_at) references label_definitions (at_uri)
create table if not exists migrations (
id integer primary key autoincrement,