diff --git a/src/Actions/InitialiseOrbitalTable.php b/src/Actions/InitialiseOrbitalTable.php index 8ff9ee1..85fbbb0 100644 --- a/src/Actions/InitialiseOrbitalTable.php +++ b/src/Actions/InitialiseOrbitalTable.php @@ -4,6 +4,8 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; +use Orbit\Contracts\Driver; +use Orbit\Contracts\ModifiesSchema; use Orbit\Contracts\Orbit; use Orbit\Support\ConfigureBlueprintFromModel; use ReflectionClass; @@ -21,7 +23,7 @@ public function shouldInitialise(Orbit&Model $model): bool return ($modelFileMTime > $databaseMTime) || ! $schemaBuilder->hasTable($model->getTable()); } - public function migrate(Orbit&Model $model): void + public function migrate(Orbit&Model $model, Driver $driver): void { $table = $model->getTable(); $schemaBuilder = $model->resolveConnection()->getSchemaBuilder(); @@ -30,12 +32,12 @@ public function migrate(Orbit&Model $model): void $schemaBuilder->drop($table); } - $blueprint = null; + $schemaBuilder->create($table, static function (Blueprint $table) use ($model, $driver) { + ConfigureBlueprintFromModel::configure($model, $table); - $schemaBuilder->create($table, static function (Blueprint $table) use (&$blueprint, $model) { - $blueprint = $table; - - ConfigureBlueprintFromModel::configure($model, $blueprint); + if ($driver instanceof ModifiesSchema) { + $driver->schema($table); + } }); } } diff --git a/src/Concerns/Orbital.php b/src/Concerns/Orbital.php index 56d5386..159bf73 100644 --- a/src/Concerns/Orbital.php +++ b/src/Concerns/Orbital.php @@ -45,7 +45,7 @@ public static function bootOrbital() $refreshed = false; if ($initialiseOrbitTable->shouldInitialise($model)) { - $initialiseOrbitTable->migrate($model); + $initialiseOrbitTable->migrate($model, $driver); $maybeRefreshDatabaseContent->refresh($model, $driver); $refreshed = true; diff --git a/src/Contracts/ModifiesSchema.php b/src/Contracts/ModifiesSchema.php new file mode 100644 index 0000000..108f908 --- /dev/null +++ b/src/Contracts/ModifiesSchema.php @@ -0,0 +1,10 @@ +text('content')->nullable(); + } + } + public function parse(string $fileContents): array { $document = YamlFrontMatter::parse($fileContents); diff --git a/src/Support/BlueprintUtilities.php b/src/Support/BlueprintUtilities.php new file mode 100644 index 0000000..2c682df --- /dev/null +++ b/src/Support/BlueprintUtilities.php @@ -0,0 +1,15 @@ +getColumns())->contains(static fn (ColumnDefinition $definition): bool => $definition->name === $column); + } +} diff --git a/tests/Feature/Support/BlueprintUtilitiesTest.php b/tests/Feature/Support/BlueprintUtilitiesTest.php new file mode 100644 index 0000000..7521a6b --- /dev/null +++ b/tests/Feature/Support/BlueprintUtilitiesTest.php @@ -0,0 +1,11 @@ +text('content')->nullable(); + + expect(BlueprintUtilities::hasColumn($blueprint, 'content'))->toBeTrue(); +});