···11+-- Simplified SQLite Database Migration Script for Issues and Comments
22+33+-- Migration for issues table
44+CREATE TABLE issues_new (
55+ id integer primary key autoincrement,
66+ owner_did text not null,
77+ repo_at text not null,
88+ issue_id integer not null,
99+ title text not null,
1010+ body text not null,
1111+ open integer not null default 1,
1212+ created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
1313+ issue_at text,
1414+ unique(repo_at, issue_id),
1515+ foreign key (repo_at) references repos(at_uri) on delete cascade
1616+);
1717+1818+-- Migrate data to new issues table
1919+INSERT INTO issues_new (
2020+ id, owner_did, repo_at, issue_id,
2121+ title, body, open, created, issue_at
2222+)
2323+SELECT
2424+ id, owner_did, repo_at, issue_id,
2525+ title, body, open, created, issue_at
2626+FROM issues;
2727+2828+-- Drop old issues table
2929+DROP TABLE issues;
3030+3131+-- Rename new issues table
3232+ALTER TABLE issues_new RENAME TO issues;
3333+3434+-- Migration for comments table
3535+CREATE TABLE comments_new (
3636+ id integer primary key autoincrement,
3737+ owner_did text not null,
3838+ issue_id integer not null,
3939+ repo_at text not null,
4040+ comment_id integer not null,
4141+ comment_at text not null,
4242+ body text not null,
4343+ created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
4444+ unique(issue_id, comment_id),
4545+ foreign key (repo_at, issue_id) references issues(repo_at, issue_id) on delete cascade
4646+);
4747+4848+-- Migrate data to new comments table
4949+INSERT INTO comments_new (
5050+ id, owner_did, issue_id, repo_at,
5151+ comment_id, comment_at, body, created
5252+)
5353+SELECT
5454+ id, owner_did, issue_id, repo_at,
5555+ comment_id, comment_at, body, created
5656+FROM comments;
5757+5858+-- Drop old comments table
5959+DROP TABLE comments;
6060+6161+-- Rename new comments table
6262+ALTER TABLE comments_new RENAME TO comments;