Skip to content

Commit

Permalink
feat: add createTableIfNotExists migration helper (#3576)
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland authored Aug 2, 2022
1 parent 61c4421 commit 7d3147d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions framework/core/src/Database/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ public static function createTable($name, callable $definition)
];
}

/**
* 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.
*/
Expand Down

0 comments on commit 7d3147d

Please sign in to comment.