mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2026-01-06 03:43:15 -06:00
separate enum migrations into their own individual transactions
This commit is contained in:
parent
879ca2d2f8
commit
0d4abe01f5
1 changed files with 95 additions and 92 deletions
|
|
@ -30,8 +30,6 @@ import (
|
|||
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
|
||||
// Status visibility type indices.
|
||||
var statusVisIndices = []struct {
|
||||
name string
|
||||
|
|
@ -98,8 +96,12 @@ func init() {
|
|||
|
||||
// Convert all visibility tables.
|
||||
for _, table := range visTables {
|
||||
if err := convertEnums(ctx, tx, table.Table, table.Column,
|
||||
visibilityMapping, table.Default, table.IndexCleanupCallback); err != nil {
|
||||
|
||||
// Perform each enum table conversion within its own transaction.
|
||||
if err := db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return convertEnums(ctx, tx, table.Table, table.Column,
|
||||
visibilityMapping, table.Default, table.IndexCleanupCallback)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +110,7 @@ func init() {
|
|||
log.Info(ctx, "creating new visibility indexes...")
|
||||
for _, index := range statusVisIndices {
|
||||
log.Infof(ctx, "creating new index %s...", index.name)
|
||||
q := tx.NewCreateIndex().
|
||||
q := db.NewCreateIndex().
|
||||
Table("statuses").
|
||||
Index(index.name).
|
||||
Column(index.cols...)
|
||||
|
|
@ -123,14 +125,15 @@ func init() {
|
|||
// Get the mapping of old enum string values to the new integer value types.
|
||||
notificationMapping := notificationEnumMapping[old_gtsmodel.NotificationType]()
|
||||
|
||||
// Migrate over old notifications table column over to new column type.
|
||||
if err := convertEnums(ctx, tx, "notifications", "notification_type", //nolint:revive
|
||||
notificationMapping, nil, nil); err != nil {
|
||||
// Migrate over old notifications table column to new type in tx.
|
||||
if err := db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return convertEnums(ctx, tx, "notifications", "notification_type", //nolint:revive
|
||||
notificationMapping, nil, nil)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
down := func(ctx context.Context, db *bun.DB) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue