Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more usage of deprecated methods #818

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Db/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1284,19 +1284,19 @@ public function executeActions(TableMetadata $table, array $actions): void
));
break;

case $action instanceof DropForeignKey && !$action->getForeignKey()->getConstraint():
case $action instanceof DropForeignKey && !$action->getForeignKey()->getName():
/** @var \Migrations\Db\Action\DropForeignKey $action */
$instructions->merge($this->getDropForeignKeyByColumnsInstructions(
$table->getName(),
$action->getForeignKey()->getColumns()
));
break;

case $action instanceof DropForeignKey && $action->getForeignKey()->getConstraint():
case $action instanceof DropForeignKey && $action->getForeignKey()->getName():
/** @var \Migrations\Db\Action\DropForeignKey $action */
$instructions->merge($this->getDropForeignKeyInstructions(
$table->getName(),
(string)$action->getForeignKey()->getConstraint()
(string)$action->getForeignKey()->getName()
));
break;

Expand Down
14 changes: 8 additions & 6 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1378,8 +1378,8 @@ protected function getIndexSqlDefinition(Index $index): string
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey): string
{
$def = '';
if ($foreignKey->getConstraint()) {
$def .= ' CONSTRAINT ' . $this->quoteColumnName((string)$foreignKey->getConstraint());
if ($foreignKey->getName()) {
$def .= ' CONSTRAINT ' . $this->quoteColumnName((string)$foreignKey->getName());
}
$columnNames = [];
foreach ($foreignKey->getColumns() as $column) {
Expand All @@ -1391,11 +1391,13 @@ protected function getForeignKeySqlDefinition(ForeignKey $foreignKey): string
$refColumnNames[] = $this->quoteColumnName($column);
}
$def .= ' REFERENCES ' . $this->quoteTableName($foreignKey->getReferencedTable()->getName()) . ' (' . implode(',', $refColumnNames) . ')';
if ($foreignKey->getOnDelete()) {
$def .= ' ON DELETE ' . $foreignKey->getOnDelete();
$onDelete = $foreignKey->getOnDelete();
if ($onDelete) {
$def .= ' ON DELETE ' . $onDelete;
}
if ($foreignKey->getOnUpdate()) {
$def .= ' ON UPDATE ' . $foreignKey->getOnUpdate();
$onUpdate = $foreignKey->getOnUpdate();
if ($onUpdate) {
$def .= ' ON UPDATE ' . $onUpdate;
}

return $def;
Expand Down
2 changes: 1 addition & 1 deletion src/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ protected function getForeignKeySqlDefinition(ForeignKey $foreignKey, string $ta
{
$parts = $this->getSchemaName($tableName);

$constraintName = $foreignKey->getConstraint() ?: (
$constraintName = $foreignKey->getName() ?: (
$parts['table'] . '_' . implode('_', $foreignKey->getColumns()) . '_fkey'
);
$def = ' CONSTRAINT ' . $this->quoteColumnName($constraintName) .
Expand Down
4 changes: 2 additions & 2 deletions src/Db/Adapter/SqliteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1866,8 +1866,8 @@ public function getColumnTypes(): array
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey): string
{
$def = '';
if ($foreignKey->getConstraint()) {
$def .= ' CONSTRAINT ' . $this->quoteColumnName((string)$foreignKey->getConstraint());
if ($foreignKey->getName()) {
$def .= ' CONSTRAINT ' . $this->quoteColumnName((string)$foreignKey->getName());
}
$columnNames = [];
foreach ($foreignKey->getColumns() as $column) {
Expand Down
2 changes: 1 addition & 1 deletion src/Db/Adapter/SqlserverAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ protected function getIndexSqlDefinition(Index $index, string $tableName): strin
*/
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey, string $tableName): string
{
$constraintName = $foreignKey->getConstraint() ?: $tableName . '_' . implode('_', $foreignKey->getColumns());
$constraintName = $foreignKey->getName() ?: $tableName . '_' . implode('_', $foreignKey->getColumns());
$def = ' CONSTRAINT ' . $this->quoteColumnName($constraintName);
$def .= ' FOREIGN KEY ("' . implode('", "', $foreignKey->getColumns()) . '")';
$def .= " REFERENCES {$this->quoteTableName($foreignKey->getReferencedTable()->getName())} (\"" . implode('", "', $foreignKey->getReferencedColumns()) . '")';
Expand Down
Loading