bbgo_origin/pkg/migrations/sqlite3/main_20200721225616_trades.go

30 lines
1.3 KiB
Go
Raw Normal View History

2021-02-06 01:51:05 +00:00
package sqlite3
import (
"context"
2024-01-18 13:36:04 +00:00
"github.com/c9s/rockhopper/v2"
2021-02-06 01:51:05 +00:00
)
func init() {
2024-01-18 13:36:04 +00:00
AddMigration("main", up_main_trades, down_main_trades)
2021-02-06 01:51:05 +00:00
}
2024-01-18 13:36:04 +00:00
func up_main_trades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
2021-02-06 01:51:05 +00:00
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `trades`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `id` INTEGER,\n `exchange` TEXT NOT NULL DEFAULT '',\n `symbol` TEXT NOT NULL,\n `price` DECIMAL(16, 8) NOT NULL,\n `quantity` DECIMAL(16, 8) NOT NULL,\n `quote_quantity` DECIMAL(16, 8) NOT NULL,\n `fee` DECIMAL(16, 8) NOT NULL,\n `fee_currency` VARCHAR(4) NOT NULL,\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `traded_at` DATETIME(3) NOT NULL\n);")
if err != nil {
return err
}
return err
}
2024-01-18 13:36:04 +00:00
func down_main_trades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
2021-02-06 01:51:05 +00:00
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `trades`;")
if err != nil {
return err
}
return err
}