Know when to save or remove data

Adobe recommends that you first determine whether you need to save this data. If you are moving data from a legacy system, any data that you can remove saves you time and effort during the migration. (There are ways to archive data if it needs to be accessed later.) To be a good steward of the application and performance, it’s okay to challenge a request to save extra data. Your goal is to ensure that saving the data is a requirement to fulfill a business need that cannot be filled another way.

Legacy data

If your project contains legacy data, such as old orders or customer records, consider an alternative lookup method. For example, if the business requires access to the data only for occasional reference, consider implementing an external search of the old database hosted outside the commerce platform instead of migrating old data to Adobe Commerce.

This situation would require the database to be migrated to a server, offering either a web interface to read the data, or perhaps training in the use of MySQL Workbench or similar tools. Excluding this data from the new database expedites the migration by allowing the development team to focus on the new site rather than troubleshooting data migration issues.

Another related option for keeping the data external to commerce but allowing you to use it in real time would be leveraging other tools, such as GraphQL mesh. This option combines different data sources and returns them as a single response.

For example, you can stitch together old orders from an external database, perhaps the old Magento 1 site that is decommissioned. Then using GraphQL mesh, show them as part of the customers order history. These old orders can be combined with the orders from your current Adobe Commerce environment.

For more information about using API mesh with GraphQL, see What is API Mesh) and GraphQL Mesh Gateway.

Migrate legacy data with extension attributes

If you determine that legacy data requires migration, or that new data needs to be saved in Adobe Commerce, Adobe recommends using extension attributes. Using extension attributes to save additional data offers the following advantages:

  • You can control the data being persisted and the database structure, which ensures that the data is saved with the correct column type and proper indexes.
  • Most entities in Adobe Commerce support the use of extension attributes.
  • Extension attributes are a storage agnostic mechanism which provides the flexibility to save the data in the optimal location for your project.

Two examples of storage locations are database tables and Redis. The key things to consider when choosing a location are whether location introduces extra complexity or impacts performance.

Consider other alternatives

As a developer, it is vital to always consider using tools outside of your Adobe Commerce environment, such as GraphQL mesh and Adobe App Builder. These tools can help you retain access to the data but have no impact to the core commerce application or its underlying database tables. With this approach, you expose your data through an API. Then, you add a data source to your App Builder configuration. Using GraphQL Mesh, you can combine those data sources and produce a single response as mentioned in legacy data.

For additional details on GraphQL mesh, see GraphQL Mesh Gateway. For information about the Adobe App Builder, see Introducing App Builder.

Modifying a core table or third-party table

If you decide to store data by modifying a core Adobe Commerce or third-party module database table, use the following guidelines to minimize impact on stability and performance.

  • Add new columns only.
  • Never modify the type value of an existing column. For example, do not change an integer to a varchar in order to satisfy your unique use case.
  • Avoid adding columns to EAV attribute tables. These tables are already overloaded with logic and responsibility.
  • Before adjusting a table, determine its size. Changing large tables impacts the deployment, which can cause minutes or hours of delay when changes are applied.

Best practices for modifying an external database table

Adobe recommends following these steps when you add a column to a core database table or a third-party table:

  1. Create a module with a name in your namespace that represents what you are updating.

    For example: app/code/YourCompany/Customer

  2. Create the appropriate files to enable the module (see Create a module.

  3. Create a file called db_schema.xml in the etc folder, and make the appropriate changes.

    If applicable, generate a db_schema_whitelist.json file. See Declarative Schema for more information.

Potential impacts

Adding a column to an external database can impact your Adobe Commerce project in the following ways:

  • Upgrades could be more complicated.
  • Deployments are impacted if the table being modified is large.
  • Migrations to a new platform could be more complicated.