Skip to content

Commit 14a3693

Browse files
committed
👽 Cleanup deprecated calls, sort tables in dump (to match 5.x behaviour)
- `setCustomSchemaOptions` => `setPlatformOptions` - `hasPrimaryKey` => `getPrimaryKey()` (nullable) - `getColumns` => `getLocalColumns`
1 parent 93e258b commit 14a3693

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

src/SchemaVersionControl/SchemaBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function buildColumn(array $columnDesc, Column $column)
9292
$column->setComment($columnDesc['comment']);
9393
}
9494
if (isset($columnDesc['custom'])) {
95-
$column->setCustomSchemaOptions($columnDesc['custom']);
95+
$column->setPlatformOptions($columnDesc['custom']);
9696
}
9797
}
9898

src/SchemaVersionControl/SchemaNormalizer.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ public function normalize(Schema $schema): array
3232
foreach ($schema->getTables() as $table) {
3333
$schemaDesc['tables'][$table->getName()] = $this->normalizeTable($table);
3434
}
35+
ksort($schemaDesc['tables']);
36+
3537
return $schemaDesc;
3638
}
3739

3840
protected function normalizeTable(Table $table)
3941
{
4042
$tableDesc = [];
4143

42-
if ($table->hasPrimaryKey()) {
43-
$pk_columns = $table->getPrimaryKey()->getUnquotedColumns();
44+
$primaryKey = $table->getPrimaryKey();
45+
if ($primaryKey) {
46+
$pk_columns = $primaryKey->getUnquotedColumns();
4447
} else {
4548
$pk_columns = [];
4649
}
@@ -103,8 +106,8 @@ protected function normalizeColumn(Column $column, bool $isPrimaryKey)
103106
if ($column->getComment() !== null) {
104107
$columnDesc['comment'] = $column->getComment();
105108
}
106-
if (!empty($column->getCustomSchemaOptions())) {
107-
$columnDesc['custom'] = $column->getCustomSchemaOptions();
109+
if (!empty($column->getPlatformOptions())) {
110+
$columnDesc['custom'] = $column->getPlatformOptions();
108111
}
109112

110113
if (count($columnDesc) > 1) {
@@ -117,10 +120,10 @@ protected function normalizeColumn(Column $column, bool $isPrimaryKey)
117120
protected function normalizeForeignKeyConstraint(ForeignKeyConstraint $foreignKeyConstraint)
118121
{
119122
$constraintDesc = [];
120-
if (count($foreignKeyConstraint->getColumns()) > 1) {
121-
$constraintDesc['columns'] = $foreignKeyConstraint->getColumns();
123+
if (count($foreignKeyConstraint->getLocalColumns()) > 1) {
124+
$constraintDesc['columns'] = $foreignKeyConstraint->getLocalColumns();
122125
} else {
123-
$constraintDesc['column'] = $foreignKeyConstraint->getColumns()[0];
126+
$constraintDesc['column'] = $foreignKeyConstraint->getLocalColumns()[0];
124127
}
125128

126129
$constraintDesc['references'] = $this->normalizeForeignReference($foreignKeyConstraint);
@@ -135,8 +138,8 @@ protected function normalizeForeignReference(ForeignKeyConstraint $foreignKeyCon
135138
$referenceDesc = [];
136139
$foreignTableName = $foreignKeyConstraint->getForeignTableName();
137140
$foreignTable = $this->schema->getTable($foreignTableName);
138-
if ($foreignTable->hasPrimaryKey()
139-
&& $foreignTable->getPrimaryKeyColumns() == $foreignKeyConstraint->getForeignColumns()) {
141+
$foreignPrimaryKey = $foreignTable->getPrimaryKey();
142+
if ($foreignPrimaryKey && $foreignPrimaryKey->getColumns() == $foreignKeyConstraint->getForeignColumns()) {
140143
$referenceDesc = $foreignKeyConstraint->getForeignTableName();
141144
} else {
142145
$referenceDesc['table'] = $foreignKeyConstraint->getForeignTableName();

src/SchemaVersionControl/SchemaVersionControlService.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ public function __construct(Connection $connection, string $schemaFile)
3030
$this->schemaFile = $schemaFile;
3131
}
3232

33-
/**
34-
* Get the current schema used in database.
35-
* @return Schema
36-
*/
37-
public function getCurrentSchema(): Schema
38-
{
39-
return $this->connection->createSchemaManager()->createSchema();
40-
}
41-
4233
/**
4334
* Load schema from config file.
4435
* @return Schema
@@ -64,7 +55,8 @@ public function loadSchemaFile(): Schema
6455
*/
6556
public function dumpSchema(): void
6657
{
67-
$schema = $this->getCurrentSchema();
58+
$schemaManager = $this->connection->createSchemaManager();
59+
$schema = $schemaManager->createSchema();
6860
$normalizer = new SchemaNormalizer();
6961
$desc = $normalizer->normalize($schema);
7062
$yamlSchema = Yaml::dump(['schema' => $desc], 10, 2);

0 commit comments

Comments
 (0)