Skip to content

[Feature]: db-verify — validate Extended-User-Field columns against user_extended_struct #5728

Description

@Jimmi08

Problem or motivation

The admin Database check (db-verify) only compares the static table
definitions in core_sql.php against the live schema
(db_verify_class.php line 166: $core_data = file_get_contents(e_CORE . 'sql/core_sql.php');).

Extended-User-Field (UEF) columns never appear in core_sql.php. When an
admin adds a UEF, core runs an ALTER TABLE on the fly to add a
user_<name> column to user_extended, driven by whatever is in
user_extended_struct (user_extended_class.php line 1028:
$sql->gen('ALTER TABLE #user_extended ADD user_'.$tp->toDB($name, true).' '.$field_info);).

Because those columns are defined at runtime by the admin, not at build
time in an SQL file, db-verify sails past them and reports everything as
fine — even when the column is actually missing.

Concrete case: I exported the UEF struct from one site to another, but the
matching user_extended columns were not created on the target table.
Database check reported all tables OK, so the problem stayed invisible
until things broke at runtime.

Proposed solution

Since core is what creates these columns, core is the natural place to
confirm they exist. db-verify already diffs every other table against an
expected definition — the same approach can be applied here:

  1. For each row in user_extended_struct, rebuild the expected
    user_<name> column definition from the struct data (name + field type
    / user_extended_struct.user_extended_struct_type), the same way the
    runtime ALTER TABLE builds it.
  2. Diff that expected column set against the live user_extended table.
  3. Report missing or mismatched columns in the db-verify results, ideally
    with the same "fix"/repair action db-verify offers for other tables, so
    the missing ALTER TABLE can be re-run.

This would make the UEF struct and the physical user_extended columns
verifiable together, instead of trusting that they never drift.

Alternatives considered

Originates from discussion:
#5586

Relevant code:

  • db_verify_class.php line 166 — db-verify reads only core_sql.php.
  • user_extended_class.php line 1028 — runtime ALTER TABLE that adds the
    UEF column.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Triage Status

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions