fix(2meet-data-optimizer): do not invent default rows when migrating an entity group

- migrate_group() REPLACEs the whole flat row; columns without a native row fell back to their DDL default (session_count / account_flags DEFAULT 0), so every backfilled user got invented zeros. Keys with no native row are now written as NULL; required NOT NULL columns keep their default.
- Covers the cron batch path (migrate_group_batch) and clears stale flat values on re-run.
- Verify: EntityMigrationEngineDefaultsTest (3 RED on main); dev36 user/activity backfill: checker extra 123 → 0 for session_count and account_flags, miss/diff unchanged.
- PR: PR-066
This commit is contained in:
2026-09-26 22:46:01 +08:00
parent 957f5c4ab0
commit 13ea341ef8
2 changed files with 151 additions and 0 deletions
@@ -243,6 +243,18 @@ final class TMDO_Entity_Migration_Engine {
return false;
}
// REPLACE rewrites the whole row: a column left out falls back to its DDL
// default (e.g. session_count DEFAULT 0), inventing a value the object never
// had. Keys without a native row are written as NULL; required columns are
// NOT NULL, so they keep their default (treated as "absent" by the diff logger).
foreach ( $field_map as $key => $field_def ) {
$col = TMDO_Schema_Manager::sanitize_column_name( $key );
if ( ! array_key_exists( $col, $data ) && empty( $field_def['required'] ) ) {
$data[ $col ] = null;
$formats[] = '%s';
}
}
if ( $dry_run ) {
return true;
}