Skip to content

Fix database schema migration for missing columns#1

Open
railway-app[bot] wants to merge 1 commit into
mainfrom
railway/code-change-QQ3lxA
Open

Fix database schema migration for missing columns#1
railway-app[bot] wants to merge 1 commit into
mainfrom
railway/code-change-QQ3lxA

Conversation

@railway-app
Copy link
Copy Markdown

@railway-app railway-app Bot commented Apr 23, 2026

Problem

The application fails to start against older PostgreSQL databases because GORM's AutoMigrate introspects existing tables before adding new columns. When those tables are missing columns the current code expects (prefill_groups.type, tokens.type, tokens.models, channels.deleted_at), the introspection queries themselves fail with "column does not exist" errors, preventing the migration from completing and leaving the service returning 502s.

Solution

Added model/schema_repair.go with a repairSchema() function that explicitly adds each missing column via ALTER TABLE … ADD COLUMN before AutoMigrate runs. Each operation is guarded by an existence check (information_schema.columns for Postgres/MySQL, PRAGMA table_info for SQLite) so it is fully idempotent and safe on every startup. repairSchema() is called at the top of migrateDB() in model/main.go, covering all three supported database backends.

Changes

  • Created model/schema_repair.go
  • Modified model/main.go

Generated by Railway

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.

0 participants