···11--- Simplified SQLite Database Migration Script for Issues and Comments22-33--- Migration for issues table44-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 cascade1616-);1717-1818--- Migrate data to new issues table1919-INSERT INTO issues_new (2020- id, owner_did, repo_at, issue_id,2121- title, body, open, created, issue_at2222-)2323-SELECT2424- id, owner_did, repo_at, issue_id,2525- title, body, open, created, issue_at2626-FROM issues;2727-2828--- Drop old issues table2929-DROP TABLE issues;3030-3131--- Rename new issues table3232-ALTER TABLE issues_new RENAME TO issues;3333-3434--- Migration for comments table3535-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 cascade4646-);4747-4848--- Migrate data to new comments table4949-INSERT INTO comments_new (5050- id, owner_did, issue_id, repo_at,5151- comment_id, comment_at, body, created5252-)5353-SELECT5454- id, owner_did, issue_id, repo_at,5555- comment_id, comment_at, body, created5656-FROM comments;5757-5858--- Drop old comments table5959-DROP TABLE comments;6060-6161--- Rename new comments table6262-ALTER TABLE comments_new RENAME TO comments;
-66
appview/db/migrations/validate.sql
···11--- Validation Queries for Database Migration22-33--- 1. Verify Issues Table Structure44-PRAGMA table_info(issues);55-66--- 2. Verify Comments Table Structure77-PRAGMA table_info(comments);88-99--- 3. Check Total Row Count Consistency1010-SELECT1111- 'Issues Row Count' AS check_type,1212- (SELECT COUNT(*) FROM issues) AS row_count1313-UNION ALL1414-SELECT1515- 'Comments Row Count' AS check_type,1616- (SELECT COUNT(*) FROM comments) AS row_count;1717-1818--- 4. Verify Unique Constraint on Issues1919-SELECT2020- repo_at,2121- issue_id,2222- COUNT(*) as duplicate_count2323-FROM issues2424-GROUP BY repo_at, issue_id2525-HAVING duplicate_count > 1;2626-2727--- 5. Verify Foreign Key Integrity for Comments2828-SELECT2929- 'Orphaned Comments' AS check_type,3030- COUNT(*) AS orphaned_count3131-FROM comments c3232-LEFT JOIN issues i ON c.repo_at = i.repo_at AND c.issue_id = i.issue_id3333-WHERE i.id IS NULL;3434-3535--- 6. Check Foreign Key Constraint3636-PRAGMA foreign_key_list(comments);3737-3838--- 7. Sample Data Integrity Check3939-SELECT4040- 'Sample Issues' AS check_type,4141- repo_at,4242- issue_id,4343- title,4444- created4545-FROM issues4646-LIMIT 5;4747-4848--- 8. Sample Comments Data Integrity Check4949-SELECT5050- 'Sample Comments' AS check_type,5151- repo_at,5252- issue_id,5353- comment_id,5454- body,5555- created5656-FROM comments5757-LIMIT 5;5858-5959--- 9. Verify Constraint on Comments (Issue ID and Comment ID Uniqueness)6060-SELECT6161- issue_id,6262- comment_id,6363- COUNT(*) as duplicate_count6464-FROM comments6565-GROUP BY issue_id, comment_id6666-HAVING duplicate_count > 1;