Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to call a .sql file in a doctrine migration?

Is it possible to call an .sql file in a migration class?

I could not find anything on that topic.

like image 797
Hyperkubus Avatar asked Nov 23 '12 09:11

Hyperkubus


People also ask

What is a doctrine migration?

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.

What is migration in Symfony?

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.


2 Answers

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);
}
like image 75
winkbrace Avatar answered Sep 27 '22 21:09

winkbrace


Yes, just put that .sql file and refer it from you migration class.

$this->addSql(file_get_contents(__DIR__ . '/sql-dump.sql'));
like image 43
Sreejith Chozhiyath Avatar answered Sep 27 '22 20:09

Sreejith Chozhiyath