fix_slug_issue.sql 864 B

123456789101112131415161718192021222324
  1. -- Fix missing slug column issue
  2. -- Execute this SQL to add the missing 'slug' column to publications table
  3. -- Add slug column if it doesn't exist
  4. ALTER TABLE publications
  5. ADD COLUMN IF NOT EXISTS slug VARCHAR(255) AFTER title;
  6. -- Add index for slug
  7. ALTER TABLE publications
  8. ADD INDEX IF NOT EXISTS idx_publications_slug (slug);
  9. -- Add published_at column if it doesn't exist
  10. ALTER TABLE publications
  11. ADD COLUMN IF NOT EXISTS published_at TIMESTAMP NULL DEFAULT NULL AFTER created_at;
  12. -- Update existing publications to generate slugs from titles
  13. UPDATE publications
  14. SET slug = LOWER(REPLACE(REPLACE(REPLACE(title, '[^a-z0-9 ]', ''), ' ', '-'), '-', ''))
  15. WHERE slug IS NULL OR slug = '';
  16. -- Update published_at for existing published publications
  17. UPDATE publications
  18. SET published_at = created_at
  19. WHERE status = 'published' AND published_at IS NULL;