deckhearth/scripts/add-favorites-system.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

43 lines
No EOL
1.7 KiB
JavaScript

#!/usr/bin/env node
import { config } from 'dotenv';
import { sql } from '../lib/sql.js';
config({ path: '.env.local' });
async function addFavoritesSystem() {
try {
console.log('⭐ Adding favorites system to database...');
// Create user_favorites table for all types of favorites
await sql`
CREATE TABLE IF NOT EXISTS user_favorites (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
item_type VARCHAR(50) NOT NULL, -- 'card', 'collection', 'deck'
item_id INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(user_id, item_type, item_id)
)
`;
console.log('✅ Created user_favorites table');
// Create indexes for performance
await sql`CREATE INDEX IF NOT EXISTS idx_user_favorites_user_id ON user_favorites(user_id)`;
await sql`CREATE INDEX IF NOT EXISTS idx_user_favorites_item_type ON user_favorites(item_type)`;
await sql`CREATE INDEX IF NOT EXISTS idx_user_favorites_item_id ON user_favorites(item_id)`;
await sql`CREATE INDEX IF NOT EXISTS idx_user_favorites_user_type ON user_favorites(user_id, item_type)`;
console.log('⚡ Created indexes for user_favorites');
console.log('\n🎉 Favorites system added successfully!\n');
console.log('📋 New Features:');
console.log(' • Users can favorite cards, collections, and decks');
console.log(' • Unified favorites table with item_type and item_id');
console.log(' • Optimized with indexes for fast queries');
console.log(' • Unique constraint prevents duplicate favorites');
} catch (error) {
console.error('❌ Failed to add favorites system:', error);
process.exit(1);
}
}
addFavoritesSystem();