Why does createDefaultRelationshipTableFields append random string to index? #850
Unanswered
IllyaMoskvin
asked this question in
Q&A
Replies: 1 comment
-
Hi @IllyaMoskvin! The reason for appending the random string is that we ran into too long generated index names on some projects, see laravel/framework#21446. Laravel maintainers are feeling like the ability to provide a custom names manually is covering for this issue. I kind of agree with the author of this proposal though ha! So our solution has been to add this random string but seeing what you had to do, I now better understand why they declined it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
With reference to this line in the
createDefaultRelationshipTableFields
function:https://github.com/area17/twill/blob/1.2/src/Helpers/migrations_helpers.php#L79
Why is
str_random(5)
appended to the index name?This causes issues if someone needs to rename one of the tables referenced in the index and wants to ensure that the index also gets renamed. We had to do this recently, and it wasn't pretty:
https://gist.github.com/IllyaMoskvin/056a52f72ae55061c062fbffc7d1fe02
Part of the problem is that we cannot predict the index name to target it for renaming, due to the random string suffix. There's probably a way to work around this without dropping all indexes as was the case in the example above – retrieve all indexes on the relationship table and find the one that starts with the predictable pattern.
But is there a reason for appending the random string? Am I overlooking something, or can we do without it?
Beta Was this translation helpful? Give feedback.
All reactions