-- Create the 'albums' table
CREATE TABLE albums (
    id UUID PRIMARY KEY,
    owner_id UUID NOT NULL REFERENCES users (id),
    name TEXT NOT NULL,
    description TEXT,
    is_public BOOLEAN NOT NULL DEFAULT FALSE,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- Create the 'album_media' join table
-- This links media items to albums
CREATE TABLE album_media (
    album_id UUID NOT NULL REFERENCES albums (id) ON DELETE CASCADE,
    media_id UUID NOT NULL REFERENCES media (id) ON DELETE CASCADE,
    PRIMARY KEY (album_id, media_id) -- Ensures no duplicates
);

-- Indexes for faster lookups
CREATE INDEX idx_albums_owner_id ON albums (owner_id);

CREATE INDEX idx_album_media_media_id ON album_media (media_id);