-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
7fcc5f9
commit ebf162f
Showing
4 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/discovery-provider/ddl/migrations/0055_playlists_tracks.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.