2012b0bab9
- Added default_language field to general settings state in SettingsPage - Replaced LanguageSelector component with simple select dropdown on settings page - Fixed public settings endpoint to read general_default_language from database - Language setting now properly saved when clicking Save Settings button - Setting is correctly used by gallery login page and legal pages 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
91 lines
2.5 KiB
JavaScript
91 lines
2.5 KiB
JavaScript
const fs = require('fs').promises;
|
|
const path = require('path');
|
|
const { db } = require('../src/database/db');
|
|
|
|
// Create migrations table if it doesn't exist
|
|
async function createMigrationsTable() {
|
|
const tableExists = await db.schema.hasTable('migrations');
|
|
if (!tableExists) {
|
|
await db.schema.createTable('migrations', (table) => {
|
|
table.increments('id').primary();
|
|
table.string('filename').unique().notNullable();
|
|
table.timestamp('applied_at').defaultTo(db.fn.now());
|
|
});
|
|
console.log('Created migrations table');
|
|
}
|
|
}
|
|
|
|
// Get list of applied migrations
|
|
async function getAppliedMigrations() {
|
|
const migrations = await db('migrations').select('filename');
|
|
return migrations.map(m => m.filename);
|
|
}
|
|
|
|
// Run a single migration
|
|
async function runMigration(filename) {
|
|
const migrationPath = path.join(__dirname, filename);
|
|
const migration = require(migrationPath);
|
|
|
|
if (migration.up) {
|
|
console.log(`Running migration: ${filename}`);
|
|
await migration.up();
|
|
await db('migrations').insert({ filename });
|
|
console.log(`Migration ${filename} completed`);
|
|
}
|
|
}
|
|
|
|
// Main migration runner
|
|
async function runMigrations() {
|
|
try {
|
|
console.log('Starting database migrations...');
|
|
|
|
// First run the init.js if it exists
|
|
const initPath = path.join(__dirname, 'init.js');
|
|
if (require.resolve(initPath)) {
|
|
console.log('Running initial setup...');
|
|
require(initPath);
|
|
// Wait a bit for init to complete
|
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
}
|
|
|
|
// Create migrations table
|
|
await createMigrationsTable();
|
|
|
|
// Get all migration files
|
|
const files = await fs.readdir(__dirname);
|
|
const migrationFiles = files
|
|
.filter(f => f.match(/^\d{3}_.*\.js$/))
|
|
.sort();
|
|
|
|
// Get applied migrations
|
|
const appliedMigrations = await getAppliedMigrations();
|
|
|
|
// Run pending migrations
|
|
let pendingCount = 0;
|
|
for (const file of migrationFiles) {
|
|
if (!appliedMigrations.includes(file)) {
|
|
await runMigration(file);
|
|
pendingCount++;
|
|
}
|
|
}
|
|
|
|
if (pendingCount === 0) {
|
|
console.log('No pending migrations');
|
|
} else {
|
|
console.log(`Applied ${pendingCount} migration(s)`);
|
|
}
|
|
|
|
console.log('All migrations completed successfully');
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('Migration failed:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Only run if called directly
|
|
if (require.main === module) {
|
|
runMigrations();
|
|
}
|
|
|
|
module.exports = { runMigrations }; |