diff --git a/framework/core/src/Database/Migration.php b/framework/core/src/Database/Migration.php index 1fb0bcb2f8..7e51f68eb3 100644 --- a/framework/core/src/Database/Migration.php +++ b/framework/core/src/Database/Migration.php @@ -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. */