Migrations
Database migrations can be brought by plugins and AdditionalBundles.
If you want to know more about migrations you can follow the steps from the Shopware documentation:
All migrations are located in the Migration/-directory of your plugin or AdditionalBundle per default.
Adding a migration to an AdditionalBundle
Shopware provides the database:create-migration console command to easily create a new migration.
To create a new migration in an AdditionalBundle you must call the command with some options:
The following example command adds a migration MyMigration to the Migration/-directory of the FooBundle:
Delete data on plugin uninstallation
If you have some migrations which add new database tables you also want to delete these tables on plugin uninstallation. dustin/shopware-utils automatically takes care about that! The only thing you need to do is to tell which tables need to be deleted on plugin uninstallation.
Overwrite the getTablesToRemove -method of your plugin or AdditionalBundle.
dustin/shopware-utils will execute the following steps to remove your tables from database:
Execute a DELETE-statement for each table in the given order. All statements will be executed in a single transaction. If there is an error and the transaction fails a rollback will be executed and the exception will be thrown. If the transaction is successful all tables should be present but with no data.
Execute a DROP TABLE-statement for each table in the given order.
DELETE-statements will be executed in the given order. If you want two tables to be deleted which have foreign key constraints you have to list the associated entity first.
Example:
You have two entities:
my_entity
my_entity_association (with a foreign key and ON DELETE RESTRICT constraint )
You must provide the entities in the following order to prevent an exception:
my_entity_association
my_entity
Last updated