···331331 unique(instance)
332332 );
333333334334+ create table if not exists pipelines (
335335+ -- identifiers
336336+ id integer primary key autoincrement,
337337+ knot text not null,
338338+ rkey text not null,
339339+340340+ repo_owner text not null,
341341+ repo_name text not null,
342342+343343+ -- every pipeline must be associated with exactly one commit
344344+ sha text not null check (length(sha) = 40),
345345+346346+ -- trigger data
347347+ trigger_id integer not null,
348348+349349+ unique(knot, rkey),
350350+ foreign key (trigger_id) references triggers(id) on delete cascade
351351+ );
352352+353353+ create table if not exists triggers (
354354+ -- primary key
355355+ id integer primary key autoincrement,
356356+357357+ -- top-level fields
358358+ kind text not null,
359359+360360+ -- pushTriggerData fields
361361+ push_ref text,
362362+ push_new_sha text check (length(push_new_sha) = 40),
363363+ push_old_sha text check (length(push_old_sha) = 40),
364364+365365+ -- pullRequestTriggerData fields
366366+ pr_source_branch text,
367367+ pr_target_branch text,
368368+ pr_source_sha text check (length(pr_source_sha) = 40),
369369+ pr_action text
370370+ );
371371+372372+ create table if not exists pipeline_statuses (
373373+ -- identifiers
374374+ id integer primary key autoincrement,
375375+ spindle text not null,
376376+ rkey text not null,
377377+378378+ -- referenced pipeline. these form the (did, rkey) pair
379379+ pipeline_knot text not null,
380380+ pipeline_rkey text not null,
381381+382382+ -- content
383383+ created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
384384+ workflow text not null,
385385+ status text not null,
386386+ error text,
387387+ exit_code integer not null default 0,
388388+389389+ unique (spindle, rkey),
390390+ foreign key (pipeline_knot, pipeline_rkey)
391391+ references pipelines (knot, rkey)
392392+ on delete cascade
393393+ );
394394+334395 create table if not exists migrations (
335396 id integer primary key autoincrement,
336397 name text unique
337337- )
398398+ );
338399 `)
339400 if err != nil {
340401 return nil, err