Skip to content

Migration ID 029 reused across versions causes cascading failures on upgrade #762

@lane711

Description

@lane711

Bug Description

When upgrading SonicJS from a version where migration 029 was "Ai Search Plugin" to v2.12.x where 029 is now "Add Forms System", the forms migration is silently skipped because 029 is already marked as applied in the migrations table. This causes cascading failures for migrations 030 (Add Turnstile To Forms) and 033 (Form Content Integration), which depend on the forms and form_submissions tables.

Steps to Reproduce

  1. Run SonicJS on a version where migration 029 = "Ai Search Plugin" (applied successfully)
  2. Upgrade to @sonicjs-cms/core@2.12.x where 029 = "Add Forms System"
  3. Go to Admin → Settings → Migrations
  4. Click "Run Migrations"

Expected Behavior

All pending migrations apply successfully, including the forms system tables.

Actual Behavior

  • Migration 029 is skipped (already marked as applied in migrations table)
  • forms, form_submissions, and form_files tables are never created
  • Migration 030 fails: D1_ERROR: no such table: forms: SQLITE_ERROR
  • Migration 033 fails: D1_ERROR: no such table: form_submissions: SQLITE_ERROR
  • Admin UI shows generic "Failed to run migrations" with no actionable detail

Root Cause

Migration ID 029 was reassigned to a completely different migration between SonicJS releases:

Version Migration 029 Creates Tables
Older Ai Search Plugin ai_search related
2.12.x Add Forms System forms, form_submissions, form_files

The autoDetectAppliedMigrations() method doesn't have a detection case for 029, so it relies solely on the migrations table record — which says 029 is applied.

Workaround

Manually create the forms, form_submissions, and form_files tables via D1 SQL, then re-run migrations.

Suggestions

  1. Never reuse migration IDs — once a migration ID is published in a release, it should be immutable
  2. Add table-existence checks for migrations with dependencies — if 030 needs the forms table, verify it exists before running
  3. Improve error messaging in the admin UI — show which specific migrations failed and why, rather than a generic "Failed to run migrations"
  4. Add auto-detection for forms tables in autoDetectAppliedMigrations() similar to how it checks for user_profiles, settings, etc.

Environment

  • @sonicjs-cms/core: upgraded from 2.10.0 to 2.12.1
  • Runtime: Cloudflare Workers
  • Database: Cloudflare D1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions