the declarative approach to database schemas23276.pcdn.co/wp-content/uploads/2018/11/douglas... ·...
TRANSCRIPT
![Page 1: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/1.jpg)
The Declarative Approach to Database Schema Upgrades in Magento 2
My XML Schema brings all the boys to the yard…
![Page 2: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/2.jpg)
Douglas Radburn Head of Development at Pinpoint Designs
- Working with Magento for 8 years
- Previously a backend developer
- Single Father to 3 under 3.
- Love PWA
Twitter: @douglasradburn
About Me
![Page 3: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/3.jpg)
Some History
![Page 4: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/4.jpg)
Magento 1
![Page 5: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/5.jpg)
Don’t just cover database structure:
- Attributes being added to Products, Categories, Customers etc
- CMS Block content
- Database data
Setup Scripts
![Page 6: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/6.jpg)
People include files just because they can or they think they should.
Blank Files
![Page 7: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/7.jpg)
In an evolving site, you’re going to end up with a lot of setup scripts for some modules, and not so many for others.
Keeping track of these can be a royal pain
Lots of Files
![Page 8: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/8.jpg)
Upgrade scripts will have missing numbers.
In theory, nothing happened to structure/data in that version.
Or, the dev didn’t commit something …
Or, two devs committed the same thing
File Sequencing
![Page 9: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/9.jpg)
If you’re looking at your database and your column type is TEXT.
You open mysql-upgrade-1.0.0-1.0.1.php
It’s defined as a VARCHAR.
You’ve got 20+ files to look through and see how it made it to a TEXT type (and whether it ultimately should be)
Hard to follow
![Page 10: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/10.jpg)
Database Specifics in M1
![Page 11: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/11.jpg)
RAW SQL
Implementation
![Page 12: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/12.jpg)
RAW SQL
Implementation
![Page 13: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/13.jpg)
Since version 1.6, Magento (in theory) supports more database backends than MySQL only
DDL (Data Definition Language)
Abstraction from direct SQL
Implementation
![Page 14: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/14.jpg)
Magento keeps track of the “current” version loaded in the core_resource table.
Version number tracked against the version supplied in etc/config.xml for your extension / for the core module.
Keeping Track
![Page 15: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/15.jpg)
Magento 2
![Page 16: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/16.jpg)
InstallData and InstallSchema - Scripts, that are executed on a clean (empty) database
UpgradeData and UpgradeSchema - Incremental scripts, that update an existing Magento database
Implementation Changes
![Page 17: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/17.jpg)
The logic moves from Magento reading file names to Magento utilising version lookups within code using version_compare.
DDL still exists
RAW SQL still exists
Problems still exist
Logic
![Page 18: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/18.jpg)
Magento keeps track of the “current” version loaded in the core_resource table.
Version number tracked against the setup_version supplied in etc/module.xml for your extension / for the core module (not composer version)
Keeping Track
![Page 19: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/19.jpg)
The FUTURE
![Page 20: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/20.jpg)
Structure declarations
![Page 21: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/21.jpg)
Magento has the answer
![Page 22: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/22.jpg)
Everyone knowsthat developers
Fucking Love XML
![Page 23: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/23.jpg)
But seriously,how can structure declarations help?
![Page 24: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/24.jpg)
Avoids missed or repeated SQL operations
![Page 25: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/25.jpg)
Dry-run mode for SQLstructure and data
![Page 26: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/26.jpg)
Performance improvements
![Page 27: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/27.jpg)
Database data rollback
![Page 28: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/28.jpg)
Ability to revert to a previous version
![Page 29: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/29.jpg)
Database structure validationbefore installation
![Page 30: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/30.jpg)
Ability to modify core database structure
![Page 31: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/31.jpg)
Developers can modifyexisting columns
![Page 32: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/32.jpg)
Show Me
![Page 33: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/33.jpg)
<Module_Vendor>/<Module_Name>/etc/db_schema.xml
Declares a module’s database structure
![Page 34: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/34.jpg)
lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/schema.xsd
Reference for what a module’s database structure can be
![Page 35: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/35.jpg)
Some Examples
![Page 36: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/36.jpg)
![Page 37: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/37.jpg)
<table name="directory_country_region_name" resource="default" engine=“innodb” comment="Directory Country Region Name">
</table>
![Page 38: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/38.jpg)
<table name="directory_country_region_name" resource="default" engine=“innodb” comment="Directory Country Region Name"> <column xsi:type="varchar" name="locale" nullable="false" length="8" comment="Locale"/> <column xsi:type="int" name="region_id" padding="10" unsigned=“true" nullable="false" identity="false" default="0" comment="Region Id"/> <column xsi:type="varchar" name="name" nullable="true" length="255" comment="Region Name"/>
</table>
![Page 39: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/39.jpg)
<table name="directory_country_region_name" resource="default" engine=“innodb” comment="Directory Country Region Name"> <column xsi:type="varchar" name="locale" nullable="false" length="8" comment="Locale"/> <column xsi:type="int" name="region_id" padding="10" unsigned=“true" nullable="false" identity="false" default="0" comment="Region Id"/> <column xsi:type="varchar" name="name" nullable="true" length="255" comment="Region Name"/> <constraint xsi:type="primary" name="PRIMARY"> <column name="locale"/> <column name="region_id"/> </constraint>
</table>
![Page 40: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/40.jpg)
<table name="directory_country_region_name" resource="default" engine=“innodb” comment="Directory Country Region Name"> <column xsi:type="varchar" name="locale" nullable="false" length="8" comment="Locale"/> <column xsi:type="int" name="region_id" padding="10" unsigned=“true" nullable="false" identity="false" default="0" comment="Region Id"/> <column xsi:type="varchar" name="name" nullable="true" length="255" comment="Region Name"/> <constraint xsi:type="primary" name="PRIMARY"> <column name="locale"/> <column name="region_id"/> </constraint> <constraint xsi:type="foreign" name=“DIR_COUNTRY_REGION_NAME_REGION_ID_DIR_COUNTRY_REGION_REGION_ID" table="directory_country_region_name" column="region_id" referenceTable=“directory_country_region" referenceColumn="region_id" onDelete=“CASCADE" />
</table>
![Page 41: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/41.jpg)
<table name="directory_country_region_name" resource="default" engine=“innodb” comment="Directory Country Region Name"> <column xsi:type="varchar" name="locale" nullable="false" length="8" comment="Locale"/> <column xsi:type="int" name="region_id" padding="10" unsigned=“true" nullable="false" identity="false" default="0" comment="Region Id"/> <column xsi:type="varchar" name="name" nullable="true" length="255" comment="Region Name"/> <constraint xsi:type="primary" name="PRIMARY"> <column name="locale"/> <column name="region_id"/> </constraint> <constraint xsi:type="foreign" name=“DIR_COUNTRY_REGION_NAME_REGION_ID_DIR_COUNTRY_REGION_REGION_ID" table="directory_country_region_name" column="region_id" referenceTable=“directory_country_region" referenceColumn="region_id" onDelete=“CASCADE" /> <index name="DIRECTORY_COUNTRY_REGION_NAME_REGION_ID" indexType="btree"> <column name=“region_id"/> </index></table>
![Page 42: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/42.jpg)
Perform common database operations
![Page 43: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/43.jpg)
Create a table
![Page 44: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/44.jpg)
Drop a table
![Page 45: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/45.jpg)
Create a foreign key
![Page 46: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/46.jpg)
Add a column to table
![Page 47: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/47.jpg)
Drop a column from a table
![Page 48: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/48.jpg)
Change the column type
![Page 49: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/49.jpg)
To rename a column, delete the original columnand create a new one.
UseonCreate=“migrateDataFrom(entity_id)"
onCreate="migrateDataFromAnotherTable(catalog_category_entity,entity_id)"
Rename a column
![Page 50: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/50.jpg)
Add an index
![Page 51: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/51.jpg)
Things you can’t do
![Page 52: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/52.jpg)
Converting to DB Schema
![Page 53: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/53.jpg)
To prepare a module for declarative schema, you must:
Develop a data patch and/or a schema patch
Configure the declarative schema for your module
Convert upgrade scripts to declarative schema- if your module already has upgrade scripts.
Once a module is converted to the declarative schema approach, it cannot be reverted to upgrade scripts.
![Page 54: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/54.jpg)
Magento provides a Schema Listener Tool to convert pre-Magento 2.3 migration scripts into declarative schema
magento setup:install --convert-old-scripts=1
magento setup:upgrade --convert-old-scripts=1
![Page 55: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/55.jpg)
The tool supports only DDL operations from \Magento\Framework\DB\Adapter\Pdo\Mysql.
The tool ignores all raw SQL in your InstallSchema or UpgradeSchema scripts.
Any DDL statements in a Recurring file will not be transferred to the new schema, because this file should be designed to run during
each installation or upgrade.
![Page 56: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/56.jpg)
Safe Installations
magento setup:upgrade --safe-modemagento setup:install --safe-mode
Rollback
setup:upgrade --data-restore
![Page 57: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/57.jpg)
Backward Compatibility
Declarative schema does not automatically delete database tables, columns or keys that are not defined in a db_schema.xml
<module_vendor>/<module_name>/etc/db_schema_whitelist.json
Can be generated withmagento setup:db-declaration:generate-whitelist --module-name=MODULENAME
![Page 58: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/58.jpg)
We essentially list out all of the elements we’ve created via XML schema declarations.
JSON Format
![Page 59: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/59.jpg)
This is now a lot harder…
Nothing is stored in setup_module anymore as it is state dependant on the db_schema.xml during setup:upgrade.
Keeping Track
![Page 60: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/60.jpg)
Summary
![Page 61: The Declarative Approach to Database Schemas23276.pcdn.co/wp-content/uploads/2018/11/Douglas... · Magento keeps track of the “current” version loaded in the core_resource table](https://reader033.vdocument.in/reader033/viewer/2022042310/5ed7a85048b98015c2021429/html5/thumbnails/61.jpg)
Twitter: @douglasradburn
That’s all folks
🌈⭐