Skip to content

Commit 6482357

Browse files
authored
feat: allow to configure migrations configuration files (#686)
1 parent b0a5d3d commit 6482357

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/ORM/AbstractORMPersistenceStrategy.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,29 @@ private function dropAndResetDatabase(Application $application): void
152152

153153
private function createSchema(Application $application): void
154154
{
155-
if (self::RESET_MODE_MIGRATE === $this->config['reset']['mode']) {
155+
if (self::RESET_MODE_SCHEMA === $this->config['reset']['mode']) {
156+
foreach ($this->managers() as $manager) {
157+
self::runCommand($application, 'doctrine:schema:update', [
158+
'--em' => $manager,
159+
'--force' => true,
160+
]);
161+
}
162+
163+
return;
164+
}
165+
166+
if (!$migrationsConfigurations = $this->config['reset']['migrations']['configurations']) {
156167
self::runCommand($application, 'doctrine:migrations:migrate', [
157168
'--no-interaction' => true,
158169
]);
159170

160171
return;
161172
}
162173

163-
foreach ($this->managers() as $manager) {
164-
self::runCommand($application, 'doctrine:schema:update', [
165-
'--em' => $manager,
166-
'--force' => true,
174+
foreach ($migrationsConfigurations as $migrationsConfiguration) {
175+
self::runCommand($application, 'doctrine:migrations:migrate', [
176+
'--configuration' => $migrationsConfiguration,
177+
'--no-interaction' => true,
167178
]);
168179
}
169180
}

src/ZenstruckFoundryBundle.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ public function configure(DefinitionConfigurator $definition): void
114114
->defaultValue(AbstractORMPersistenceStrategy::RESET_MODE_SCHEMA)
115115
->values([AbstractORMPersistenceStrategy::RESET_MODE_SCHEMA, AbstractORMPersistenceStrategy::RESET_MODE_MIGRATE])
116116
->end()
117+
->arrayNode('migrations')
118+
->addDefaultsIfNotSet()
119+
->children()
120+
->arrayNode('configurations')
121+
->info('Migration configurations')
122+
->defaultValue([])
123+
->scalarPrototype()->end()
124+
->validate()
125+
->ifTrue(function(array $configurationFiles): bool {
126+
foreach ($configurationFiles as $configurationFile) {
127+
if (!\is_file($configurationFile)) {
128+
return true;
129+
}
130+
}
131+
132+
return false;
133+
})
134+
->thenInvalid('At least one migrations configuration file does not exist.')
135+
->end()
136+
->end()
137+
->end()
138+
->end()
117139
->end()
118140
->end()
119141
->end()

0 commit comments

Comments
 (0)