Generating a Schema Whitelist File

I hope you’ve gotten used to Magento’s declarative schema for managing your database tables and fields! But if you’re only writing db_schema.xml and stopping there, you’re missing a key piece: the generation of a schema “whitelist” file. This is easy to do with setup:db-declaration:generate-whitelist, and you should do it any time schema changes.

The whitelist lets Magento know what schema the module is “in charge” of, and this is important if a destructive operation (i.e., removing a table/field) is ever needed. Magento won’t remove a structure that has disappeared from db_schema.xml unless it finds it in the whitelist. Here’s a peek at how the schema “diff” that’s ultimately executed during setup:upgrade is generated.

Chris Nanninga

Director of Training and Development at SwiftOtter -@ChrisNanninga