Skip to content

Commit c606b6c

Browse files
author
Sergey Podgornyy
committed
Fix COLLATE issue for BLOB
1 parent 2d5b030 commit c606b6c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

column.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,13 @@ func (s String) buildRow() string {
295295
// longtext ➡️ migrator.Text{Prefix: "long", Default: "write you text", Charset: "utf8mb4", Collate: "utf8mb4_general_ci"}
296296
// ↪️ longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'write you text'
297297
// tinyblob ➡️ migrator.Text{Prefix: "tiny", Blob: true}
298-
// ↪️ tinyblob COLLATE utf8mb4_unicode_ci NOT NULL
298+
// ↪️ tinyblob NOT NULL
299299
// blob ➡️ migrator.Text{Blob: true}
300-
// ↪️ blob COLLATE utf8mb4_unicode_ci NOT NULL
300+
// ↪️ blob NOT NULL
301301
// mediumblob ➡️ migrator.Text{Prefix: "medium", Blob: true}
302-
// ↪️ mediumblob COLLATE utf8mb4_unicode_ci NOT NULL
302+
// ↪️ mediumblob NOT NULL
303303
// longblob ➡️ migrator.Text{Prefix: "long", Blob: true}
304-
// ↪️ longblob COLLATE utf8mb4_unicode_ci NOT NULL
304+
// ↪️ longblob NOT NULL
305305
type Text struct {
306306
Default string
307307
Nullable bool
@@ -330,7 +330,7 @@ func (t Text) buildRow() string {
330330

331331
if t.Collate != "" {
332332
sql += " COLLATE " + t.Collate
333-
} else if t.Charset == "" {
333+
} else if t.Charset == "" && !t.Blob {
334334
// use default
335335
sql += " COLLATE utf8mb4_unicode_ci"
336336
}

column_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,12 @@ func TestText(t *testing.T) {
308308

309309
t.Run("it builds blob", func(t *testing.T) {
310310
c := Text{Blob: true}
311-
assert.Equal(t, "blob COLLATE utf8mb4_unicode_ci NOT NULL", c.buildRow())
311+
assert.Equal(t, "blob NOT NULL", c.buildRow())
312312
})
313313

314314
t.Run("it builds blob with prefix", func(t *testing.T) {
315315
c := Text{Prefix: "tiny", Blob: true}
316-
assert.Equal(t, "tinyblob COLLATE utf8mb4_unicode_ci NOT NULL", c.buildRow())
316+
assert.Equal(t, "tinyblob NOT NULL", c.buildRow())
317317
})
318318

319319
t.Run("it builds with charset", func(t *testing.T) {
@@ -349,7 +349,7 @@ func TestText(t *testing.T) {
349349
t.Run("it builds string with all parameters", func(t *testing.T) {
350350
c := Text{
351351
Prefix: "long",
352-
Blob: true,
352+
Blob: false,
353353
Nullable: true,
354354
Charset: "utf8mb4",
355355
Collate: "utf8mb4_general_ci",
@@ -360,7 +360,7 @@ func TestText(t *testing.T) {
360360

361361
assert.Equal(
362362
t,
363-
"longblob CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'nice' ON UPDATE set null COMMENT 'test'",
363+
"longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'nice' ON UPDATE set null COMMENT 'test'",
364364
c.buildRow(),
365365
)
366366
})

0 commit comments

Comments
 (0)