-- T0326: Create Track History Database Model -- Create table track_history for tracking track modifications -- Table track_history CREATE TABLE IF NOT EXISTS track_history ( id BIGSERIAL PRIMARY KEY, track_id BIGINT NOT NULL REFERENCES tracks(id) ON DELETE CASCADE, user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE SET NULL, action VARCHAR(50) NOT NULL, old_value TEXT, new_value TEXT, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- Indexes for performance CREATE INDEX IF NOT EXISTS idx_track_history_track_id ON track_history(track_id); CREATE INDEX IF NOT EXISTS idx_track_history_user_id ON track_history(user_id); CREATE INDEX IF NOT EXISTS idx_track_history_action ON track_history(action); CREATE INDEX IF NOT EXISTS idx_track_history_created_at ON track_history(created_at DESC); CREATE INDEX IF NOT EXISTS idx_track_history_track_created ON track_history(track_id, created_at DESC);