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

Exception thrown when creating migration #6392

Open
lecneri opened this issue May 8, 2024 · 1 comment
Open

Exception thrown when creating migration #6392

lecneri opened this issue May 8, 2024 · 1 comment

Comments

@lecneri
Copy link

lecneri commented May 8, 2024

Bug Report

Q A
Version 3.8.4

Summary

Exception occurs at Doctrine\DBAL\Schema\Index::__addColumn while I try to make a migration with a table that has a function as index instead of column.
I believe this exception happens because I'm using a function inside the index in MySQL (8.0.35)

Current behaviour

I try to make a a migration and I an error is thrown. Here I paste the log
[2024-05-08T15:30:30.136808+00:00] console.CRITICAL: Error thrown while running command "make:migration -vvv". Message: "Doctrine\DBAL\Schema\Index::_addColumn(): Argument #1 ($column) must be of type string, null given, called in /home/len/projetos/dbal-bug-reproduce/vendor/doctrine/dbal/src/Schema/Index.php on line 72" {"exception":"[object] (TypeError(code: 0): Doctrine\\DBAL\\Schema\\Index::_addColumn(): Argument #1 ($column) must be of type string, null given, called in /home/len/projetos/dbal-bug-reproduce/vendor/doctrine/dbal/src/Schema/Index.php on line 72 at /home/len/projetos/dbal-bug-reproduce/vendor/doctrine/dbal/src/Schema/Index.php:81)","command":"make:migration -vvv","message":"Doctrine\\DBAL\\Schema\\Index::_addColumn(): Argument #1 ($column) must be of type string, null given, called in /home/len/projetos/dbal-bug-reproduce/vendor/doctrine/dbal/src/Schema/Index.php on line 72"} []

How to reproduce

1 - I started with composer create-project symfony/skeleton <project_name>
2 - composer req orm
3 - composer req --dev migrations maker debug log (last 2 is to make life easier)
4 - connect to MySQL and create database and table

CREATE TABLE foo (id int not null auto_increment, bugged_column datetime, primary key(id));

5 - create the index on bugged_column as follow

CREATE INDEX idx_bugged_column ON foo ((date(bugged_column)));

this will create an date based index, removing the time from column
6 - php bin/console make:migration
7 - Watch the crash

As far as I noticed, the error happens at Doctrine\DBAL\Schema\Index line 72, because the index created is not associated to any column directly, making the query return columns key with 1 line, but with a null value
image
this happens around line 1472 of Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableTableIndexesList
$result[$keyName]['columns'][] = $tableIndex['column_name']; // column name is null as returned from query in mysql
When I replaced with
$result[$keyName]['columns'][] = $tableIndex['column_name'] ?? ''; migration succeded, but I don't know what will happen leaving this way.
If you try to check before hand if the value is null it'll throw an error requiring columns

if ( $tableIndex['column_name'] !== null ) 
   $result[$keyName]['columns'][]            = $tableIndex['column_name'];

Expected behaviour

The expected behaviour is to execute the migration command correctly, creating a new migration.


I have a table with few hundred millions rows and I have a column datetime and few systems in php, power bi, excel querying this table making this date(column) instead of between yyyy-mm-dd 00:00:00 and yyyy-mm-dd 23:59:59, which was triggering a full table scan and this index improved performance a lot

@josipNi

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants