ALTER TABLE blog_posts
    ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ;

DROP INDEX IF EXISTS idx_blog_slug;
DROP INDEX IF EXISTS blog_posts_slug_key;

CREATE UNIQUE INDEX IF NOT EXISTS ux_blog_posts_slug_active
    ON blog_posts (slug)
    WHERE deleted_at IS NULL;

CREATE INDEX IF NOT EXISTS idx_blog_slug_active
    ON blog_posts (slug)
    WHERE deleted_at IS NULL;

CREATE INDEX IF NOT EXISTS idx_blog_published_active
    ON blog_posts (is_published, published_at DESC)
    WHERE deleted_at IS NULL;

CREATE INDEX IF NOT EXISTS idx_blog_category_active
    ON blog_posts (category_id)
    WHERE deleted_at IS NULL;
