veza/veza-backend-api/migrations/022_add_profile_slug.sql

13 lines
408 B
MySQL
Raw Normal View History

2025-12-03 19:29:37 +00:00
-- T0219: Add Profile Slug Generation
-- Add slug column to users table for URL-friendly profile URLs
ALTER TABLE users ADD COLUMN IF NOT EXISTS slug VARCHAR(255);
CREATE UNIQUE INDEX IF NOT EXISTS idx_users_slug ON users(slug);
-- Populate existing users with slugs from their usernames
UPDATE users
SET slug = LOWER(REGEXP_REPLACE(username, '[^a-zA-Z0-9]', '-', 'g'))
WHERE slug IS NULL OR slug = '';