Fix deployment failure by implementing automated schema migration - #8
Conversation
The server was failing to start with "SqliteError: no such column: user_id" because existing databases were missing columns required by the latest code. This change: 1. Implements a lightweight migration system in server/index.js. 2. Checks for missing columns in existing tables on startup. 3. Automatically adds missing columns via ALTER TABLE before creating indexes. 4. Adds server-side error logging to the Express error handler for easier debugging. This ensures existing deployments are automatically upgraded to the correct schema, restoring stability and preventing similar failures in the future. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR adds a startup-time SQLite schema “self-healing” step in the Node/Express backend so the server can boot against older database files without failing on missing columns (notably in tracked_members) before indexes are created.
Changes:
- Added a lightweight migration routine that inspects existing tables via
PRAGMA table_info(...)andALTER TABLE ... ADD COLUMNfor missing columns prior to index creation. - Added a partial unique index on
users(email)(excludingNULLemails). - Improved production troubleshooting by logging 5xx errors in the global Express error handler.
| ensureColumn('tracked_members', 'user_id', 'INTEGER') | ||
| ensureColumn('tracked_members', 'rank_id', 'TEXT') |
This PR fixes a critical deployment issue where the server would fail to start if the SQLite database was from an older version of the application. The root cause was a schema mismatch—specifically, missing columns like
user_idin thetracked_memberstable—which causedCREATE INDEXor other database operations to fail.I've implemented an automated, non-destructive migration mechanism in
server/index.jsthat:PRAGMA table_infoto inspect the current database schema at startup.user_id,rank_id,activity_times) to existing tables usingALTER TABLE.I also added console error logging to the Express global error handler to make future production troubleshooting more efficient.
The fix has been verified by:
npm test).PR created automatically by Jules for task 16742487900414631646 started by @RyanS4