-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Schema diffing breaks since 3.2.0 when defining custom collation on column #5349
Comments
In you column definitions, can you please use |
@derrabus Thanks, I updated the issue and used collate everywhere, that seems to improve it, as it reduces the diff to this:
|
I'm not sure if those column options should be called Also good to mention as to why I'm specifying When the column specifies the same as the Table defaults, they are removed by Doctrine\DBAL\Platforms\MySQL\Comparator::normalizeColumns. When comparing them to the database schema, it's always different that causes the diff tool to propose an update. I think this normalization is naive. When a user explicitly added the values, they should not be removed (normalized). |
After spending the whole day debugging, I came to the realization that the only reason I have custom charset/collation on the columns is that I want to setup the JoinColumns between tables in 2 different charset/collations. This is actually a bug in ORM, and should be fixed like this: |
I've just had this problem the other day, so I wanted to check if this fixes your problem as well. Apparently, it does. I think, @greg0ire has worked on this previously. This still seems to be a footgun. 😓 |
I think it does not solve the problem it just masks it... The column should use The root cause of my problems (in this issue) are drilled down to the following:
I think the real problem is that DBAL has no idea of knowing if the column (from the database) has explicitly defined it's charset/collation, or that it used the table's default. It runs this SQL query: SELECT
COLUMN_NAME AS Field, COLUMN_TYPE AS Type, IS_NULLABLE AS `Null`, COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment,
CHARACTER_SET_NAME AS CharacterSet,
COLLATION_NAME AS Collation
FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'content_organizer_brand' ORDER BY ORDINAL_POSITION ASC and from there, there is no difference between explicit and implicit charset/collation. But when you use
If DBAL would use that information, it would know that the column already had the correct charset/collation. |
If I use "collation" instead of "collate" in the |
Shouldn't it be the opposite? See #5249. |
Hello everyone, thanks for your help so far. I created a reproducer repository where I was table to reproduce the problem for ORM specific: $ php orm.php
The following SQL statements will be executed:
CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL,
firstName VARCHAR(255) CHARACTER SET ascii NOT NULL COLLATE `ascii_general_ci`,
lastName VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`,
email VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_bin`,
PRIMARY KEY(id)) DEFAULT CHARACTER SET ascii COLLATE `ascii_general_ci` ENGINE = InnoDB;
CREATE TABLE tags (id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_bin`,
title VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`,
description VARCHAR(255) CHARACTER SET ascii NOT NULL COLLATE `ascii_general_ci`,
PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;
Updating database schema...
2 queries were executed
Database schema updated successfully!
Checking if database schema is sync...
Database schema is not sync!
The following differences were found:
ALTER TABLE users CHANGE firstName firstName VARCHAR(255) CHARACTER SET ascii NOT NULL COLLATE `ascii_general_ci`;
ALTER TABLE tags CHANGE name name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_bin`,
CHANGE title title VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`; I also tried to reproduce it for DBAL but couldn't get the exact same result but I think I'm not setting the schema like ORM does. The conclusion is that as soon as your column defines charset / collation that is exactly the same as the table default, it will always be a difference, that you cannot ever get to sync. This is caused by the MySQL Comparator::normalizeColumns method. I think that the normalization should be altered, so that it knows when a user defines Please have a look, thanks 💙 |
@ruudk, if you believe the problem exists and needs to be fixed in the DBAL, please reproduce it using only the DBAL APIs like you did in the issue description but without using the deprecated "collate" option as suggested in #5349 (comment). Once the problem is reproduced, we can discuss the solution. |
I'm going to close the issue as non-reproducible. Please feel free to provide the steps to reproduce and reopen. |
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. |
Bug Report
Summary
After upgrading from dbal 3.1.5 I noticed that diffing schema changes (by Doctrine Migrations Bundle) would always result in updates that never go away after applying them.
This issue has been reported numerous times:
collate
#5265Still, after following those issues and waiting for a new release, the problem is not gone for me.
Current behaviour
I know this is a DBAL repository, and it should only talk about DBAL, but my table configuration is coming from ORM. To give all the context, this is my ORM configuration. Afterwards I'll share a DBAL only reproducer.
When running
bin/console doctrine:schema:update --dump-sql
I get the following:How to reproduce
This is a DBAL only reproducer that shows the same problem:
This results in the following queries:
Even when I apply them, it keeps on reporting them.
Expected behaviour
No changes.
The text was updated successfully, but these errors were encountered: