Merge 0c78d4095a
into 72fa575fee
This commit is contained in:
commit
460e2dc069
4 changed files with 62 additions and 0 deletions
|
@ -57,6 +57,7 @@ const (
|
||||||
ColumnTypeChar ColumnType = iota
|
ColumnTypeChar ColumnType = iota
|
||||||
ColumnTypeVarChar ColumnType = iota
|
ColumnTypeVarChar ColumnType = iota
|
||||||
ColumnTypeText ColumnType = iota
|
ColumnTypeText ColumnType = iota
|
||||||
|
ColumnTypeLongText ColumnType = iota
|
||||||
ColumnTypeDateTime ColumnType = iota
|
ColumnTypeDateTime ColumnType = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -125,6 +126,14 @@ func (d ColumnType) Format(dialect DialectType, size OptionalInt) (string, error
|
||||||
return "DATETIME", nil
|
return "DATETIME", nil
|
||||||
case ColumnTypeText:
|
case ColumnTypeText:
|
||||||
return "TEXT", nil
|
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)
|
return "", fmt.Errorf("unsupported column type %d for dialect %d and size %v", d, dialect, size)
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ var migrations = []Migration{
|
||||||
New("support password resetting", supportPassReset), // V13 -> V14
|
New("support password resetting", supportPassReset), // V13 -> V14
|
||||||
New("speed up blog post retrieval", addPostRetrievalIndex), // V14 -> V15
|
New("speed up blog post retrieval", addPostRetrievalIndex), // V14 -> V15
|
||||||
New("support ActivityPub likes", supportRemoteLikes), // V15 -> V16 (v0.16.0)
|
New("support ActivityPub likes", supportRemoteLikes), // V15 -> V16 (v0.16.0)
|
||||||
|
New("posts.content column size", increasePostContentSize), // V16 -> V17
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentVer returns the current migration version the application is on
|
// CurrentVer returns the current migration version the application is on
|
||||||
|
|
|
@ -36,3 +36,4 @@ func supportRemoteLikes(db *datastore) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
51
migrations/v17.go
Normal file
51
migrations/v17.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue