-- Migration 012: Add user_id to shortlinks table
-- This allows tracking which user created each shortlink

-- Add user_id column to shortlinks
ALTER TABLE shortlinks
ADD COLUMN user_id INT UNSIGNED NULL AFTER id,
ADD INDEX idx_user_id (user_id);

-- Add foreign key constraint
ALTER TABLE shortlinks
ADD CONSTRAINT fk_shortlink_user
    FOREIGN KEY (user_id) REFERENCES users(id)
    ON DELETE SET NULL
    ON UPDATE CASCADE;

-- Existing shortlinks will have NULL user_id (created before multi-user system)
