mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-28 12:46:16 -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() {
|
func init() {
|
||||||
up := func(ctx context.Context, db *bun.DB) error {
|
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.
|
// Status visibility type indices.
|
||||||
var statusVisIndices = []struct {
|
var statusVisIndices = []struct {
|
||||||
name string
|
name string
|
||||||
|
|
@ -98,8 +96,12 @@ func init() {
|
||||||
|
|
||||||
// Convert all visibility tables.
|
// Convert all visibility tables.
|
||||||
for _, table := range visTables {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +110,7 @@ func init() {
|
||||||
log.Info(ctx, "creating new visibility indexes...")
|
log.Info(ctx, "creating new visibility indexes...")
|
||||||
for _, index := range statusVisIndices {
|
for _, index := range statusVisIndices {
|
||||||
log.Infof(ctx, "creating new index %s...", index.name)
|
log.Infof(ctx, "creating new index %s...", index.name)
|
||||||
q := tx.NewCreateIndex().
|
q := db.NewCreateIndex().
|
||||||
Table("statuses").
|
Table("statuses").
|
||||||
Index(index.name).
|
Index(index.name).
|
||||||
Column(index.cols...)
|
Column(index.cols...)
|
||||||
|
|
@ -123,14 +125,15 @@ func init() {
|
||||||
// Get the mapping of old enum string values to the new integer value types.
|
// Get the mapping of old enum string values to the new integer value types.
|
||||||
notificationMapping := notificationEnumMapping[old_gtsmodel.NotificationType]()
|
notificationMapping := notificationEnumMapping[old_gtsmodel.NotificationType]()
|
||||||
|
|
||||||
// Migrate over old notifications table column over to new column type.
|
// Migrate over old notifications table column to new type in tx.
|
||||||
if err := convertEnums(ctx, tx, "notifications", "notification_type", //nolint:revive
|
if err := db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||||
notificationMapping, nil, nil); err != nil {
|
return convertEnums(ctx, tx, "notifications", "notification_type", //nolint:revive
|
||||||
|
notificationMapping, nil, nil)
|
||||||
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
down := func(ctx context.Context, db *bun.DB) error {
|
down := func(ctx context.Context, db *bun.DB) error {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue