24 lines
910 B
SQL
24 lines
910 B
SQL
-- +goose Up
|
|
CREATE TABLE playlists (
|
|
id uuid PRIMARY KEY,
|
|
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
name text NOT NULL CHECK (char_length(name) BETWEEN 1 AND 120),
|
|
description text NOT NULL DEFAULT '' CHECK (char_length(description) <= 2000),
|
|
revision integer NOT NULL DEFAULT 1,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX playlists_owner ON playlists(user_id, updated_at DESC, id);
|
|
CREATE TABLE playlist_tracks (
|
|
playlist_id uuid NOT NULL REFERENCES playlists(id) ON DELETE CASCADE,
|
|
track_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
|
|
position integer NOT NULL CHECK (position >= 0),
|
|
PRIMARY KEY (playlist_id, track_id),
|
|
UNIQUE (playlist_id, position)
|
|
);
|
|
CREATE INDEX playlist_tracks_track ON playlist_tracks(track_id);
|
|
|
|
-- +goose Down
|
|
DROP TABLE playlist_tracks;
|
|
DROP TABLE playlists;
|