mirror of
https://github.com/flarum/core.git
synced 2025-08-05 07:57:46 +02:00
feat: add createTableIfNotExists migration helper (#3576)
This commit is contained in:
@@ -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.
|
* Rename a table.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user