What is the "official" way of inserting data into a database table now since
InstallSchema, Installdata etc. scripts are said to be "Phased out soon" in documentation.
??
Solved! Go to Solution.
Hi @roman_polevecko,
As per magento documentation you can't insert data using db_schema.xml. It is only for table schemas.
Since in the old method, we used to write scripts in Install Schema or Upgrade schema when a table was created, but now in the new version, this will be done through Patch system.
A schema patch contains custom schema modification instructions. These modifications can be complex.
It is defined in a<Vendor>/<Module_Name>/Setup/Patch/Schema/<Patch_Name>.php file and implements \Magento\Setup\Model\Patch\SchemaPatchInterface.
So to add data to the author table create AddData.php file inside folder.
You can follow the following document.
https://cedcommerce.com/blog/declarative-schema-in-magento-2-3/
I hope it will help you!
Hi @roman_polevecko,
Declarative db_schema.xml is bascially being used for do the operation with table. For example: create/update/alter table etc.
https://devdocs.magento.com/guides/v2.3/extension-dev-guide/declarative-schema/db-schema.html
You can use following url to insert data using magento 2 standard way.
declarative-schema-in-magento-2-3/
I hope it will help you!
Thank you, but I think I wasn't too clear in my question.
Is there a way to insert rows into a database using the new declarative schema?
Old way you would use InstallData.php
At the moment I'm using a combination of both db_schema.xml and InstallData.php
but since old way of using install/update scripts for database is being 'phased out' soon
I wanted to know what the alternative is
Hi @roman_polevecko,
As per magento documentation you can't insert data using db_schema.xml. It is only for table schemas.
Since in the old method, we used to write scripts in Install Schema or Upgrade schema when a table was created, but now in the new version, this will be done through Patch system.
A schema patch contains custom schema modification instructions. These modifications can be complex.
It is defined in a<Vendor>/<Module_Name>/Setup/Patch/Schema/<Patch_Name>.php file and implements \Magento\Setup\Model\Patch\SchemaPatchInterface.
So to add data to the author table create AddData.php file inside folder.
You can follow the following document.
https://cedcommerce.com/blog/declarative-schema-in-magento-2-3/
I hope it will help you!
Thank you.
It'll have a look into the patch methods. Seems like quite an involved method, but that's what I was looking for. Thank you, again!