Skip to content

Fix deployment/crash by improving schema migration logic - #9

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

Fix deployment/crash by improving schema migration logic#9
RyanS4 merged 1 commit into
mainfrom
fix-deployment-schema-migration-12920079633459169510

Conversation

@RyanS4

@RyanS4 RyanS4 commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

This PR addresses a deployment failure where the server would crash on startup with a SqliteError: no such column: class when preparing statements.

The root cause was that the automated schema migration logic in server/index.js was not tracking several tables (characters, guild_ranks, audit_logs, applications, email_verification_tokens, password_reset_tokens) and was not ensuring that their newer columns were present in existing SQLite databases.

Changes:

  1. Updated tableInfos: Added all missing tables to the migration tracking object.
  2. Robust Migration: Added ensureColumn calls for all essential columns in the affected tables, matching their CREATE TABLE definitions. This ensures that the schema is always in sync with the code's expectations, even when deploying over an older database version.
  3. Fixed Guild Creation: Resolved a separate bug in the /api/guilds POST handler where the activityTimes parameter was missing from the recruitment settings initialization call, which would have caused a runtime error with better-sqlite3.

Verification:

  • Ran npm test (all tests passed).
  • Ran npm run build (production build succeeded).
  • Verified production server startup and /healthz endpoint response.
  • Obtained a positive code review confirming the fix.

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

- Update tableInfos in server/index.js to include all relevant tables.
- Add ensureColumn calls for characters, guild_ranks, audit_logs, and applications to handle missing columns in existing databases.
- Specifically fix the "no such column: class" error reported in logs.
- Fix a bug in POST /api/guilds where activityTimes was missing from the recruitment settings initialization.

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 16:04
@RyanS4
RyanS4 merged commit d7ac5bf into main Jul 5, 2026

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 hardens the server’s SQLite startup migration to prevent deployments from crashing on older databases (e.g., missing columns like characters.class), and fixes guild creation by aligning recruitment settings inserts with the current schema.

Changes:

  • Expanded schema introspection (tableInfos) to include additional tables involved in migrations.
  • Added ensureColumn migrations for several newer columns in characters, guild_ranks, audit_logs, and applications.
  • Fixed /api/guilds creation flow to include activityTimes when inserting default recruitment settings.

Comment thread server/index.js
Comment on lines +239 to +240
ensureColumn('characters', 'class', 'TEXT NOT NULL')
ensureColumn('characters', 'role', 'TEXT NOT NULL')
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