mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 05:52:49 +08:00
feat: add createTableIfNotExists migration helper (#3576)
This commit is contained in:
parent
61c4421bd2
commit
7d3147d4e1
|
@ -38,6 +38,25 @@ abstract class Migration
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a table if it doesn't already exist.
|
||||
*/
|
||||
public static function createTableIfNotExists($name, callable $definition)
|
||||
{
|
||||
return [
|
||||
'up' => function (Builder $schema) use ($name, $definition) {
|
||||
if (! $schema->hasTable($name)) {
|
||||
$schema->create($name, function (Blueprint $table) use ($definition) {
|
||||
$definition($table);
|
||||
});
|
||||
}
|
||||
},
|
||||
'down' => function (Builder $schema) use ($name) {
|
||||
$schema->dropIfExists($name);
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a table.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user