diff --git a/pkg/migrations/mysql/main_20240918132534_add_position_index.go b/pkg/migrations/mysql/main_20240918132534_add_position_index.go new file mode 100644 index 000000000..56381b136 --- /dev/null +++ b/pkg/migrations/mysql/main_20240918132534_add_position_index.go @@ -0,0 +1,29 @@ +package mysql + +import ( + "context" + + "github.com/c9s/rockhopper/v2" +) + +func init() { + AddMigration("main", up_main_addPositionIndex, down_main_addPositionIndex) +} + +func up_main_addPositionIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is applied. + _, err = tx.ExecContext(ctx, "CREATE INDEX positions_traded_at ON positions (traded_at, profit);") + if err != nil { + return err + } + return err +} + +func down_main_addPositionIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is rolled back. + _, err = tx.ExecContext(ctx, "DROP INDEX positions_traded_at ON positions;") + if err != nil { + return err + } + return err +} diff --git a/pkg/migrations/sqlite3/main_20240918132534_add_position_index.go b/pkg/migrations/sqlite3/main_20240918132534_add_position_index.go new file mode 100644 index 000000000..6301ddc68 --- /dev/null +++ b/pkg/migrations/sqlite3/main_20240918132534_add_position_index.go @@ -0,0 +1,29 @@ +package sqlite3 + +import ( + "context" + + "github.com/c9s/rockhopper/v2" +) + +func init() { + AddMigration("main", up_main_addPositionIndex, down_main_addPositionIndex) +} + +func up_main_addPositionIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is applied. + _, err = tx.ExecContext(ctx, "CREATE INDEX positions_traded_at ON positions (traded_at, profit);") + if err != nil { + return err + } + return err +} + +func down_main_addPositionIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is rolled back. + _, err = tx.ExecContext(ctx, "DROP INDEX positions_traded_at;") + if err != nil { + return err + } + return err +}