932e5e137c
- Add database tables for email configs, settings, and activity logs - Create backend endpoints for dashboard stats, analytics, archives, email config, and settings - Create frontend service layer (admin, archive, email, settings services) - Update AdminDashboard to use real statistics and activity data - Update AnalyticsPage to fetch real analytics from backend - Update ArchivesPage with pagination and real archive operations - Update EmailConfigPage to manage real SMTP config and templates - Remove all mock data and replace with API calls throughout admin interface 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
89 lines
3.4 KiB
JavaScript
89 lines
3.4 KiB
JavaScript
const bcrypt = require('bcrypt');
|
|
const { db, initializeDatabase } = require('../src/database/db');
|
|
|
|
async function runMigrations() {
|
|
console.log('Running database migrations...');
|
|
|
|
try {
|
|
// Initialize tables
|
|
await initializeDatabase();
|
|
|
|
// Create default admin user if none exists
|
|
const adminExists = await db('admin_users').first();
|
|
if (!adminExists) {
|
|
const defaultPassword = 'admin123'; // Change this!
|
|
const passwordHash = await bcrypt.hash(defaultPassword, 10);
|
|
|
|
await db('admin_users').insert({
|
|
username: 'admin',
|
|
email: 'admin@example.com',
|
|
password_hash: passwordHash
|
|
});
|
|
|
|
console.log('Default admin user created:');
|
|
console.log('Username: admin');
|
|
console.log('Password: admin123');
|
|
console.log('⚠️ Please change this password immediately!');
|
|
}
|
|
|
|
// Create default email templates if none exist
|
|
const templateExists = await db('email_templates').first();
|
|
if (!templateExists) {
|
|
await db('email_templates').insert([
|
|
{
|
|
template_key: 'gallery_created',
|
|
subject: 'Your Photo Gallery is Ready!',
|
|
body_html: `<h2>Gallery Created Successfully</h2>
|
|
<p>Dear {{host_name}},</p>
|
|
<p>Your photo gallery "{{event_name}}" has been created successfully!</p>
|
|
<p><strong>Gallery Details:</strong></p>
|
|
<ul>
|
|
<li>Event Date: {{event_date}}</li>
|
|
<li>Gallery Link: {{gallery_link}}</li>
|
|
<li>Password: {{gallery_password}}</li>
|
|
<li>Expires: {{expiry_date}}</li>
|
|
</ul>
|
|
<p>Share this link and password with your guests to allow them to view and download photos.</p>`,
|
|
body_text: 'Gallery Created Successfully\n\nDear {{host_name}},\n\nYour photo gallery "{{event_name}}" has been created successfully!',
|
|
variables: JSON.stringify(['host_name', 'event_name', 'event_date', 'gallery_link', 'gallery_password', 'expiry_date'])
|
|
},
|
|
{
|
|
template_key: 'expiration_warning',
|
|
subject: 'Your Photo Gallery Expires Soon',
|
|
body_html: `<h2>Gallery Expiring Soon</h2>
|
|
<p>Dear {{host_name}},</p>
|
|
<p>Your photo gallery "{{event_name}}" will expire in {{days_remaining}} days.</p>
|
|
<p>After expiration, the gallery will be archived and no longer accessible to guests.</p>
|
|
<p><a href="{{gallery_link}}">Visit Gallery</a></p>`,
|
|
body_text: 'Gallery Expiring Soon\n\nDear {{host_name}},\n\nYour photo gallery "{{event_name}}" will expire in {{days_remaining}} days.',
|
|
variables: JSON.stringify(['host_name', 'event_name', 'days_remaining', 'gallery_link'])
|
|
}
|
|
]);
|
|
console.log('Default email templates created');
|
|
}
|
|
|
|
// Create default email config if none exists
|
|
const emailConfig = await db('email_configs').first();
|
|
if (!emailConfig) {
|
|
await db('email_configs').insert({
|
|
smtp_host: process.env.SMTP_HOST || 'mailhog',
|
|
smtp_port: process.env.SMTP_PORT || 1025,
|
|
smtp_secure: process.env.SMTP_SECURE === 'true',
|
|
smtp_user: process.env.SMTP_USER || '',
|
|
smtp_pass: process.env.SMTP_PASS || '',
|
|
from_email: process.env.EMAIL_FROM || 'noreply@photo-sharing.local',
|
|
from_name: 'Photo Sharing'
|
|
});
|
|
console.log('Default email configuration created');
|
|
}
|
|
|
|
console.log('Migrations completed successfully');
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('Migration failed:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
runMigrations();
|