smoq / database-dump-bundle
A small Symfony bundle that allows for database dump from the client side in excel or sql format
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.1
- doctrine/dbal: ^3.6
- doctrine/doctrine-bundle: ^2.7
- doctrine/orm: ^2.15
- phpoffice/phpspreadsheet: ^1.25
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.17
- phpstan/phpstan: ^1.10
This package is auto-updated.
Last update: 2025-05-04 21:33:59 UTC
README
This bundle allows to easily dump a full database to an excel file or an SQL file.
Usage
example in a controller :
#[Route("/database/dump/excel", name: "app_dump_database_excel")] function dumpDatabase(ManagerRegistry $doctrine, ExcelDumper $dumper): BinaryFileResponse { $filepath = getcwd() . "/exports/dump.xlsx"; // dump the db to a .xlsx file $dumper->dumpToFile($filepath, ["doctrine_migration_versions"], true); $response = new BinaryFileResponse($filepath); $response->setContentDisposition( ResponseHeaderBag::DISPOSITION_ATTACHMENT, "dump.sql" ); // return it as an attachment (download it to the user's computer) return $response; }
Simply replace ExcelDumper by SqlDumper to create a .sql file instead (don't forget to replace the extension in the filepath !).
If you only want to dump the schema of the database, without its data, you can use the DumperInterface::dumpSchema
method.
Excel dumper
Please note that when using the excel dumper, the file format is specified by the file extension (string after the last dot). If the file format isn't supported, it will default throw an error
Sql dumper
If you try to exclude an entity which another depends upon, without excluding the other one, an error will be thrown, as the generated sql file would be broken otherwise.