mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-08 23:18:15 -07:00
fix: release associations and add cleanup migration (#168)
* fix: release associations and add cleanup migration * fix: incorrect test
This commit is contained in:
parent
16cee8cfca
commit
cb4d177875
9 changed files with 106 additions and 26 deletions
|
|
@ -15,11 +15,17 @@ BEGIN
|
|||
DELETE FROM tracks WHERE id NOT IN (SELECT l.track_id FROM listens l);
|
||||
DELETE FROM releases WHERE id NOT IN (SELECT t.release_id FROM tracks t);
|
||||
DELETE FROM artists WHERE id NOT IN (SELECT at.artist_id FROM artist_tracks at);
|
||||
DELETE FROM artist_releases ar
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM artist_tracks at
|
||||
JOIN tracks t ON at.track_id = t.id
|
||||
WHERE at.artist_id = ar.artist_id
|
||||
AND t.release_id = ar.release_id
|
||||
);
|
||||
END $$
|
||||
`
|
||||
|
||||
// DELETE FROM releases WHERE release_group_id NOT IN (SELECT t.release_group_id FROM tracks t);
|
||||
// DELETE FROM releases WHERE release_group_id NOT IN (SELECT rg.id FROM release_groups rg);
|
||||
func (q *Queries) CleanOrphanedEntries(ctx context.Context) error {
|
||||
_, err := q.db.Exec(ctx, cleanOrphanedEntries)
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue