| 1 | -- Attachments on work items (attachments.rs): a work item filed without a |
| 2 | -- repository takes files too, kept by the work item (`item_id`, with its |
| 3 | -- `workspace`, so a deleted workspace's go with it) instead of a |
| 4 | -- repository. Each row names one or the other. |
| 5 | CREATE TABLE attachments_new ( |
| 6 | id TEXT PRIMARY KEY, |
| 7 | repo_id TEXT, |
| 8 | item_id TEXT, |
| 9 | workspace TEXT, |
| 10 | user_id TEXT NOT NULL, |
| 11 | name TEXT NOT NULL, |
| 12 | content_type TEXT NOT NULL, |
| 13 | size INTEGER NOT NULL, |
| 14 | created_at TEXT NOT NULL, |
| 15 | CHECK (repo_id IS NOT NULL OR item_id IS NOT NULL) |
| 16 | ); |
| 17 | |
| 18 | INSERT INTO attachments_new (id, repo_id, user_id, name, content_type, size, created_at) |
| 19 | SELECT id, repo_id, user_id, name, content_type, size, created_at FROM attachments; |
| 20 | |
| 21 | DROP TABLE attachments; |
| 22 | ALTER TABLE attachments_new RENAME TO attachments; |
| 23 | |
| 24 | CREATE INDEX attachments_by_repo ON attachments (repo_id); |
| 25 | CREATE INDEX attachments_by_workspace ON attachments (workspace) WHERE workspace IS NOT NULL; |