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

Detect smallint as numeric type in PostgreSQLPlatform::isNumericType to support schema changes for SMALLSERIAL #5390

Closed
umherirrender opened this issue May 12, 2022 · 1 comment · Fixed by #5395

Comments

@umherirrender
Copy link

umherirrender commented May 12, 2022

Bug Report

Q A
Version 3.1.5

Summary

The code in PostgreSQLPlatform::isNumericType (on version 3.1.5 it is in PostgreSQL94Platform) only detects INTEGER or BIGINT as numeric type, the smallint type is missing here.

Current behaviour

I want to change the column of a table from SERIAL to SMALLSERIAL, but the generated DDL contains a DROP DEFAULT, which is a bad idea on serial types

ALTER TABLE  table ALTER column TYPE SMALLINT;
ALTER TABLE  table ALTER column DROP  DEFAULT;

When changing from SERIAL to BIGSERIAL the DROP DEFAULT is not generated. This should be done for SMALLSERIAL as well.

How to reproduce

echo "Working bigint:\n";
$oldSchema = new \Doctrine\DBAL\Schema\Schema();
$oldTable = $oldSchema->createTable( 'table' );
$oldTable->addColumn( 'column', 'integer', [ 'autoincrement' => true ] );

$newSchema = new \Doctrine\DBAL\Schema\Schema();
$newTable = $newSchema->createTable( 'table' );
$newTable->addColumn( 'column', 'bigint', [ 'autoincrement' => true ] );

$comparator = new \Doctrine\DBAL\Schema\Comparator();
$schemaDiff = $comparator->compare( $oldSchema, $newSchema );
echo implode( ";\n", $schemaDiff->toSql( new \Doctrine\DBAL\Platforms\PostgreSQL94Platform ) ) . ';';

echo "\nNot working smalint:\n";
$oldSchema = new \Doctrine\DBAL\Schema\Schema();
$oldTable = $oldSchema->createTable( 'table' );
$oldTable->addColumn( 'column', 'integer', [ 'autoincrement' => true ] );

$newSchema = new \Doctrine\DBAL\Schema\Schema();
$newTable = $newSchema->createTable( 'table' );
$newTable->addColumn( 'column', 'smallint', [ 'autoincrement' => true ] );

$comparator = new \Doctrine\DBAL\Schema\Comparator();
$schemaDiff = $comparator->compare( $oldSchema, $newSchema );
echo implode( ";\n", $schemaDiff->toSql( new \Doctrine\DBAL\Platforms\PostgreSQL94Platform ) ) . ';';

gives

Working bigint:
ALTER TABLE "table" ALTER "column" TYPE BIGINT;
Not working smallint:
ALTER TABLE "table" ALTER "column" TYPE SMALLINT;
ALTER TABLE "table" ALTER "column" DROP DEFAULT;

Expected behaviour

Working bigint:
ALTER TABLE "table" ALTER "column" TYPE BIGINT;
Working smallint:
ALTER TABLE "table" ALTER "column" TYPE SMALLINT;

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants