1

I'm working with a legacy module where they used the old InstallData.php script to build their tables, and now I need to make some changes to them.

If I wrote those changes in a db_schema.xml, it gets executed before the original install data even with my module declared to load after theirs on the module.xml, causing a mess in the final result.

Am I missing something?

2 Answers 2

2

You are right. You cannot update DB schema with db_schema.xml when the table is not defined in 3rd party module db_schema.xml and creates with InstallData. As you correct said this is related to priority of run upgrade logic.

Single way in your case is add sequence from 3rd party module in your etc/module.xml and make changes with Setup/InstallData in your module.

3
  • Sorry answered in the same time but in a different way. Is it a good practice to use db_schema to run modification rather than patch ?
    – Claims
    Commented Aug 17, 2022 at 15:16
  • Unfortunately, but technically it doesn't. Schema upgrades run earlier than InstallData and you cannot change this. This is make impossible to properly work for fresh installation. Commented Aug 17, 2022 at 15:23
  • 1
    About best practice, preferable way to manage DB after 2.4 is db_schema.xml Configure declarative schema. Commented Aug 17, 2022 at 15:34
0

My suggestion would be that; running the two way in the same time is tricky.

Why not doing your modification to a custom UpgradeData ? Or even using a patch data interface.

To me db_schema is supposed to be the original content which is why it's normal he is executed first, not the final content. Patch and update will modify that content, not the opposite.

To resume :

InstallData (or more likely InstallSchema) or db_schema to create a database structure (but not both)

Then

UpdateData or PatchInterface to update these data.

1
  • Why not doing your modification to a custom UpgradeData? - I prefer to avoid legacy way of doing things as much as possible Commented Aug 17, 2022 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.