Skip to content

Commit

Permalink
[PAY-2523] CollectionTrackRelations migration for sellable albums (#7677
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dharit-tan authored Feb 23, 2024
1 parent 7fcc5f9 commit ebf162f
Show file tree
Hide file tree
Showing 4 changed files with 487 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BEGIN;

CREATE TABLE IF NOT EXISTS playlist_tracks (
playlist_id INTEGER NOT NULL,
track_id INTEGER NOT NULL,
is_removed BOOLEAN NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (playlist_id, track_id)
);

CREATE INDEX IF NOT EXISTS idx_playlist_tracks_track_id ON playlist_tracks USING btree (track_id, created_at);

INSERT INTO playlist_tracks (playlist_id, track_id, is_removed)
SELECT playlist_id, track_id, FALSE
FROM (
SELECT
playlist_id,
CAST(jsonb_array_elements(playlist_contents->'track_ids')->>'track' AS INTEGER) AS track_id
FROM playlists
) AS subquery
WHERE track_id IS NOT NULL ON CONFLICT DO NOTHING;

COMMIT;
Loading

0 comments on commit ebf162f

Please sign in to comment.