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:
- 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.
- Diff that expected column set against the live
user_extended table.
- 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
Problem or motivation
The admin Database check (db-verify) only compares the static table
definitions in
core_sql.phpagainst 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 anadmin adds a UEF, core runs an
ALTER TABLEon the fly to add auser_<name>column touser_extended, driven by whatever is inuser_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_extendedcolumns 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:
user_extended_struct, rebuild the expecteduser_<name>column definition from the struct data (name + field type/
user_extended_struct.user_extended_struct_type), the same way theruntime
ALTER TABLEbuilds it.user_extendedtable.with the same "fix"/repair action db-verify offers for other tables, so
the missing
ALTER TABLEcan be re-run.This would make the UEF struct and the physical
user_extendedcolumnsverifiable together, instead of trusting that they never drift.
Alternatives considered
Originates from discussion:
#5586
Relevant code:
core_sql.php.ALTER TABLEthat adds theUEF column.
Additional context
No response