mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-23 15:25:14 +00:00
45 lines
915 B
Go
45 lines
915 B
Go
package mysql
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/c9s/rockhopper"
|
|
)
|
|
|
|
func init() {
|
|
AddMigration(upAddPnlColumn, downAddPnlColumn)
|
|
|
|
}
|
|
|
|
func upAddPnlColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
|
// This code is executed when the migration is applied.
|
|
|
|
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `pnl` DECIMAL NULL;")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `strategy` VARCHAR(32) NULL;")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func downAddPnlColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
|
// This code is executed when the migration is rolled back.
|
|
|
|
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` DROP COLUMN `pnl`;")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` DROP COLUMN `strategy`;")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return err
|
|
}
|