-
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.
SchemaBuilder Per Connection Grammar (#27)
* Create multiple SchemaBuilder implementations per Connection Grammar. --------- Authored-by: kfriars <[email protected]>
- Loading branch information
Showing
17 changed files
with
447 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
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\SnapshotBuilder; | ||
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 SnapshotBuilder($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,38 @@ | ||
<?php | ||
|
||
namespace Plank\Snapshots\Schema; | ||
|
||
use Illuminate\Database\Schema\Builder; | ||
use Nette\NotImplementedException; | ||
use Plank\Snapshots\Concerns\HasVersionedSchema; | ||
use Plank\Snapshots\Contracts\VersionedSchema; | ||
|
||
/** | ||
* @mixin Builder | ||
*/ | ||
class SnapshotBuilder extends Builder implements VersionedSchema | ||
{ | ||
use HasVersionedSchema; | ||
|
||
/** | ||
* Get the indexes for a given table. | ||
* | ||
* @param string $table | ||
* @return array | ||
*/ | ||
public function getIndexes($table) | ||
{ | ||
throw new NotImplementedException('The `getIndexes` method requires a grammar specific Schema Builder.'); | ||
} | ||
|
||
/** | ||
* Get the foreign keys for a given table. | ||
* | ||
* @param string $table | ||
* @return array | ||
*/ | ||
public function getForeignKeys($table) | ||
{ | ||
throw new NotImplementedException('The `getForeignKeys` method requires a grammar specific Schema Builder.'); | ||
} | ||
} |
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
Oops, something went wrong.