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

Error in migration when using postgres. #747

Closed
oscarteg opened this issue Aug 15, 2019 · 16 comments · Fixed by #761
Closed

Error in migration when using postgres. #747

oscarteg opened this issue Aug 15, 2019 · 16 comments · Fixed by #761
Labels

Comments

@oscarteg
Copy link

oscarteg commented Aug 15, 2019

  • Cashier Version: v10.0.0
  • Laravel Version: v5.8.32
  • PHP Version: 7.3.8
  • Database Driver & Version: postgres 10

Description:

Then migration 2019_05_03_000001_create_customer_columns gives an error when using the postgres with Laravel. Running php artisan migrate on a fresh installation gives the following error.

Illuminate\Database\QueryException  : SQLSTATE[42704]: Undefined object: 7 ERROR:  collation "utf8mb4_bin" for encoding "UTF8" does not exist at character 57 (SQL: alter table "users" add column "stripe_id" varchar(255) collate "utf8mb4_bin" null, add column "card_brand" varchar(255) null, add column "card_last_four" varchar(4) null, add column "trial_ends_at" timestamp(0) without time zone null)

Steps To Reproduce:

  1. Fresh installation of laravel
  2. Change .env to use postgres as driver
  3. Add cashier as dependency
  4. php artisan migrate
@driesvints
Copy link
Member

Hmm, doesn't this collation exists on Postgres? I'm unfamiliar with Postgres so I don't know for sure. Stripe actually recommends to use this for MySQL but now I'm not sure if it's universal for every DB type: https://stripe.com/docs/upgrades#what-changes-does-stripe-consider-to-be-backwards-compatible

@hanspagel
Copy link

Can confirm, had this issue too. Had to delete the collation from the migration.

@driesvints
Copy link
Member

We'll need to find a universal way for this since it's recommended by Stripe to add this.

@pedrommone
Copy link
Contributor

pedrommone commented Aug 19, 2019

Just had the same issue.

As https://stripe.com/docs/upgrades#what-changes-does-stripe-consider-to-be-backwards-compatible says: If for example you’re using MySQL, you should store IDs in a VARCHAR(255) COLLATE utf8_bin column (the COLLATE configuration ensures case-sensitivity in lookups).

IMHO, there are two ways to fix that:

  1. Ignore since its specific for MySQL;
  2. Reproduce the same behavior for PgSQL.

Searching a little but, I've found that using LIKE for queries, as you can see here, can reproduce the case-sensitive behavior.

@pedrommone
Copy link
Contributor

Maybe the Laravel Schema should implement an $table->string('stripe_id')->sensitive() flag.

@driesvints
Copy link
Member

I think that would be pretty hard to do. I'd be pretty opinionated to enforce this with utf8mb4_bin in MySQL.

@rwdim
Copy link

rwdim commented Aug 23, 2019

Postgres uses utf8mb4 by default, but it's called "utf8". This should use the database config values:
'mysql' => [ ... 'charset' => 'utf8mb4',
and
'pgsql' => [ 'charset' => 'utf8',
values.

@driesvints
Copy link
Member

@rwdim if we'd change it to utf8_bin would that work?

@rwdim
Copy link

rwdim commented Aug 26, 2019 via email

@driesvints
Copy link
Member

@rwdim okay.

Can anyone try out on postgres by changing the migrations to use utf8_bin instead to see if that works?

@rwdim
Copy link

rwdim commented Aug 26, 2019 via email

@rwdim
Copy link

rwdim commented Aug 26, 2019 via email

@driesvints
Copy link
Member

I think maybe removing the default collation and noting something in the docs could be a good idea.

@staudenmeir do you think if we could add this to the schema builder to provide a solution for both postgres and mysql (and maybe the other two drivers as well)?

@rwdim
Copy link

rwdim commented Aug 26, 2019 via email

@staudenmeir
Copy link

This was "caused" by laravel/framework#29213. Before, Laravel ignored the collation on PostgreSQL.

I don't see how we could fix this in the schema builder.

Not the most elegant solution: We could detect the database driver in the migration and only add the collation on MySQL.

@driesvints
Copy link
Member

I think maybe it's best that we just remove the collation for now and add a note in the docs. I'll send in a PR.

driesvints added a commit that referenced this issue Aug 27, 2019
The reason for this is that the current collation is MySQL specific and doesn't works in other databases (like Postgres). This is still recommended by Stripe but maybe a note in the docs for this will suffice.

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

Successfully merging a pull request may close this issue.

6 participants