Is it possible to call an .sql file in a migration class?
I could not find anything on that topic.
The Doctrine Migrations offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and powerful tool. In order to use migrations you need to do some setup first.
Database migrations are a way to safely update your database schema both locally and on production. Instead of running the doctrine:schema:update command or applying the database changes manually with SQL statements, migrations allow to replicate the changes in your database schema in a safe manner.
I know it's an old question, but it is still the only real hit when I googled for it. The above answer can be slightly improved. It's a simple thing, but you might not think of it. If you have a sql file that contains multiple queries divided by semicolon, you can explode the contents on semicolon.
<?php
foreach (explode(';', file_get_contents(__DIR__ . '/sql-dump.sql')) as $sql) {
$this->addSql($sql);
}
Yes, just put that .sql file and refer it from you migration class.
$this->addSql(file_get_contents(__DIR__ . '/sql-dump.sql'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With