Skip to content

Commit 2b7ad1f

Browse files
committed
feat: Added Support for Applying one Single Migration
1 parent e7ec27c commit 2b7ad1f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

webfiori/database/migration/MigrationsRunner.php

+30
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,36 @@ public function hasMigration(string $name) : bool {
118118
}
119119
return false;
120120
}
121+
/**
122+
* Apply one single migration at a time.
123+
*
124+
* @return AbstractMigration|null If a migration was applied, the method will
125+
* return its information in an object of type 'AbstractMigration'. Other than that, null
126+
* is returned.
127+
*/
128+
public function applyOne() : ?AbstractMigration {
129+
$applied = null;
130+
foreach ($this->migrations as $m) {
131+
if ($this->isApplied($m->getName())) {
132+
continue;
133+
}
134+
$m->up($this);
135+
$this->table('migrations')
136+
->insert([
137+
'name' => $m->getName(),
138+
'applied-on' => date('Y-m-d H:i:s')
139+
])->execute();
140+
$applied = $m;
141+
break;
142+
}
143+
return $applied;
144+
}
145+
/**
146+
* Apply all detected migrations.
147+
*
148+
* @return array The method will return an array that holds all applied migrations
149+
* as objects of type 'AbstractMigration'.
150+
*/
121151
public function apply() : array {
122152
$applied = [];
123153
foreach ($this->migrations as $m) {

0 commit comments

Comments
 (0)