-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
135 lines (109 loc) · 4.79 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
-- FIXME: Not thrilled about normalizing the wiki and type, but this seemed
-- like an easy way to guarantee data integrity.
-- Reference table pointing to external wiki db.
create table if not exists wiki_ref (
wiki_id integer unsigned not null primary key auto_increment,
-- Wiki key, implicit foreign key to sites.site_global_key
wiki_global_key varchar(32) not null
-- TODO: How do we get the translated, natural language name? Or can we
-- avoid rendering that?
);
create unique index wr_dbname
on wiki_ref (wiki_global_key);
-- Reference table defining the types of wiki artifact we support.
create table if not exists artifact_type (
type_id integer unsigned not null primary key auto_increment,
-- Machine name for this artifact type, e.g. "diff", "revision", "page".
type_name varchar(64) not null
);
create unique index at_type
on artifact_type (type_name);
-- Record pointing to an on-wiki artifact being judged. These are unique, each
-- wiki artifact will have 0..1 records in this table.
create table if not exists artifact (
-- Automatic primary key.
artifact_id integer unsigned not null primary key auto_increment,
-- Wiki where this artifact lives.
wiki_id integer unsigned not null,
-- Artifact type
type_id integer unsigned not null,
-- Implicit, variable foreign key to the external database, target depends on wiki and type.
onwiki_id integer unsigned not null
);
create index art_wiki
on artifact (wiki_id);
create index art_type
on artifact (type_id);
create unique index art_target
on artifact (wiki_id, type_id, onwiki_id);
alter table artifact
add constraint fk_art_wiki foreign key (wiki_id) references wiki_ref (wiki_id)
on delete restrict on update cascade;
-- add foreign key (type_id) references artifact_type (type_id)
-- on update cascade on delete restrict;
-- Note that the target database and column can vary, so the onwiki foreign key
-- relationship cannot be enforced, (onwiki_id) -> wikidb#tablename.id_column
create table if not exists judgment (
judgment_id integer unsigned not null primary key auto_increment,
-- Foreign key to an artifact's primary key.
judgment_artifact_id integer unsigned not null,
-- Global wiki user ID creating this judgment.
judgment_user_id integer unsigned not null,
judgment_created datetime not null,
-- Modified time is only touched when changing rank.
judgment_modified datetime not null,
-- Optional link to freeform text comment, conent may be embedded within a page.
judgment_comment varbinary(255) null,
-- A judgment may be promoted or deprecated for various TBD reasons.
judgment_rank enum ('preferred', 'normal', 'deprecated'),
-- Bitfield of who can access this judgment. Zero means public.
-- Value can only be changed with admin privileges.
-- TBD: We might not need this, if oversight can be isolated to Flow comments.
visibility tinyint not null default 0
);
create index ju_artifact
on judgment (judgment_artifact_id);
create index ju_created
on judgment (judgment_created);
create index ju_rank
on judgment (rank);
create index ju_visibility
on judgment (visibility);
alter table judgment
add foreign key (judgment_artifact_id) references artifact(artifact_id)
on update cascade on delete restrict;
create table if not exists scoring_schema (
schema_id integer unsigned not null primary key auto_increment,
schema_name varchar(64) not null,
schema_version varchar(64) not null,
schema_definition blob not null
);
create index sc_name
on scoring_schema (schema_name);
create index sc_version
on scoring_schema (schema_version);
create unique index sc_ref
on scoring_schema (schema_name, schema_version);
create table if not exists judgment_score (
judgment_score_id integer unsigned not null primary key auto_increment,
-- Judgment this score belongs to.
judgment_id integer unsigned not null,
-- Schema defining what data this score may contain.
schema_id integer unsigned not null,
-- Score data, conforming to the given schema.
data blob not null,
created datetime not null,
-- Note: Scores can only be deprecated, not modified.
);
create index js_judgment
on judgment_score (judgment_id);
create index js_schema
on judgment_score (schema_id);
alter table judgment_score
add constraint fk_js_judgment foreign key (judgment_id) references judgment(judgment_id)
on delete cascade on update cascade,
add constraint fk_js_schema foreign key (schema_id) references scoring_schema(schema_id)
on delete cascade on update cascade;
-- Each user may only provide one non-deprecated score per schema, per
-- artifact. This constraint is enforced in code, and newer scores will
-- deprecate older.