create temporary index for the migration

This commit is contained in:
tobi 2025-03-03 18:17:57 +01:00
commit 672c63131c

View file

@ -34,22 +34,22 @@ func init() {
// To make update queries faster, // To make update queries faster,
// create an index on statuses // create an index on statuses
// that we'll drop when we're done. // that we'll drop when we're done.
log.Info(ctx, "creating temporary index statuses_local_created_with_application_id_idx, please wait...") log.Info(ctx, "creating temporary index statuses_created_with_application_id_idx, please wait...")
if _, err := db. if _, err := db.
NewCreateIndex(). NewCreateIndex().
Table("statuses"). Table("statuses").
Index("statuses_local_created_with_application_id_idx"). Index("statuses_created_with_application_id_idx").
Column("local", "created_with_application_id"). Column("created_with_application_id").
IfNotExists(). IfNotExists().
Exec(ctx); err != nil { Exec(ctx); err != nil {
return err return err
} }
defer func() { defer func() {
log.Info(ctx, "cleaning up temporary index statuses_local_created_with_application_id_idx, please wait...") log.Info(ctx, "cleaning up temporary index statuses_created_with_application_id_idx, please wait...")
if _, err := db. if _, err := db.
NewDropIndex(). NewDropIndex().
Index("statuses_local_created_with_application_id_idx"). Index("statuses_created_with_application_id_idx").
IfExists(). IfExists().
Exec(ctx); err != nil { Exec(ctx); err != nil {
panic(err) panic(err)
@ -131,7 +131,6 @@ func init() {
NewUpdate(). NewUpdate().
Table("statuses"). Table("statuses").
Set("? = ?", bun.Ident("created_with_application_id"), newAppID). Set("? = ?", bun.Ident("created_with_application_id"), newAppID).
Where("? = ?", bun.Ident("local"), true).
Where("? = ?", bun.Ident("created_with_application_id"), oldApp.ID). Where("? = ?", bun.Ident("created_with_application_id"), oldApp.ID).
Exec(ctx); err != nil { Exec(ctx); err != nil {
return err return err