在Doctrine迁移中触发

时间:2016-02-14 09:14:14

标签: doctrine-orm doctrine doctrine-migrations

我正在尝试在学说迁移类中创建一个相当复杂的触发器:

https://github.com/2ndQuadrant/audit-trigger/blob/master/audit.sql

第一个冲动就是将整个触发器代码放在一个大blob中并添加它

使用:

public function up(Schema $schema)
{
    $this->addSql($triggerSqlInABigBlob);
}

然而迁移失败

SQLSTATE[42601]: Syntax error: 7 ERROR:  cannot insert multiple commands into a prepared statement

这甚至可以在学说迁移中进行管理吗?是否有解决方法/最佳做法?

1 个答案:

答案 0 :(得分:2)

Doctrine addSql中的

AbstractMigration需要一个SQL命令或多个SQL命令的数组。您发送的是包含多个SQL命令的字符串,这是不允许的。你可以试试这个:

public function up(Schema $schema)
{
    $this->addSql(explode(';',$triggerSqlInABigBlob));
}

应将字符串转换为数组,其中每个元素都是一个SQL命令。评论可能是一个问题。

相关问题