Skip to content

Commit a7f6a2a

Browse files
Add upgrade schema function
1 parent 8fb3436 commit a7f6a2a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Eloquent/HasSchemaVersion.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public static function bootHasSchemaVersion(): void
2222
});
2323

2424
static::retrieved(function ($model) {
25-
if ($model->getSchemaVersion() < $model->currentSchemaVersion) {
26-
$model->migrateSchema($model->getSchemaVersion());
27-
}
25+
$model->migrateSchema($model->upgradeSchemaVersion());
2826
});
2927
}
3028

@@ -35,6 +33,20 @@ public function migrateSchema(int $fromVersion): void
3533
{
3634
}
3735

36+
/**
37+
* migrate schema and set current model version
38+
* @return void
39+
*/
40+
public function upgradeSchemaVersion(): void
41+
{
42+
$version = $this->getSchemaVersion();
43+
44+
if ($version && $version < $this->currentSchemaVersion) {
45+
$this->migrateSchema($version);
46+
$this->setSchemaVersion($this->currentSchemaVersion);
47+
}
48+
}
49+
3850
/**
3951
* Get Current document version
4052
*

0 commit comments

Comments
 (0)