deckhearth/scripts/add-user-profile-columns.js
Randall Stillwell b3240dbb3c 🎨 Enhanced Signup with Username & Profile Images
 New Signup Features:
- Added username field with validation (3+ chars, alphanumeric + underscore)
- Profile image upload with file validation (5MB max)
- DiceBear Adventurer Neutral API integration for random avatars
- Generate new random avatar button with dice emoji
- Initial random avatar generation on page load

🔧 Backend Updates:
- Updated registration API to handle all new fields
- Username uniqueness validation with specific error messages
- Profile image URL storage in database
- Enhanced user response with all profile data

🗄️ Database Migration:
- Added first_name, last_name, username, profile_image_url columns
- Unique constraint on username field
- Migration script with existing user updates
- Default values for existing accounts

🎯 User Experience:
- Real-time form validation with error states
- Loading states for image upload/generation
- File type and size validation
- Clean profile image preview with rounded borders
- Consistent styling with existing theme

Ready for enhanced user profiles! 🚀
2025-07-28 11:18:58 -05:00

61 lines
No EOL
1.7 KiB
JavaScript

import { sql } from '@vercel/postgres';
import dotenv from 'dotenv';
// Load environment variables
dotenv.config({ path: '.env.local' });
async function addUserProfileColumns() {
console.log('🔄 Adding user profile columns to users table...');
try {
// Add new columns to users table
await sql`
ALTER TABLE users
ADD COLUMN IF NOT EXISTS first_name VARCHAR(255),
ADD COLUMN IF NOT EXISTS last_name VARCHAR(255),
ADD COLUMN IF NOT EXISTS username VARCHAR(255) UNIQUE,
ADD COLUMN IF NOT EXISTS profile_image_url TEXT
`;
console.log('✅ Successfully added user profile columns');
// Update existing users with default values
console.log('🔄 Updating existing users with default values...');
const existingUsers = await sql`SELECT id, email FROM users WHERE first_name IS NULL`;
for (const user of existingUsers.rows) {
// Generate default values from email
const emailPrefix = user.email.split('@')[0];
const defaultUsername = `${emailPrefix}_${user.id}`;
await sql`
UPDATE users
SET
first_name = 'User',
last_name = ${user.id.toString()},
username = ${defaultUsername}
WHERE id = ${user.id}
`;
console.log(`✅ Updated user ${user.email} with default values`);
}
console.log('✅ Migration completed successfully!');
} catch (error) {
console.error('❌ Error during migration:', error);
throw error;
}
}
// Run the migration
addUserProfileColumns()
.then(() => {
console.log('🎉 User profile columns migration completed!');
process.exit(0);
})
.catch((error) => {
console.error('💥 Migration failed:', error);
process.exit(1);
});