Skip to content

Fix deployment failure by implementing automated schema migration - #8

Merged
RyanS4 merged 1 commit into
mainfrom
fix-deployment-schema-migration-16742487900414631646
Jul 5, 2026
Merged

Fix deployment failure by implementing automated schema migration#8
RyanS4 merged 1 commit into
mainfrom
fix-deployment-schema-migration-16742487900414631646

Conversation

@RyanS4

@RyanS4 RyanS4 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

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_id in the tracked_members table—which caused CREATE INDEX or other database operations to fail.

I've implemented an automated, non-destructive migration mechanism in server/index.js that:

  • Uses PRAGMA table_info to inspect the current database schema at startup.
  • Dynamically adds any missing columns (e.g., user_id, rank_id, activity_times) to existing tables using ALTER TABLE.
  • Ensures this migration happens before index creation to avoid SQL errors.

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:

  • Triggering the migrations on an older database instance.
  • Running the server and confirming it listens successfully.
  • Verifying the schema with a diagnostic script.
  • Running the full test suite (npm test).

PR created automatically by Jules for task 16742487900414631646 started by @RyanS4

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings July 5, 2026 15:15
@RyanS4
RyanS4 merged commit 734ed0e into main Jul 5, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...) and ALTER TABLE ... ADD COLUMN for missing columns prior to index creation.
  • Added a partial unique index on users(email) (excluding NULL emails).
  • Improved production troubleshooting by logging 5xx errors in the global Express error handler.

Comment thread server/index.js
Comment on lines +221 to +222
ensureColumn('tracked_members', 'user_id', 'INTEGER')
ensureColumn('tracked_members', 'rank_id', 'TEXT')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants