deckhearth/scripts/add-user-profile-columns.js
Randall Stillwell 1cc2e28423 Migrate Deck Hearth off Vercel/Neon to homelab Dokploy stack.
Replace @vercel/postgres, Blob, and Upstash with lib/sql.js, MinIO object
storage, and CT 102 Redis rate limits. Add Dockerfile for Dokploy deploy,
homelab runbooks, Neon data-copy helper, and point CI smoke/visual at the
homelab URL instead of Vercel previews.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-15 09:32:13 -05:00

61 lines
No EOL
1.7 KiB
JavaScript

import { sql } from '../lib/sql.js';
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);
});