Skip to content

Commit

Permalink
feat: allow to configure migrations configuration files (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatTheCat authored Sep 5, 2024
1 parent b0a5d3d commit 6482357
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/ORM/AbstractORMPersistenceStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,29 @@ private function dropAndResetDatabase(Application $application): void

private function createSchema(Application $application): void
{
if (self::RESET_MODE_MIGRATE === $this->config['reset']['mode']) {
if (self::RESET_MODE_SCHEMA === $this->config['reset']['mode']) {
foreach ($this->managers() as $manager) {
self::runCommand($application, 'doctrine:schema:update', [
'--em' => $manager,
'--force' => true,
]);
}

return;
}

if (!$migrationsConfigurations = $this->config['reset']['migrations']['configurations']) {
self::runCommand($application, 'doctrine:migrations:migrate', [
'--no-interaction' => true,
]);

return;
}

foreach ($this->managers() as $manager) {
self::runCommand($application, 'doctrine:schema:update', [
'--em' => $manager,
'--force' => true,
foreach ($migrationsConfigurations as $migrationsConfiguration) {
self::runCommand($application, 'doctrine:migrations:migrate', [
'--configuration' => $migrationsConfiguration,
'--no-interaction' => true,
]);
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/ZenstruckFoundryBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,28 @@ public function configure(DefinitionConfigurator $definition): void
->defaultValue(AbstractORMPersistenceStrategy::RESET_MODE_SCHEMA)
->values([AbstractORMPersistenceStrategy::RESET_MODE_SCHEMA, AbstractORMPersistenceStrategy::RESET_MODE_MIGRATE])
->end()
->arrayNode('migrations')
->addDefaultsIfNotSet()
->children()
->arrayNode('configurations')
->info('Migration configurations')
->defaultValue([])
->scalarPrototype()->end()
->validate()
->ifTrue(function(array $configurationFiles): bool {
foreach ($configurationFiles as $configurationFile) {
if (!\is_file($configurationFile)) {
return true;
}
}

return false;
})
->thenInvalid('At least one migrations configuration file does not exist.')
->end()
->end()
->end()
->end()
->end()
->end()
->end()
Expand Down

0 comments on commit 6482357

Please sign in to comment.