USE au_publishing_db;

ALTER TABLE blogs
    ADD COLUMN IF NOT EXISTS slug VARCHAR(255) NULL AFTER title;

UPDATE blogs
SET slug = CONCAT('blog-', id)
WHERE slug IS NULL OR slug = '';

ALTER TABLE blogs
    MODIFY COLUMN slug VARCHAR(255) NOT NULL;

CREATE UNIQUE INDEX uniq_blogs_slug ON blogs (slug);
