veza/veza-backend-api/migrations/022_add_profile_slug.sql
2025-12-03 20:29:37 +01:00

12 lines
408 B
SQL

-- 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 = '';