[2.x] fix(messages): shorten mention pivot table and column names - #4960
[2.x] fix(messages): shorten mention pivot table and column names#4960imorland wants to merge 2 commits into
Conversation
|
Closing — the approach here cannot work, and #4961 replaces it. This tried to raise the maximum usable table prefix by shortening the identifiers these migrations generate. Migrations are immutable and a new installation replays all of them, so the ceiling is set by migration history, not by the current schema. A later rename cannot stop the original The defect is real: the installer accepts a 10-character prefix that no driver can actually accommodate. #4961 fixes it the only way that works without touching migration history — by deriving the limit per driver (9 on MySQL and MariaDB, 8 on PostgreSQL, unrestricted on SQLite) and enforcing it in the installer and at boot, so the failure is stated up front instead of surfacing as MySQL error 1059 from inside a migration. The audit that came out of this is still worth recording: |
Found while validating the reworked CI matrix in #4959, which runs prefixed jobs at the maximum prefix length the installer accepts. Two of those jobs failed:
Changes proposed in this pull request:
DatabaseConfigaccepts table prefixes of up to 10 characters. This extension's mention pivot tables generate foreign key names that cannot survive one:So on MySQL or MariaDB, a bundled extension cannot be enabled on any installation using a 10-character prefix, and the installer permits exactly that. On PostgreSQL it appears to succeed, because PostgreSQL truncates over-long identifiers silently rather than erroring — the constraint is created under a name nobody chose, and two such names colliding after truncation would be the next failure.
Auditing every migration in core and the bundled extensions — 181 files, driven through Laravel's own
createIndexNamerather than by pattern-matching the convention — put all seven of the longest identifiers in this extension:This renames the four pivot tables and their columns so the generated names fit:
dialog_message_mentions_usermessage_mentions_userdialog_message_mentions_postmessage_mentions_postdialog_message_mentions_groupmessage_mentions_groupdialog_message_mentions_tagmessage_mentions_tagdialog_message_idmessage_idmentions_user_id/mentions_post_id/mentions_group_id/mentions_tag_iduser_id/post_id/group_id/tag_idThe longest identifier here becomes 41 characters, so this extension is no longer the binding constraint —
flarum/mentionsis, at 45. The maximum safe prefix across all supported drivers goes from 8 to 18, which finally clears the 10 the installer allows, with room to spare.The tables and columns are private to the extension: they are referenced only by these migrations and the four
belongsToManycalls inDialogMessage, all updated here. Nothing in the JS, the API resources, or the tests refers to them.Why rename rather than name the keys explicitly
Passing an explicit name to
foreign()looked like the smaller change, but it is wrong.prefix_indexesis consulted only insideBlueprint::createIndexName(), which runs only when no name is supplied — so an explicit name is never prefixed. Foreign key constraint names must be unique per database, not per table, which is exactly the shared-database case prefixes exist to serve. Two installations sharing one database would then collide:Verified against MySQL 8.4. Shortening the generated names keeps prefixing intact and avoids trading a length bug for a collision bug.
Existing installations
A release candidate installation that already enabled this extension has the old tables.
2026_08_22_000000_rename_message_mentions_tables.phprenames them and their columns where present, and no-ops where the new names already exist, so a fresh install and an upgraded one converge. An installation using a 10-character prefix cannot have created the old tables in the first place, since that is the failure this fixes.Reviewers should focus on:
message_mentions_*is the right name given the parent table isdialog_messages. Strictly the convention would givedialog_message_mentions_*, which is what caused this. The alternative is renamingdialog_messagestomessagesas well, which is a much larger change for no additional headroom.RENAME COLUMNnatively; SQLite needs 3.25 or newer, which is below the declaredSQLITE_MINIMUMof 3.35.Necessity
Confirmed
flarum/testingcheck, both following separately.RENAME COLUMNabove.