-- Run once on an existing database (before this change posts had no portal).
ALTER TABLE posts ADD COLUMN portal_id VARCHAR(64) NOT NULL DEFAULT 'default' AFTER id;
ALTER TABLE posts DROP INDEX uq_slug, DROP INDEX idx_public, DROP INDEX idx_category;
ALTER TABLE posts
  ADD UNIQUE KEY uq_portal_slug (portal_id, slug),
  ADD KEY idx_public (portal_id, is_published, published_at),
  ADD KEY idx_category (portal_id, category);
ALTER TABLE posts ALTER COLUMN portal_id DROP DEFAULT;
