max / makenotwork
| 1 | -- Track which versions a user has downloaded, so the library can show |
| 2 | -- "already downloaded" vs "new version available". |
| 3 | NOT EXISTS user_downloads ( |
| 4 | user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, |
| 5 | item_id UUID NOT NULL REFERENCES items(id) ON DELETE CASCADE, |
| 6 | version_id UUID NOT NULL REFERENCES versions(id) ON DELETE CASCADE, |
| 7 | downloaded_at TIMESTAMPTZ NOT NULL DEFAULT NOW, |
| 8 | PRIMARY KEY (user_id, item_id, version_id) |
| 9 | ); |
| 10 | |
| 11 | NOT EXISTS idx_user_downloads_user_item ON user_downloads(user_id, item_id); |
| 12 |