shlinkio / shlink

The definitive self-hosted URL shortener
https://shlink.io
MIT License
3.12k stars 253 forks source link

Upgrade from 3.7.4 to 4.0.3: Column "api_key_id" has invalid type #2165

Closed fibis closed 8 hours ago

fibis commented 1 month ago

Shlink version

3.7.4

PHP version

4.0.3

How do you serve Shlink

Docker image

Database engine

PostgreSQL

Database version

16

Current behavior

Migration is not successful and throws error:

shlink-1  |   ERR    ERR  In InvalidColumnDeclaration.php line 17:
shlink-1  |   ERR    ERR                                                        
shlink-1  |   ERR    ERR    [Doctrine\DBAL\Exception\InvalidColumnDeclaration]  
shlink-1  |   ERR    ERR    Column "api_key_id" has invalid type                
shlink-1  |   ERR    ERR                                                        
shlink-1  |   ERR    ERR  
shlink-1  |   ERR    ERR  Exception trace:
shlink-1  |   ERR    ERR    at /etc/shlink/vendor/doctrine/dbal/src/Exception/InvalidColumnDeclaration.php:17
shlink-1  |   ERR    ERR   Doctrine\DBAL\Exception\InvalidColumnDeclaration::fromInvalidColumnType() at /etc/shlink/vendor/doctrine/dbal/src/Platforms/AbstractPlatform.php:1399
shlink-1  |   ERR    ERR   Doctrine\DBAL\Platforms\AbstractPlatform->getDecimalTypeDeclarationSQL() at /etc/shlink/vendor/doctrine/dbal/src/Types/DecimalType.php:22
shlink-1  |   ERR    ERR   Doctrine\DBAL\Types\DecimalType->getSQLDeclaration() at /etc/shlink/vendor/doctrine/dbal/src/Platforms/AbstractPlatform.php:1372
shlink-1  |   ERR    ERR   Doctrine\DBAL\Platforms\AbstractPlatform->getColumnDeclarationSQL() at /etc/shlink/vendor/doctrine/dbal/src/Platforms/AbstractPlatform.php:2200
shlink-1  |   ERR    ERR   Doctrine\DBAL\Platforms\AbstractPlatform->columnsEqual() at /etc/shlink/vendor/doctrine/dbal/src/Schema/Comparator.php:404
shlink-1  |   ERR    ERR   Doctrine\DBAL\Schema\Comparator->columnsEqual() at /etc/shlink/vendor/doctrine/dbal/src/Schema/Comparator.php:183
shlink-1  |   ERR    ERR   Doctrine\DBAL\Schema\Comparator->compareTables() at /etc/shlink/vendor/doctrine/dbal/src/Schema/Comparator.php:59
shlink-1  |   ERR    ERR   Doctrine\DBAL\Schema\Comparator->compareSchemas() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Provider/DBALSchemaDiffProvider.php:44
shlink-1  |   ERR    ERR   Doctrine\Migrations\Provider\DBALSchemaDiffProvider->getSqlDiffToMigrate() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Provider/LazySchemaDiffProvider.php:50
shlink-1  |   ERR    ERR   Doctrine\Migrations\Provider\LazySchemaDiffProvider->getSqlDiffToMigrate() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Version/DbalExecutor.php:144
shlink-1  |   ERR    ERR   Doctrine\Migrations\Version\DbalExecutor->executeMigration() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Version/DbalExecutor.php:72
shlink-1  |   ERR    ERR   Doctrine\Migrations\Version\DbalExecutor->execute() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/DbalMigrator.php:88
shlink-1  |   ERR    ERR   Doctrine\Migrations\DbalMigrator->executePlan() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/DbalMigrator.php:54
shlink-1  |   ERR    ERR   Doctrine\Migrations\DbalMigrator->executeMigrations() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/DbalMigrator.php:136
shlink-1  |   ERR    ERR   Doctrine\Migrations\DbalMigrator->migrate() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php:219
shlink-1  |   ERR    ERR   Doctrine\Migrations\Tools\Console\Command\MigrateCommand->execute() at /etc/shlink/vendor/symfony/console/Command/Command.php:279
shlink-1  |   ERR    ERR   Symfony\Component\Console\Command\Command->run() at /etc/shlink/vendor/symfony/console/Application.php:1031
shlink-1  |   ERR    ERR   Symfony\Component\Console\Application->doRunCommand() at /etc/shlink/vendor/symfony/console/Application.php:318
shlink-1  |   ERR    ERR   Symfony\Component\Console\Application->doRun() at /etc/shlink/vendor/symfony/console/Application.php:169
shlink-1  |   ERR    ERR   Symfony\Component\Console\Application->run() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php:95
shlink-1  |   ERR    ERR   Doctrine\Migrations\Tools\Console\ConsoleRunner::run() at /etc/shlink/vendor/doctrine/migrations/bin/doctrine-migrations.php:45
shlink-1  |   ERR    ERR   Doctrine\Migrations\{closure}() at /etc/shlink/vendor/doctrine/migrations/bin/doctrine-migrations.php:46
shlink-1  |   ERR    ERR  
shlink-1  |   ERR    ERR  In ColumnPrecisionRequired.php line 18:
shlink-1  |   ERR    ERR                                                                         
shlink-1  |   ERR    ERR    [Doctrine\DBAL\Exception\InvalidColumnType\ColumnPrecisionRequired]  
shlink-1  |   ERR    ERR    Column precision is not specified                                    
shlink-1  |   ERR    ERR                                                                         
shlink-1  |   ERR    ERR  
shlink-1  |   ERR    ERR  Exception trace:
shlink-1  |   ERR    ERR    at /etc/shlink/vendor/doctrine/dbal/src/Exception/InvalidColumnType/ColumnPrecisionRequired.php:18
shlink-1  |   ERR    ERR   Doctrine\DBAL\Exception\InvalidColumnType\ColumnPrecisionRequired::new() at /etc/shlink/vendor/doctrine/dbal/src/Platforms/AbstractPlatform.php:1391
shlink-1  |   ERR    ERR   Doctrine\DBAL\Platforms\AbstractPlatform->getDecimalTypeDeclarationSQL() at /etc/shlink/vendor/doctrine/dbal/src/Types/DecimalType.php:22
shlink-1  |   ERR    ERR   Doctrine\DBAL\Types\DecimalType->getSQLDeclaration() at /etc/shlink/vendor/doctrine/dbal/src/Platforms/AbstractPlatform.php:1372
shlink-1  |   ERR    ERR   Doctrine\DBAL\Platforms\AbstractPlatform->getColumnDeclarationSQL() at /etc/shlink/vendor/doctrine/dbal/src/Platforms/AbstractPlatform.php:2200
shlink-1  |   ERR    ERR   Doctrine\DBAL\Platforms\AbstractPlatform->columnsEqual() at /etc/shlink/vendor/doctrine/dbal/src/Schema/Comparator.php:404
shlink-1  |   ERR    ERR   Doctrine\DBAL\Schema\Comparator->columnsEqual() at /etc/shlink/vendor/doctrine/dbal/src/Schema/Comparator.php:183
shlink-1  |   ERR    ERR   Doctrine\DBAL\Schema\Comparator->compareTables() at /etc/shlink/vendor/doctrine/dbal/src/Schema/Comparator.php:59
shlink-1  |   ERR    ERR   Doctrine\DBAL\Schema\Comparator->compareSchemas() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Provider/DBALSchemaDiffProvider.php:44
shlink-1  |   ERR    ERR   Doctrine\Migrations\Provider\DBALSchemaDiffProvider->getSqlDiffToMigrate() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Provider/LazySchemaDiffProvider.php:50
shlink-1  |   ERR    ERR   Doctrine\Migrations\Provider\LazySchemaDiffProvider->getSqlDiffToMigrate() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Version/DbalExecutor.php:144
shlink-1  |   ERR    ERR   Doctrine\Migrations\Version\DbalExecutor->executeMigration() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Version/DbalExecutor.php:72
shlink-1  |   ERR    ERR   Doctrine\Migrations\Version\DbalExecutor->execute() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/DbalMigrator.php:88
shlink-1  |   ERR    ERR   Doctrine\Migrations\DbalMigrator->executePlan() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/DbalMigrator.php:54
shlink-1  |   ERR    ERR   Doctrine\Migrations\DbalMigrator->executeMigrations() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/DbalMigrator.php:136
shlink-1  |   ERR    ERR   Doctrine\Migrations\DbalMigrator->migrate() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php:219
shlink-1  |   ERR    ERR   Doctrine\Migrations\Tools\Console\Command\MigrateCommand->execute() at /etc/shlink/vendor/symfony/console/Command/Command.php:279
shlink-1  |   ERR    ERR   Symfony\Component\Console\Command\Command->run() at /etc/shlink/vendor/symfony/console/Application.php:1031
shlink-1  |   ERR    ERR   Symfony\Component\Console\Application->doRunCommand() at /etc/shlink/vendor/symfony/console/Application.php:318
shlink-1  |   ERR    ERR   Symfony\Component\Console\Application->doRun() at /etc/shlink/vendor/symfony/console/Application.php:169
shlink-1  |   ERR    ERR   Symfony\Component\Console\Application->run() at /etc/shlink/vendor/doctrine/migrations/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php:95
shlink-1  |   ERR    ERR   Doctrine\Migrations\Tools\Console\ConsoleRunner::run() at /etc/shlink/vendor/doctrine/migrations/bin/doctrine-migrations.php:45
shlink-1  |   ERR    ERR   Doctrine\Migrations\{closure}() at /etc/shlink/vendor/doctrine/migrations/bin/doctrine-migrations.php:46
shlink-1  |   ERR    ERR  
shlink-1  |   ERR    ERR  migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--all-or-nothing [ALL-OR-NOTHING]] [--configuration CONFIGURATION] [--em EM] [--conn CONN] [--] [<version>]

Expected behavior

Succesfull migrate

Minimum steps to reproduce

Upgrade from 3x to 4x

acelaya commented 1 month ago

Minimum steps to reproduce

Upgrade from 3x to 4x

Sadly, not enough the reproduce the issue.

Please, provide a docker-compose-based environment where this can be reproduced consistently and I'll reopen.

fibis commented 1 month ago

This issue is related to the upgrade to doctrine 3 and relations don't have to correct type. For example, the api key id has the type bigint but api_key_id in api_key_roles is still numeric. This is throwing the error. To migrate successfully, you need to update the columns manually to bigint.

acelaya commented 1 month ago

Since you already seem to know the root cause, I'm happy to review a pull request 🙂

Also, would you mind adding some link/s which explain what made you come to this conclusion?

acelaya commented 8 hours ago

Closing until this becomes a priority for someone.