Increased `posts.content` size for MySQL.

`TEXT` -> 64kB
`MEDIUMTEXT` -> 16MB

Closes: https://github.com/writefreely/writefreely/issues/987
pull/1145/head
Fabio Manganiello 1 day ago
parent e29f371232
commit 13ce3d0784
No known key found for this signature in database
GPG Key ID: D90FBA7F76362774
  1. 9
      db/create.go
  2. 50
      migrations/v16.go
  3. 2
      schema.sql

@ -57,6 +57,7 @@ const (
ColumnTypeChar ColumnType = iota
ColumnTypeVarChar ColumnType = iota
ColumnTypeText ColumnType = iota
ColumnTypeLongText ColumnType = iota
ColumnTypeDateTime ColumnType = iota
)
@ -125,6 +126,14 @@ func (d ColumnType) Format(dialect DialectType, size OptionalInt) (string, error
return "DATETIME", nil
case ColumnTypeText:
return "TEXT", nil
case ColumnTypeLongText:
{
// MySQL TEXT is limited to 64KB, so use MEDIUMTEXT for larger sizes (up to 16MB)
if dialect == DialectMySQL {
return "MEDIUMTEXT", nil
}
return "TEXT", nil
}
}
return "", fmt.Errorf("unsupported column type %d for dialect %d and size %v", d, dialect, size)
}

@ -0,0 +1,50 @@
/*
* Copyright © 2019-2024 Musing Studio LLC.
*
* This file is part of WriteFreely.
*
* WriteFreely is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, included
* in the LICENSE file in this source code package.
*/
package migrations
import (
"context"
"database/sql"
wf_db "github.com/writefreely/writefreely/db"
)
func increasePostContentSize(db *datastore) error {
if db.driverName != driverMySQL {
// Only MySQL databases need this migration
return nil
}
dialect := wf_db.DialectMySQL
return wf_db.RunTransactionWithOptions(context.Background(), db.DB, &sql.TxOptions{}, func(ctx context.Context, tx *sql.Tx) error {
builders := []wf_db.SQLBuilder{
dialect.AlterTable("posts").
ChangeColumn("content",
dialect.Column(
"column",
wf_db.ColumnTypeLongText,
wf_db.OptionalInt{
Set: false,
Value: 0,
}).SetNullable(false)),
}
for _, builder := range builders {
query, err := builder.ToSQL()
if err != nil {
return err
}
if _, err := tx.ExecContext(ctx, query); err != nil {
return err
}
}
return nil
})
}

@ -136,7 +136,7 @@ CREATE TABLE IF NOT EXISTS `posts` (
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`view_count` int(6) NOT NULL,
`title` varchar(160) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
`content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
`content` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_slug` (`collection_id`,`slug`),
UNIQUE KEY `owner_id` (`owner_id`,`id`),

Loading…
Cancel
Save