我扩展了Symfony AbstractMigration
类,因此在函数preUp()
中,它收集了所有在迁移过程中会受到影响的postgreSQL模式,在postUp()
中,它为每个运行up()
模式(公共,app32423,app34534,app ...)
扩展类与此类似:
class OurAbstractMigration extends AbstractMigration
{
protected $arrayOfDbSchemas;
public function preUp(Schema $schema): void
{
// huge logic that gets all schemas on what migration should be applied
// these schemas are not always the same
$arrayOfDbSchemas = ...
$this->dbSchemas = $arrayOfDbSchemas;
}
public function postUp(Schema $schema) : void
{
foreach($this->dbSchemas as $dbSchema) {
up($schema, $dbSchema);
}
}
}
迁移类与此类似:
final class Version20190719123142 extends OurAbstractMigration
{
public function up(Schema $schema, $dbSchema = 'public') : void
{
$this->addSql('INSERT INTO' . $dbSchema . '.someTable ...rest of query');
}
}
现在,我知道不好的做法是调用postUp()
来改变数据库,尤其是再次调用up()
函数。我什至读到,这并不总是可行。
是否可以在多个架构上进行一次迁移,因此迁移不需要在up()
函数中进行任何更改。我们有数千个迁移文件,每个迁移都可以从1(公共)模式应用到10000个模式。
(我从问题down()
中排除,希望它是类似的解决方法:D)
我们正在使用: