diff --git a/migrations/202401092201_add_events_id_index.go b/migrations/202401092201_add_events_id_index.go new file mode 100644 index 00000000..7b2ef48e --- /dev/null +++ b/migrations/202401092201_add_events_id_index.go @@ -0,0 +1,17 @@ +package migrations + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +// Create a composite index to improve performance of finding the latest nostr event for an app +var _202401092201_add_events_id_index = &gormigrate.Migration{ + ID: "202401092201_add_events_id_index", + Migrate: func(tx *gorm.DB) error { + return tx.Exec("CREATE INDEX idx_nostr_events_app_id_and_id ON nostr_events(app_id, id)").Error + }, + Rollback: func(tx *gorm.DB) error { + return nil + }, +} diff --git a/migrations/migrate.go b/migrations/migrate.go index a3281a89..771b10ff 100644 --- a/migrations/migrate.go +++ b/migrations/migrate.go @@ -11,7 +11,8 @@ func Migrate(db *gorm.DB) error { _202309271616_initial_migration, _202309271617_fix_preimage_null, _202309271618_add_payment_sum_index, + _202401092201_add_events_id_index, }) return m.Migrate() -} \ No newline at end of file +}