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

Fix collision and performance issue #213

Merged
merged 2 commits into from
Oct 26, 2023
Merged

Conversation

hari
Copy link
Contributor

@hari hari commented Oct 9, 2023

Closes #210

@hari
Copy link
Contributor Author

hari commented Oct 9, 2023

@ash-jc-allen This one needs your review 😊. All tests are passing. I don't think I need to add any extra tests.

@ash-jc-allen
Copy link
Owner

Hey @hari! Apologies for the delay in getting this merged (it's been a busy few weeks!). Huge thank you 😄

@ash-jc-allen ash-jc-allen merged commit 0fea805 into ash-jc-allen:master Oct 26, 2023
13 checks passed
@boris-glumpler
Copy link
Contributor

Hey @ash-jc-allen, did you see my comment above? Came across this same issue with another package a while ago and their migrations threw an error for me because this particular collation doesn't exist on Postgres, which is case-sensitive by default.

@ash-jc-allen
Copy link
Owner

Hey @boris-glumpler! I can't see any comments from you on this page, sorry. This is all I see:

image

I wonder if the comment might be part of a "review" that's not been submitted yet, maybe?

Thanks for pointing this out to me. I've not got any experience with using Postgres, so I wasn't aware of that. I'll make sure to update the readme to mention that you might want to remove this part of the migration if you're using Postgres 🙂

@@ -16,7 +16,7 @@ public function up()
Schema::create('short_urls', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('destination_url');
$table->string('url_key')->unique();
$table->string('url_key')->unique()->collation('utf8mb4_bin');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think utf8mb4_bin is specific to MySQL and will fail on Postgres.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work:

$table->string('url_key')->unique()->when(
    Schema::getConnection()->getConfig('driver') === 'mysql',
    function (Blueprint $column) {
        $column->collation('utf8mb4_bin');
    }
);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thanks for this suggestion! I can't quite make my mind up between whether we should automatically handle this in the migration, or just mention it in the docs so people can make the change themselves. I guess there are pros and cons to either side 🤔

What's your opinion on this? 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boris-glumpler thank you for the information. I think we should do both - update the doc and add the conditional logic @ash-jc-allen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure there's a downside to adding the conditional. If it bothers people, they can change it. If not, then no harm done.

@boris-glumpler
Copy link
Contributor

Duh... You should be able to see it now ;)

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

Successfully merging this pull request may close these issues.

Collision and performance issue
3 participants