Skip to content

Database migration fails to add new columns on Docker container upgrade #1026

@jorikfon

Description

@jorikfon

Summary

When upgrading a Docker container to a new version while reusing an existing database volume, new columns added in recent versions are missing from the database. This causes PDOException: no such column errors at runtime.

Sentry Evidence

Three related errors from the same server (mikopbx-in-a-docker, release 2026.1.223, PHP 8.4.16):

Sentry # Error Missing Column
#27959 no such column: m_LanInterfaces.ipv6_mode ipv6_mode (added for IPv6 support)
#27960 no such column: m_AsteriskManagerUsers.eventfilter eventfilter (AMI event filtering)
#27961 no such column: m_Iax.registration_type registration_type (IAX registration)

All 6 events each, 1 user, triggered via SIPConf::reload()WorkerModelsEvents.

Expected Behavior

UpdateDatabase::updateDatabaseStructure() runs during boot via SystemLoader::startSystem() and should detect missing columns from model @Column annotations, then add them via ALTER TABLE ADD COLUMN.

Potential Root Cause

In UpdateDatabase::getAddableColumns() (line ~580-621): when extra columns exist in the database that are NOT in the model (e.g., from a previous version or module), the function returns null for core models. This triggers the slow path (full table copy via temp table). During the copy, array_intersect($newColNames, $oldColNames) only transfers data for columns present in both old and new schemas — but the new table structure itself should still have the new columns.

Possible scenarios:

  1. Migration errors are silently caught and the old table structure is preserved
  2. The migration doesn't run at all in certain Docker upgrade paths
  3. A schema comparison mismatch causes the migration to skip the table entirely

Reproduction

  1. Run MikoPBX Docker with an older version (pre-IPv6, e.g., 2025.1.x)
  2. Create some data (extensions, settings)
  3. Upgrade container image to 2026.1.223 while keeping the cf volume
  4. Check database: sqlite3 /cf/conf/mikopbx.db ".schema m_LanInterfaces" | grep ipv6_mode

Files to Investigate

  • src/Core/System/Upgrade/UpdateDatabase.php — main migration logic
  • src/Core/System/Upgrade/UpdateDatabase.php:getAddableColumns() — column addition decision
  • src/Core/System/SystemLoader.php:startSystem() — boot sequence calling migration
  • src/Core/System/ContainerEntrypoint.php — Docker/LXC boot entry point

Affected Models

  • src/Common/Models/LanInterfaces.phpipv6_mode, ipv6addr, ipv6_subnet, ipv6_gateway, primarydns6, secondarydns6
  • src/Common/Models/AsteriskManagerUsers.phpeventfilter
  • src/Common/Models/Iax.phpregistration_type

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions