-- Portfolio authors (same pattern as blogs.author_id)
ALTER TABLE portfolios
  ADD COLUMN IF NOT EXISTS author_id BIGINT;

DO $$
BEGIN
  IF NOT EXISTS (
    SELECT 1
    FROM pg_constraint
    WHERE conname = 'portfolios_author_id_fkey'
  ) THEN
    ALTER TABLE portfolios
      ADD CONSTRAINT portfolios_author_id_fkey
      FOREIGN KEY (author_id) REFERENCES users (id)
      ON UPDATE NO ACTION
      ON DELETE SET NULL;
  END IF;
END $$;

CREATE INDEX IF NOT EXISTS idx_portfolios_author_id ON portfolios (author_id);
