Make the Doctrine mapping describe the tables the module actually installs - #249
Draft
boo-code wants to merge 1 commit into
Draft
Make the Doctrine mapping describe the tables the module actually installs#249boo-code wants to merge 1 commit into
boo-code wants to merge 1 commit into
Conversation
…talls The three entities declare column types and indexes that differ from sql/install/*.sql, so doctrine:schema:update emits statements that fail or destroy data on a shop where the module is installed: ALTER TABLE ps_psgdpr_consent CHANGE error_message error_message VARCHAR(255) NOT NULL; ALTER TABLE ps_psgdpr_consent_lang CHANGE message message VARCHAR(255) NOT NULL; ALTER TABLE ps_psgdpr_log CHANGE id_guest id_guest INT NOT NULL, CHANGE client_name client_name VARCHAR(255) NOT NULL; DROP INDEX id_customer ON ps_psgdpr_log; DROP INDEX idx_id_customer ON ps_psgdpr_log; error_message and message are TEXT in the install SQL, so narrowing them to VARCHAR(255) fails with 'Data too long for column' on any consent text longer than 255 characters. id_guest and client_name are nullable in the install SQL. The two psgdpr_log indexes are created by the install SQL but absent from the mapping, so the schema tool treats them as unknown and drops them. Align the mapping with the shipped tables. Doctrine's text type maps to LONGTEXT unless a length is given, so length=65535 is needed to land on TEXT.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sql/install/*.sql, sodoctrine:schema:updateemits statements that fail or destroy data on a shop where the module is installed.error_messageandmessageareTEXTin the install SQL andVARCHAR(255) NOT NULLin the mapping, so the emittedCHANGEfails withERROR 1406 Data too long for columnon any consent text over 255 characters.id_guestandclient_nameare nullable in the install SQL andNOT NULLin the mapping. The twopsgdpr_logindexes created by the install SQL are absent from the mapping, so the schema tool treats them as unknown and emitsDROP INDEXfor both - including the module's own covering indexidx_id_customer.php bin/console doctrine:schema:update --dump-sqland look at theps_psgdpr_*lines. Before this change the output contains threeVARCHAR(255) NOT NULLnarrowings and twoDROP INDEX ... ON ps_psgdpr_log; after it, none of them.Measured
PrestaShop 9.2.0, psgdpr at
dev(2.0.3), the three tables created from this module's ownsql/install/*.sql. Only the mapping changed between the two runs.Before:
After (this branch alone, #230 not applied):
After (this branch stacked on #230):
Nothing destructive is left. The remaining statements are additive foreign keys and indexes the install
SQL never created, plus two safe items left deliberately out of scope (below).
The two failures are real, not theoretical, measured directly against MySQL 8:
Deliberately out of scope
activeanderrorareINT(10)in the install SQL andbooleanin the mapping, so the schema toolemits
TINYINT(1). The mapping is right - they are flags, and the getters returnbool- so the fixbelongs in the install SQL plus an upgrade script, not in the annotation. The statement is safe on the
values these columns hold, so it is left alone here.
MODIFY id_gdpr_consent INT NOT NULLonps_psgdpr_consent_langremoves anAUTO_INCREMENTthe installSQL puts on a column that is a foreign key into
ps_psgdpr_consent. Doctrine is right to drop it; samereasoning, same conclusion.
Notes
Two details that are easy to get wrong here:
texttype maps toLONGTEXT, notTEXT. Withoutlength=65535the emitted statementbecomes
CHANGE message message LONGTEXT DEFAULT NULL- safe, but still a diff. The length is whatmakes it disappear.
@ORM\Table()that omits indexes is not neutral.schema:updatetreats the mapping as the desiredstate, so any index it does not know about is emitted as
DROP INDEX, and--forcewould remove themodule's own covering index.
The module has no PHPUnit harness (CI is php-linter, php-cs-fixer and PHPStan only), so the verification
above stands in for a unit test.
doctrine:schema:validatereports[OK] The mapping files are correct.,and
php-cs-fixer --dry-runonsrc/Entityis clean.