···104104 foreign key (repo_at, issue_id) references issues(repo_at, issue_id) on delete cascade
105105 );
106106 create table if not exists pulls (
107107+ -- identifiers
107108 id integer primary key autoincrement,
109109+ pull_id integer not null,
110110+111111+ -- at identifiers
112112+ repo_at text not null,
108113 owner_did text not null,
109109- repo_at text not null,
110110- pull_id integer not null,
114114+ rkey text not null,
115115+ pull_at text,
116116+117117+ -- content
111118 title text not null,
112119 body text not null,
113113- patch text,
114114- pull_at text,
115115- rkey text not null,
116120 target_branch text not null,
117121 state integer not null default 0 check (state in (0, 1, 2)), -- open, merged, closed
122122+123123+ -- meta
118124 created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
125125+126126+ -- constraints
119127 unique(repo_at, pull_id),
120128 foreign key (repo_at) references repos(at_uri) on delete cascade
121129 );
130130+131131+ -- every pull must have atleast 1 submission: the initial submission
132132+ create table if not exists pull_submissions (
133133+ -- identifiers
134134+ id integer primary key autoincrement,
135135+ pull_id integer not null,
136136+137137+ -- at identifiers
138138+ repo_at text not null,
139139+140140+ -- content, these are immutable, and require a resubmission to update
141141+ round_number integer not null default 0,
142142+ patch text,
143143+144144+ -- meta
145145+ created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
146146+147147+ -- constraints
148148+ unique(repo_at, pull_id, round_number),
149149+ foreign key (repo_at, pull_id) references pulls(repo_at, pull_id) on delete cascade
150150+ );
151151+122152 create table if not exists pull_comments (
153153+ -- identifiers
123154 id integer primary key autoincrement,
124124- owner_did text not null,
125155 pull_id integer not null,
156156+ submission_id integer not null,
157157+158158+ -- at identifiers
126159 repo_at text not null,
127127- comment_id integer not null,
160160+ owner_did text not null,
128161 comment_at text not null,
162162+163163+ -- content
129164 body text not null,
165165+166166+ -- meta
130167 created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
131131- unique(pull_id, comment_id),
132132- foreign key (repo_at, pull_id) references pulls(repo_at, pull_id) on delete cascade
168168+169169+ -- constraints
170170+ foreign key (repo_at, pull_id) references pulls(repo_at, pull_id) on delete cascade,
171171+ foreign key (submission_id) references pull_submissions(id) on delete cascade
133172 );
173173+134174 create table if not exists _jetstream (
135175 id integer primary key autoincrement,
136176 last_time_us integer not null