bbgo_origin/pkg/migrations/sqlite3/main_20220307132917_add_positions.go

30 lines
1.5 KiB
Go
Raw Normal View History

2022-03-07 05:44:43 +00:00
package sqlite3
import (
"context"
2024-01-18 13:36:04 +00:00
"github.com/c9s/rockhopper/v2"
2022-03-07 05:44:43 +00:00
)
func init() {
2024-01-18 13:36:04 +00:00
AddMigration("main", up_main_addPositions, down_main_addPositions)
2022-03-07 05:44:43 +00:00
}
2024-01-18 13:36:04 +00:00
func up_main_addPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
2022-03-07 05:44:43 +00:00
// This code is executed when the migration is applied.
2022-03-11 08:05:12 +00:00
_, err = tx.ExecContext(ctx, "CREATE TABLE `positions`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `strategy` VARCHAR(32) NOT NULL,\n `strategy_instance_id` VARCHAR(64) NOT NULL,\n `symbol` VARCHAR(20) NOT NULL,\n `quote_currency` VARCHAR(10) NOT NULL,\n `base_currency` VARCHAR(10) NOT NULL,\n -- average_cost is the position average cost\n `average_cost` DECIMAL(16, 8) NOT NULL,\n `base` DECIMAL(16, 8) NOT NULL,\n `quote` DECIMAL(16, 8) NOT NULL,\n `profit` DECIMAL(16, 8) NULL,\n -- trade related columns\n `trade_id` BIGINT NOT NULL,\n `side` VARCHAR(4) NOT NULL, -- side of the trade\n `exchange` VARCHAR(12) NOT NULL, -- exchange of the trade\n `traded_at` DATETIME(3) NOT NULL\n);")
2022-03-07 05:44:43 +00:00
if err != nil {
return err
}
return err
}
2024-01-18 13:36:04 +00:00
func down_main_addPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
2022-03-07 05:44:43 +00:00
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `positions`;")
if err != nil {
return err
}
return err
}