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

Doctrine Migrations can't work with integer column names. #5295

Open
ddpv opened this issue Feb 24, 2022 · 1 comment
Open

Doctrine Migrations can't work with integer column names. #5295

ddpv opened this issue Feb 24, 2022 · 1 comment

Comments

@ddpv
Copy link

ddpv commented Feb 24, 2022

Bug Report

In Doctrine\DBAL\Schema\Table in the function getColumns an array_merge is done where some of the indexes are the column names. If a column name is an integer like 2512 but not 0504 then the index is re-indexed and becomes a sequential number mixed with the string indexes.
This causes Doctrine Migrations to try to drop and add the columns with the integer names during any migration because it compares the current database to itself and can't find the columns. Why it insists on doing this when only Doctrine Migrations (not ORM part) is used is not clear to me but that is the way it is.
I can't find a definitive answer whether integer column names (123 causes error, 0123 does not) are legal names but both MS-SQL and MySQL allow for it, you have to wrap the column name in [] and `` respectively but it does work.

This is the SQL it generates in my use case:

ALTER TABLE feestdagen ADD 2412 VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci,
ADD 2512 VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci,
ADD 2612 VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci,
ADD 3112 VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci,
ADD 2704 VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci,
ADD 1305 VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci,
ADD 2305 VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci,
ADD 3103 VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci,
ADD 2405 VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT '' NOT NULL COLLATE utf8mb4_unicode_ci,
DROP 2412, DROP 2512, DROP 2612, DROP 3112, DROP 2704, DROP 1305, DROP 2305, DROP 3103, DROP 2405;

We are migrating away from the offending table so this issue is not urgent but I think if it can't be fixed at least having a record of it might help other users. Spend a few hours wondering why suddenly the index names disappeared.

Q A
Version 3.4.1.0

Summary

Doctrine Migrations can't handle integer column names, it tries to drop and add them for each migration.

Current behaviour

Each migration gets an additional line of alter table.

How to reproduce

Create a table with an integer for a column name.

CREATE TABLE feestdagen (
id int NOT NULL AUTO_INCREMENT,
restaurant varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
0512 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
2412 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
2512 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
2612 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
3112 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
0101 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
0204 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
0404 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
0504 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
2704 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
0505 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
1305 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
2305 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
3103 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
2405 varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

feestdagen means holidays, the offending field are the dates of holidays, those starting with 0 work fine.

Expected behaviour

For integer column names to work the same as string column names.

@morozov
Copy link
Member

morozov commented Feb 24, 2022

This seems similar to #4508. I don't believe there is a simple solution to this. In general, it's a particular case of #4357 and requires a major API rework as described in #4772.

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

No branches or pull requests

2 participants