In a new release of a module, a developer decides to rename a table that was defined in the earlier versions.
Which action, if any, allows the developer to prevent data loss?
- Define onCreate="migrateDataFromAnotherTable(old_table_name)" attribute in the table tag.
- Declarative schema supports RENAME TABLE', so the data will be migrated to the new table automatically.
- Define the table and columns mapping in the db.schema_whitelist.json
Answer(s): A
Explanation:
To prevent data loss when renaming a table that was defined in the earlier versions of a module, the developer should define onCreate="migrateDataFromAnotherTable(old_table_name)" attribute in the table tag of the db_schema.xml file. This attribute will instruct Adobe Commerce to copy all data from the old table to the new table during installation or upgrade.
Declarative schema does not support RENAME TABLE statement, so the data will not be migrated to the new table automatically. The db.schema_whitelist.json file is used to whitelist changes that are allowed for backward compatibility, not for data migration.
Reference:
Adobe Commerce Developer Guide - Declare schema and data patches
Reveal Solution Next Question