forked from tangled.org/core
Monorepo for Tangled

appview/db: add tables for label.definition and label.op

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li c5adf8c9 15df4a8b

verified
Changed files
+65
appview
db
+65
appview/db/db.go
··· 466 466 primary key (did, rkey) 467 467 ); 468 468 469 + create table if not exists label_definitions ( 470 + -- identifiers 471 + id integer primary key autoincrement, 472 + did text not null, 473 + rkey text not null, 474 + at_uri text generated always as ('at://' || did || '/' || 'sh.tangled.label.definition' || '/' || rkey) stored, 475 + 476 + -- content 477 + name text not null, 478 + value_type text not null check (value_type in ( 479 + "null", 480 + "boolean", 481 + "integer", 482 + "string" 483 + )), 484 + value_format text not null default "any", 485 + value_enum text, -- comma separated list 486 + scope text not null, 487 + color text, 488 + multiple integer not null default 0, 489 + created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 490 + 491 + -- constraints 492 + unique (did, rkey) 493 + unique (at_uri) 494 + ); 495 + 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 ( 498 + -- identifiers 499 + id integer primary key autoincrement, 500 + did text not null, 501 + rkey text not null, 502 + at_uri text generated always as ('at://' || did || '/' || 'sh.tangled.label.op' || '/' || rkey) stored, 503 + 504 + -- content 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')), 512 + 513 + -- constraints 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) 518 + ); 519 + 520 + create table if not exists repo_labels ( 521 + -- identifiers 522 + id integer primary key autoincrement, 523 + 524 + -- repo identifiers 525 + repo_at text not null, 526 + 527 + -- label to subscribe to 528 + label_at text not null, 529 + 530 + unique (repo_at, label_at), 531 + foreign key (label_at) references label_definitions (at_uri) 532 + ); 533 + 469 534 create table if not exists migrations ( 470 535 id integer primary key autoincrement, 471 536 name text unique