-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating multiple SchemaBuilder implementations to allow interop with…
… newer Framework changes.
- Loading branch information
Kurt Friars
committed
Oct 3, 2024
1 parent
4b474f4
commit 385e27e
Showing
11 changed files
with
182 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Plank\Snapshots\Contracts; | ||
|
||
use Closure; | ||
|
||
interface VersionedSchema | ||
{ | ||
/** | ||
* Create a new table on the schema. | ||
* | ||
* @param class-string<Model> $model | ||
*/ | ||
public function createForModel(string $model, Closure $callback): void; | ||
|
||
/** | ||
* Create a new table on the schema. | ||
* | ||
* @param class-string<Model> $model | ||
* @param \Closure $callback | ||
*/ | ||
public function dropForModel($model): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Plank\Snapshots\Factory; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Schema\Builder; | ||
use Illuminate\Database\Schema\MySqlBuilder; | ||
use Illuminate\Database\Schema\PostgresBuilder; | ||
use Illuminate\Database\Schema\SQLiteBuilder; | ||
use Illuminate\Database\Schema\SqlServerBuilder; | ||
use Plank\Snapshots\Contracts\ManagesCreatedTables; | ||
use Plank\Snapshots\Contracts\ManagesVersions; | ||
use Plank\Snapshots\Contracts\VersionedSchema; | ||
use Plank\Snapshots\Schema\MySqlSnapshotBuilder; | ||
use Plank\Snapshots\Schema\PostgresSnapshotBuilder; | ||
use Plank\Snapshots\Schema\SnapshotSchemaBuilder; | ||
use Plank\Snapshots\Schema\SQLiteSnapshotBuilder; | ||
use Plank\Snapshots\Schema\SqlServerSnapshotBuilder; | ||
|
||
class SchemaBuilderFactory | ||
{ | ||
public static function make( | ||
Connection $connection, | ||
ManagesVersions $versions, | ||
ManagesCreatedTables $tables, | ||
): Builder&VersionedSchema { | ||
return match(get_class($connection->getSchemaBuilder())) { | ||
MySqlBuilder::class => new MySqlSnapshotBuilder($connection, $versions, $tables), | ||
PostgresBuilder::class => new PostgresSnapshotBuilder($connection, $versions, $tables), | ||
SQLiteBuilder::class => new SQLiteSnapshotBuilder($connection, $versions, $tables), | ||
SqlServerBuilder::class => new SqlServerSnapshotBuilder($connection, $versions, $tables), | ||
default => new SnapshotSchemaBuilder($connection, $versions, $tables), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Plank\Snapshots\Schema; | ||
|
||
use Illuminate\Database\Schema\MySqlBuilder; | ||
use Plank\Snapshots\Concerns\HasVersionedSchema; | ||
use Plank\Snapshots\Contracts\VersionedSchema; | ||
|
||
class MySqlSnapshotBuilder extends MySqlBuilder implements VersionedSchema | ||
{ | ||
use HasVersionedSchema; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Plank\Snapshots\Schema; | ||
|
||
use Illuminate\Database\Schema\PostgresBuilder; | ||
use Plank\Snapshots\Concerns\HasVersionedSchema; | ||
use Plank\Snapshots\Contracts\VersionedSchema; | ||
|
||
class PostgresSnapshotBuilder extends PostgresBuilder implements VersionedSchema | ||
{ | ||
use HasVersionedSchema; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Plank\Snapshots\Schema; | ||
|
||
use Illuminate\Database\Schema\SQLiteBuilder; | ||
use Plank\Snapshots\Concerns\HasVersionedSchema; | ||
use Plank\Snapshots\Contracts\VersionedSchema; | ||
|
||
class SQLiteSnapshotBuilder extends SQLiteBuilder implements VersionedSchema | ||
{ | ||
use HasVersionedSchema; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Plank\Snapshots\Schema; | ||
|
||
use Illuminate\Database\Schema\Builder; | ||
use Plank\Snapshots\Concerns\HasVersionedSchema; | ||
use Plank\Snapshots\Contracts\VersionedSchema; | ||
|
||
/** | ||
* @mixin Builder | ||
*/ | ||
class SnapshotSchemaBuilder extends Builder implements VersionedSchema | ||
{ | ||
use HasVersionedSchema; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Plank\Snapshots\Schema; | ||
|
||
use Illuminate\Database\Schema\SqlServerBuilder; | ||
use Plank\Snapshots\Concerns\HasVersionedSchema; | ||
use Plank\Snapshots\Contracts\VersionedSchema; | ||
|
||
class SqlServerSnapshotBuilder extends SqlServerBuilder implements VersionedSchema | ||
{ | ||
use HasVersionedSchema; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters