1
0
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:
Ian Morland
2022-08-02 10:43:31 +01:00
committed by GitHub
parent 61c4421bd2
commit 7d3147d4e1

View File

@@ -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.
*/