1

I want update my trigger from live, and I want to know if I can use migrations for that because I tried 2 alternative in my migrations:

public function up(Schema $schema)
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $stmt = $this->connection->prepare(file_get_contents(__DIR__ . '/Version20150929103205/new_trigger_procedure.sql'));
        $stmt->execute();

        $this->addSql(file_get_contents(__DIR__ . '/Version20150929103205/new_trigger_procedure.sql'));
    }

but not work. My sql file have multiple declaration. Is a possibility to run it with migrations?

Here is a model:

DROP TRIGGER IF EXISTS trigger_1; Create Trigger trigger_1 BEFORE... DROP Trigger IF EXISTS trigger_2; Create Trigger trigger_2 Before ... . . .

6
  • What's in the .sql file, can you post it? Try executing the same statement with the same user on the same server in console. Commented Sep 29, 2015 at 8:51
  • I update my question ... model is my query's in my sql file. Commented Sep 29, 2015 at 8:57
  • OK, now execute the contents of this file on the server in a MySQL console logged in as the user that executes SQL from within your application and see if it's successfully executed. In theory it should be possible from Symfony migrations file but you likely have a permission issue. Commented Sep 29, 2015 at 9:08
  • I run it ... but the problem is if you have more then 1 sintax with semicolons migration say run it, but he don't execute in db (no error, it look like every thing is ok but isn't). I see only solution to make n sql file for every query. If you know a better solution to put all query in 1 sql and my migration to run it. Commented Sep 29, 2015 at 11:01
  • @Laurentiu, have you tried running $this->connection->executeQuery($fileContents);? Commented Sep 29, 2015 at 14:43

1 Answer 1

1

the only solution was to split everything someting like that:

$this->addSql('DROP TRIGGER IF EXISTS trigger_1');
$this->addSql('...');
... 

or to do someting like that:

$querys = explode(file_get_contents($file));
foreach($querys as $query){
   $this->addSql($query);
}

but in this case you should be sure you have instruction what end with ; and not have ; in values at inserted query or everything else situations.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.