From c0deedcf48bad892f9f8b69b0d091c83ca736934 Mon Sep 17 00:00:00 2001 From: Alex Snast Date: Tue, 13 Aug 2019 02:09:45 -0700 Subject: [PATCH] set default mysql table collation to utf8mb4_bin (#1295) Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1295 Pull Request resolved: https://github.com/facebookincubator/ent/pull/13 See [Case Sensitivity in String Searches](https://dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html) Reviewed By: a8m Differential Revision: D16782072 fbshipit-source-id: f2a836e580757f0e956a444c3fdf93c502723098 --- dialect/sql/schema/schema.go | 6 +++--- entc/integration/integration_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/dialect/sql/schema/schema.go b/dialect/sql/schema/schema.go index 245f48b38..bcc281e0a 100644 --- a/dialect/sql/schema/schema.go +++ b/dialect/sql/schema/schema.go @@ -77,9 +77,9 @@ func (t *Table) MySQL(version string) *sql.TableBuilder { for _, pk := range t.PrimaryKey { b.PrimaryKey(pk.Name) } - // default character set to MySQL table. - // columns can be override using the "Charset" field. - b.Charset("utf8mb4") + // default charset / collation on MySQL table. + // columns can be override using the Charset / Collate fields. + b.Charset("utf8mb4").Collate("utf8mb4_bin") return b } diff --git a/entc/integration/integration_test.go b/entc/integration/integration_test.go index efd4ce52a..c0a9c9eb9 100644 --- a/entc/integration/integration_test.go +++ b/entc/integration/integration_test.go @@ -100,6 +100,7 @@ var tests = []func(*testing.T, *ent.Client){ Sanity, Paging, Charset, + Collation, Relation, Predicate, UniqueConstraint, @@ -245,6 +246,15 @@ func Charset(t *testing.T, client *ent.Client) { require.Equal("Nati", f4.Name) } +func Collation(t *testing.T, client *ent.Client) { + require := require.New(t) + ctx := context.Background() + _ = client.File.Create().SetName("Foo").SaveX(ctx) + query := client.File.Query().Where(file.Name("foo")) + require.False(query.ExistX(ctx)) + require.Nil(query.FirstX(ctx)) +} + func Predicate(t *testing.T, client *ent.Client) { require := require.New(t) ctx := context.Background()