fix(migration): resolve v1.0.0 password column migration causing login failures (#1059)

Fixes users unable to login after upgrading from v1.0.0 to v1.1.0-dev.16.

The migration was using COALESCE(password_digest, password) which fails in
SQLite when password_digest column doesn't exist in v1.0.0 databases. The
v1.0.0 schema had a 'password' column, not 'password_digest'.

Changes:
- Dynamically detect which password column exists (password vs password_digest)
- Use the correct column in the migration SELECT statement
- Add enhanced trust proxy diagnostics to help debug configuration issues

Tested:
- Created v1.0.0 database with 'password' column
- Verified user login works pre-migration
- Ran migration with fix
- Confirmed password hash preserved and login still works post-migration
This commit is contained in:
Chris 2026-04-23 17:53:55 +03:00 committed by GitHub
parent 56af7b9985
commit 0499fa127c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -26,6 +26,8 @@ if (config.trustProxy !== false) {
console.log(`[Trust Proxy] Disabled (value: false)`);
}
console.log(`[Trust Proxy] Express setting confirmed:`, app.get('trust proxy'));
// Session store
const sessionStore = new SequelizeStore({
db: sequelize,

View file

@ -48,6 +48,26 @@ module.exports = {
);
`);
const [columns] = await queryInterface.sequelize.query(
'PRAGMA table_info(users);'
);
const hasPasswordDigest = columns.some(
(col) => col.name === 'password_digest'
);
const hasPassword = columns.some((col) => col.name === 'password');
const passwordColumn = hasPasswordDigest
? 'password_digest'
: hasPassword
? 'password'
: null;
if (!passwordColumn) {
throw new Error(
'Neither password nor password_digest column found in users table'
);
}
await queryInterface.sequelize.query(`
INSERT INTO users_new (
id, uid, name, surname, email, password_digest, appearance, language,
@ -64,7 +84,7 @@ module.exports = {
)
SELECT
id, uid, name, surname, email,
COALESCE(password_digest, password) as password_digest,
${passwordColumn} as password_digest,
appearance, language,
timezone, first_day_of_week, avatar_image, telegram_bot_token,
telegram_chat_id, task_summary_enabled, task_summary_frequency,