Fix 001_init.js database column mismatch
Mirror to GitHub / mirror (push) Successful in 26s
Test and Lint / backend-test (push) Successful in 1m13s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 1m58s
Version and Release / version-bump (push) Failing after 36s
Version and Release / trigger-drone (push) Has been skipped
Mirror to GitHub / mirror (push) Successful in 26s
Test and Lint / backend-test (push) Successful in 1m13s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 1m58s
Version and Release / version-bump (push) Failing after 36s
Version and Release / trigger-drone (push) Has been skipped
- Removed must_change_password field that doesn't exist in admin_users table - Changed from using db to knex parameter for database operations - Fixed require statement that was accidentally changed - Updated security message to reflect no forced password change - Removed debug logging after identifying the issue The error occurred because 001_init.js was trying to insert a column that doesn't exist in the admin_users table schema created by initializeDatabase().
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
const bcrypt = require('bcrypt');
|
const bcrypt = require('bcrypt');
|
||||||
const { db, initializeDatabase } = require('../../src/database/db');
|
const { initializeDatabase } = require('../../src/database/db');
|
||||||
const { generateReadablePassword } = require('../../src/utils/passwordGenerator');
|
const { generateReadablePassword } = require('../../src/utils/passwordGenerator');
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@@ -12,17 +12,16 @@ exports.up = async function(knex) {
|
|||||||
await initializeDatabase();
|
await initializeDatabase();
|
||||||
|
|
||||||
// Create default admin user if none exists
|
// Create default admin user if none exists
|
||||||
const adminExists = await db('admin_users').first();
|
const adminExists = await knex('admin_users').first();
|
||||||
if (!adminExists) {
|
if (!adminExists) {
|
||||||
// Generate a secure random password
|
// Generate a secure random password
|
||||||
const generatedPassword = generateReadablePassword();
|
const generatedPassword = generateReadablePassword();
|
||||||
const passwordHash = await bcrypt.hash(generatedPassword, 12); // Increased rounds for better security
|
const passwordHash = await bcrypt.hash(generatedPassword, 12); // Increased rounds for better security
|
||||||
|
|
||||||
await db('admin_users').insert({
|
await knex('admin_users').insert({
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
email: '[email protected]',
|
email: '[email protected]',
|
||||||
password_hash: passwordHash,
|
password_hash: passwordHash,
|
||||||
must_change_password: true, // Flag for forcing password change
|
|
||||||
created_at: new Date()
|
created_at: new Date()
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -39,7 +38,7 @@ Username: admin
|
|||||||
Password: ${generatedPassword}
|
Password: ${generatedPassword}
|
||||||
|
|
||||||
IMPORTANT SECURITY NOTES:
|
IMPORTANT SECURITY NOTES:
|
||||||
1. You MUST change this password on first login
|
1. Please change this password after first login
|
||||||
2. This file will be created only once
|
2. This file will be created only once
|
||||||
3. Store these credentials securely
|
3. Store these credentials securely
|
||||||
4. Delete this file after noting the password
|
4. Delete this file after noting the password
|
||||||
@@ -65,9 +64,9 @@ Generated on: ${new Date().toISOString()}
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create default email templates if none exist
|
// Create default email templates if none exist
|
||||||
const templateExists = await db('email_templates').first();
|
const templateExists = await knex('email_templates').first();
|
||||||
if (!templateExists) {
|
if (!templateExists) {
|
||||||
await db('email_templates').insert([
|
await knex('email_templates').insert([
|
||||||
{
|
{
|
||||||
template_key: 'gallery_created',
|
template_key: 'gallery_created',
|
||||||
subject: 'Your Photo Gallery is Ready!',
|
subject: 'Your Photo Gallery is Ready!',
|
||||||
@@ -101,9 +100,9 @@ Generated on: ${new Date().toISOString()}
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create default email config if none exists
|
// Create default email config if none exists
|
||||||
const emailConfig = await db('email_configs').first();
|
const emailConfig = await knex('email_configs').first();
|
||||||
if (!emailConfig) {
|
if (!emailConfig) {
|
||||||
await db('email_configs').insert({
|
await knex('email_configs').insert({
|
||||||
smtp_host: process.env.SMTP_HOST || 'mailhog',
|
smtp_host: process.env.SMTP_HOST || 'mailhog',
|
||||||
smtp_port: process.env.SMTP_PORT || 1025,
|
smtp_port: process.env.SMTP_PORT || 1025,
|
||||||
smtp_secure: process.env.SMTP_SECURE === 'true',
|
smtp_secure: process.env.SMTP_SECURE === 'true',
|
||||||
|
|||||||
@@ -141,7 +141,6 @@ async function runMigrations() {
|
|||||||
const numB = parseInt(baseB.split('_')[0]);
|
const numB = parseInt(baseB.split('_')[0]);
|
||||||
return numA - numB;
|
return numA - numB;
|
||||||
});
|
});
|
||||||
console.log('Migration files in order:', migrationFiles.map(f => path.basename(f)));
|
|
||||||
} else {
|
} else {
|
||||||
// For existing deployments, run all migrations (legacy + core)
|
// For existing deployments, run all migrations (legacy + core)
|
||||||
console.log('Existing deployment detected - checking all migrations');
|
console.log('Existing deployment detected - checking all migrations');
|
||||||
|
|||||||
Reference in New Issue
Block a user