diff --git a/Makefile b/Makefile index fd234a2e8..9c2105df4 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,9 @@ dist: bin-dir bbgo-linux bbgo-darwin mkdir -p $(DIST_DIR) tar -C $(BUILD_DIR) -cvzf $(DIST_DIR)/bbgo-$$(git describe --tags).tar.gz . +migrations: + rockhopper compile --config rockhopper.yaml --output pkg/migrations + docker: GOPATH=$(PWD)/.mod go mod download docker build --build-arg GO_MOD_CACHE=.mod --tag yoanlin/bbgo . @@ -36,4 +39,4 @@ docker-push: docker push yoanlin/bbgo bash -c "[[ -n $(DOCKER_TAG) ]] && docker push yoanlin/bbgo:$(DOCKER_TAG)" -.PHONY: dist +.PHONY: dist migrations diff --git a/go.mod b/go.mod index 33af58ec9..074e2483c 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/adshao/go-binance/v2 v2.2.1-0.20210108025425-9a582c63144e github.com/c9s/goose v0.0.0-20200415105707-8da682162a5b - github.com/c9s/rockhopper v1.2.1-0.20210114070642-bde97ed28999 + github.com/c9s/rockhopper v1.2.1-0.20210115022144-cc77e66fc34f github.com/codingconcepts/env v0.0.0-20200821220118-a8fbf8d84482 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/go-redis/redis/v8 v8.4.0 diff --git a/go.sum b/go.sum index 44b40b09b..da4768fd1 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,12 @@ github.com/c9s/rockhopper v1.2.1-0.20210114064926-84f8d06c527b h1:D4TpmOWK8GVV7b github.com/c9s/rockhopper v1.2.1-0.20210114064926-84f8d06c527b/go.mod h1:KJnQjZSrWA83jjwGF/+O7Y96VCVirYTYEvXJJOc6kMU= github.com/c9s/rockhopper v1.2.1-0.20210114070642-bde97ed28999 h1:++sXjheN0ZuQtOvzqnCx/jCs4wDSQoj2GMEbE1UvsGE= github.com/c9s/rockhopper v1.2.1-0.20210114070642-bde97ed28999/go.mod h1:KJnQjZSrWA83jjwGF/+O7Y96VCVirYTYEvXJJOc6kMU= +github.com/c9s/rockhopper v1.2.1-0.20210115015707-d3b0b1892dfd h1:Q3MLSogx558Xnc43uBFbPnlIQvI3mThaAc/buea/mQ4= +github.com/c9s/rockhopper v1.2.1-0.20210115015707-d3b0b1892dfd/go.mod h1:KJnQjZSrWA83jjwGF/+O7Y96VCVirYTYEvXJJOc6kMU= +github.com/c9s/rockhopper v1.2.1-0.20210115020622-659f1b03767b h1:1Ixa0xWAD3KADLCEb5sHAz/3rjP47XqHRW3zK6oz1Sk= +github.com/c9s/rockhopper v1.2.1-0.20210115020622-659f1b03767b/go.mod h1:KJnQjZSrWA83jjwGF/+O7Y96VCVirYTYEvXJJOc6kMU= +github.com/c9s/rockhopper v1.2.1-0.20210115022144-cc77e66fc34f h1:n1Ly7178MJj+GQB38q4dV66QktUvzEi2rA7xCtTy6Ck= +github.com/c9s/rockhopper v1.2.1-0.20210115022144-cc77e66fc34f/go.mod h1:KJnQjZSrWA83jjwGF/+O7Y96VCVirYTYEvXJJOc6kMU= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= diff --git a/migrations/20200721225616_trades.sql b/migrations/20200721225616_trades.sql index 806efd22f..12d4e4c77 100644 --- a/migrations/20200721225616_trades.sql +++ b/migrations/20200721225616_trades.sql @@ -1,23 +1,23 @@ -- +up -CREATE TABLE `trades` ( - `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, +CREATE TABLE `trades` +( + `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, - `id` BIGINT UNSIGNED, - `exchange` VARCHAR(24) NOT NULL DEFAULT '', - `symbol` VARCHAR(8) NOT NULL, - `price` DECIMAL(16, 8) UNSIGNED NOT NULL, - `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, - `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, - `fee` DECIMAL(16, 8) UNSIGNED NOT NULL, - `fee_currency` VARCHAR(4) NOT NULL, - `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE, - `is_maker` BOOLEAN NOT NULL DEFAULT FALSE, - `side` VARCHAR(4) NOT NULL DEFAULT '', - `traded_at` DATETIME(3) NOT NULL, + `id` BIGINT UNSIGNED, + `exchange` VARCHAR(24) NOT NULL DEFAULT '', + `symbol` VARCHAR(8) NOT NULL, + `price` DECIMAL(16, 8) UNSIGNED NOT NULL, + `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, + `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, + `fee` DECIMAL(16, 8) UNSIGNED NOT NULL, + `fee_currency` VARCHAR(4) NOT NULL, + `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE, + `is_maker` BOOLEAN NOT NULL DEFAULT FALSE, + `side` VARCHAR(4) NOT NULL DEFAULT '', + `traded_at` DATETIME(3) NOT NULL, - PRIMARY KEY (`gid`), - UNIQUE KEY `id` (`id`) - -) ENGINE=InnoDB; --- +goose Down + PRIMARY KEY (`gid`), + UNIQUE KEY `id` (`id`) +); +-- +down DROP TABLE `trades`; diff --git a/migrations/20200819054742_trade_index.sql b/migrations/20200819054742_trade_index.sql index 61f8fb3fd..6ce90b1bd 100644 --- a/migrations/20200819054742_trade_index.sql +++ b/migrations/20200819054742_trade_index.sql @@ -1,9 +1,9 @@ --- +goose Up +-- +up CREATE INDEX trades_symbol ON trades(symbol); CREATE INDEX trades_symbol_fee_currency ON trades(symbol, fee_currency, traded_at); CREATE INDEX trades_traded_at_symbol ON trades(traded_at, symbol); --- +goose Down +-- +down DROP INDEX trades_symbol ON trades; DROP INDEX trades_symbol_fee_currency ON trades; DROP INDEX trades_traded_at_symbol ON trades; diff --git a/migrations/20201102222546_orders.sql b/migrations/20201102222546_orders.sql index 70f0dedb8..ec5eb0e11 100644 --- a/migrations/20201102222546_orders.sql +++ b/migrations/20201102222546_orders.sql @@ -1,4 +1,4 @@ --- +goose Up +-- +up CREATE TABLE `orders` ( `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, @@ -21,7 +21,6 @@ CREATE TABLE `orders` `updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3), PRIMARY KEY (`gid`) -) ENGINE = InnoDB; - --- +goose Down +); +-- +down DROP TABLE `orders`; diff --git a/migrations/20201103173342_trades_add_order_id.sql b/migrations/20201103173342_trades_add_order_id.sql index ab33542ae..6af8910fd 100644 --- a/migrations/20201103173342_trades_add_order_id.sql +++ b/migrations/20201103173342_trades_add_order_id.sql @@ -1,7 +1,7 @@ --- +goose Up +-- +up ALTER TABLE `trades` ADD COLUMN `order_id` BIGINT UNSIGNED NOT NULL; --- +goose Down +-- +down ALTER TABLE `trades` DROP COLUMN `order_id`; diff --git a/migrations/20201105092857_trades_index_fix.sql b/migrations/20201105092857_trades_index_fix.sql index 0934eb491..452f7fa8d 100644 --- a/migrations/20201105092857_trades_index_fix.sql +++ b/migrations/20201105092857_trades_index_fix.sql @@ -1,4 +1,4 @@ --- +goose Up +-- +up DROP INDEX trades_symbol ON trades; DROP INDEX trades_symbol_fee_currency ON trades; DROP INDEX trades_traded_at_symbol ON trades; @@ -7,7 +7,7 @@ CREATE INDEX trades_symbol ON trades (exchange, symbol); CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at); CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol); --- +goose Down +-- +down DROP INDEX trades_symbol ON trades; DROP INDEX trades_symbol_fee_currency ON trades; DROP INDEX trades_traded_at_symbol ON trades; diff --git a/migrations/20201105093056_orders_add_index.sql b/migrations/20201105093056_orders_add_index.sql index 484143730..4d685d4a9 100644 --- a/migrations/20201105093056_orders_add_index.sql +++ b/migrations/20201105093056_orders_add_index.sql @@ -1,7 +1,7 @@ --- +goose Up +-- +up CREATE INDEX orders_symbol ON orders (exchange, symbol); CREATE UNIQUE INDEX orders_order_id ON orders (order_id, exchange); --- +goose Down +-- +down DROP INDEX orders_symbol ON orders; DROP INDEX orders_order_id ON orders; diff --git a/migrations/20201106114742_klines.sql b/migrations/20201106114742_klines.sql index 04c3a326f..ab1cfd749 100644 --- a/migrations/20201106114742_klines.sql +++ b/migrations/20201106114742_klines.sql @@ -1,4 +1,4 @@ --- +goose Up +-- +up CREATE TABLE `klines` ( `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, @@ -18,14 +18,14 @@ CREATE TABLE `klines` PRIMARY KEY (`gid`) -) ENGINE = InnoDB; +); CREATE INDEX `klines_end_time_symbol_interval` ON klines (`end_time`, `symbol`, `interval`); CREATE TABLE `okex_klines` LIKE `klines`; CREATE TABLE `binance_klines` LIKE `klines`; CREATE TABLE `max_klines` LIKE `klines`; --- +goose Down +-- +down DROP INDEX `klines_end_time_symbol_interval` ON `klines`; DROP TABLE `binance_klines`; DROP TABLE `okex_klines`; diff --git a/migrations/20201211175751_fix_symbol_length.sql b/migrations/20201211175751_fix_symbol_length.sql index 23a05d480..e0965ee42 100644 --- a/migrations/20201211175751_fix_symbol_length.sql +++ b/migrations/20201211175751_fix_symbol_length.sql @@ -1,7 +1,7 @@ --- +goose Up +-- +up ALTER TABLE trades MODIFY COLUMN symbol VARCHAR(9); ALTER TABLE orders MODIFY COLUMN symbol VARCHAR(9); --- +goose Down +-- +down ALTER TABLE trades MODIFY COLUMN symbol VARCHAR(8); ALTER TABLE orders MODIFY COLUMN symbol VARCHAR(8); diff --git a/pkg/migrations/20200721225616_trades.go b/pkg/migrations/20200721225616_trades.go index a3bcbb0c3..12f449bbd 100644 --- a/pkg/migrations/20200721225616_trades.go +++ b/pkg/migrations/20200721225616_trades.go @@ -1,7 +1,6 @@ package migrations import ( - "database/sql" "context" "github.com/c9s/rockhopper" @@ -11,10 +10,10 @@ func init() { rockhopper.AddMigration(upTrades, downTrades) } -func upTrades(ctx context.Context, tx *sql.Tx) (err error) { +func upTrades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is applied. - _, err = tx.ExecContext(ctx, "CREATE TABLE `trades` (\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `id` BIGINT UNSIGNED,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(8) NOT NULL,\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `fee` DECIMAL(16, 8) UNSIGNED 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 PRIMARY KEY (`gid`),\n UNIQUE KEY `id` (`id`)\n) ENGINE=InnoDB;") + _, err = tx.ExecContext(ctx, "CREATE TABLE `trades`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `id` BIGINT UNSIGNED,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(8) NOT NULL,\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `fee` DECIMAL(16, 8) UNSIGNED 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 PRIMARY KEY (`gid`),\n UNIQUE KEY `id` (`id`)\n);") if err != nil { return err } @@ -22,7 +21,7 @@ func upTrades(ctx context.Context, tx *sql.Tx) (err error) { return err } -func downTrades(ctx context.Context, tx *sql.Tx) (err error) { +func downTrades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is rolled back. _, err = tx.ExecContext(ctx, "DROP TABLE `trades`;") diff --git a/pkg/migrations/20200819054742_trade_index.go b/pkg/migrations/20200819054742_trade_index.go index 18181311f..59c7b89ef 100644 --- a/pkg/migrations/20200819054742_trade_index.go +++ b/pkg/migrations/20200819054742_trade_index.go @@ -1,7 +1,6 @@ package migrations import ( - "database/sql" "context" "github.com/c9s/rockhopper" @@ -11,7 +10,7 @@ func init() { rockhopper.AddMigration(upTradeIndex, downTradeIndex) } -func upTradeIndex(ctx context.Context, tx *sql.Tx) (err error) { +func upTradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is applied. _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades(symbol);") @@ -32,7 +31,7 @@ func upTradeIndex(ctx context.Context, tx *sql.Tx) (err error) { return err } -func downTradeIndex(ctx context.Context, tx *sql.Tx) (err error) { +func downTradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is rolled back. _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol ON trades;") diff --git a/pkg/migrations/20201102222546_orders.go b/pkg/migrations/20201102222546_orders.go index 314887916..04af54150 100644 --- a/pkg/migrations/20201102222546_orders.go +++ b/pkg/migrations/20201102222546_orders.go @@ -1,7 +1,6 @@ package migrations import ( - "database/sql" "context" "github.com/c9s/rockhopper" @@ -11,10 +10,10 @@ func init() { rockhopper.AddMigration(upOrders, downOrders) } -func upOrders(ctx context.Context, tx *sql.Tx) (err error) { +func upOrders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is applied. - _, err = tx.ExecContext(ctx, "CREATE TABLE `orders`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- order_id is the order id returned from the exchange\n `order_id` BIGINT UNSIGNED NOT NULL,\n `client_order_id` VARCHAR(42) NOT NULL DEFAULT '',\n `order_type` VARCHAR(16) NOT NULL,\n `symbol` VARCHAR(8) NOT NULL,\n `status` VARCHAR(12) NOT NULL,\n `time_in_force` VARCHAR(4) NOT NULL,\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `stop_price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `executed_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `is_working` BOOL NOT NULL DEFAULT FALSE,\n `created_at` DATETIME(3) NOT NULL,\n `updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),\n PRIMARY KEY (`gid`)\n) ENGINE = InnoDB;") + _, err = tx.ExecContext(ctx, "CREATE TABLE `orders`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- order_id is the order id returned from the exchange\n `order_id` BIGINT UNSIGNED NOT NULL,\n `client_order_id` VARCHAR(42) NOT NULL DEFAULT '',\n `order_type` VARCHAR(16) NOT NULL,\n `symbol` VARCHAR(8) NOT NULL,\n `status` VARCHAR(12) NOT NULL,\n `time_in_force` VARCHAR(4) NOT NULL,\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `stop_price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `executed_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `is_working` BOOL NOT NULL DEFAULT FALSE,\n `created_at` DATETIME(3) NOT NULL,\n `updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),\n PRIMARY KEY (`gid`)\n);") if err != nil { return err } @@ -22,7 +21,7 @@ func upOrders(ctx context.Context, tx *sql.Tx) (err error) { return err } -func downOrders(ctx context.Context, tx *sql.Tx) (err error) { +func downOrders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is rolled back. _, err = tx.ExecContext(ctx, "DROP TABLE `orders`;") diff --git a/pkg/migrations/20201103173342_trades_add_order_id.go b/pkg/migrations/20201103173342_trades_add_order_id.go index d5626d629..596624746 100644 --- a/pkg/migrations/20201103173342_trades_add_order_id.go +++ b/pkg/migrations/20201103173342_trades_add_order_id.go @@ -1,7 +1,6 @@ package migrations import ( - "database/sql" "context" "github.com/c9s/rockhopper" @@ -11,7 +10,7 @@ func init() { rockhopper.AddMigration(upTradesAddOrderId, downTradesAddOrderId) } -func upTradesAddOrderId(ctx context.Context, tx *sql.Tx) (err error) { +func upTradesAddOrderId(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is applied. _, err = tx.ExecContext(ctx, "ALTER TABLE `trades`\n ADD COLUMN `order_id` BIGINT UNSIGNED NOT NULL;") @@ -22,7 +21,7 @@ func upTradesAddOrderId(ctx context.Context, tx *sql.Tx) (err error) { return err } -func downTradesAddOrderId(ctx context.Context, tx *sql.Tx) (err error) { +func downTradesAddOrderId(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`\n DROP COLUMN `order_id`;") diff --git a/pkg/migrations/20201105092857_trades_index_fix.go b/pkg/migrations/20201105092857_trades_index_fix.go index 45db95679..72b90f321 100644 --- a/pkg/migrations/20201105092857_trades_index_fix.go +++ b/pkg/migrations/20201105092857_trades_index_fix.go @@ -1,7 +1,6 @@ package migrations import ( - "database/sql" "context" "github.com/c9s/rockhopper" @@ -11,7 +10,7 @@ func init() { rockhopper.AddMigration(upTradesIndexFix, downTradesIndexFix) } -func upTradesIndexFix(ctx context.Context, tx *sql.Tx) (err error) { +func upTradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is applied. _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol ON trades;") @@ -47,7 +46,7 @@ func upTradesIndexFix(ctx context.Context, tx *sql.Tx) (err error) { return err } -func downTradesIndexFix(ctx context.Context, tx *sql.Tx) (err error) { +func downTradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is rolled back. _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol ON trades;") diff --git a/pkg/migrations/20201105093056_orders_add_index.go b/pkg/migrations/20201105093056_orders_add_index.go index e6766a831..9d1251169 100644 --- a/pkg/migrations/20201105093056_orders_add_index.go +++ b/pkg/migrations/20201105093056_orders_add_index.go @@ -1,7 +1,6 @@ package migrations import ( - "database/sql" "context" "github.com/c9s/rockhopper" @@ -11,7 +10,7 @@ func init() { rockhopper.AddMigration(upOrdersAddIndex, downOrdersAddIndex) } -func upOrdersAddIndex(ctx context.Context, tx *sql.Tx) (err error) { +func upOrdersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is applied. _, err = tx.ExecContext(ctx, "CREATE INDEX orders_symbol ON orders (exchange, symbol);") @@ -27,7 +26,7 @@ func upOrdersAddIndex(ctx context.Context, tx *sql.Tx) (err error) { return err } -func downOrdersAddIndex(ctx context.Context, tx *sql.Tx) (err error) { +func downOrdersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is rolled back. _, err = tx.ExecContext(ctx, "DROP INDEX orders_symbol ON orders;") diff --git a/pkg/migrations/20201106114742_klines.go b/pkg/migrations/20201106114742_klines.go index e272b6477..bbb4ca9ac 100644 --- a/pkg/migrations/20201106114742_klines.go +++ b/pkg/migrations/20201106114742_klines.go @@ -1,7 +1,6 @@ package migrations import ( - "database/sql" "context" "github.com/c9s/rockhopper" @@ -11,10 +10,10 @@ func init() { rockhopper.AddMigration(upKlines, downKlines) } -func upKlines(ctx context.Context, tx *sql.Tx) (err error) { +func upKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is applied. - _, err = tx.ExecContext(ctx, "CREATE TABLE `klines`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(10) NOT NULL,\n `start_time` DATETIME(3) NOT NULL,\n `end_time` DATETIME(3) NOT NULL,\n `interval` VARCHAR(3) NOT NULL,\n `symbol` VARCHAR(7) NOT NULL,\n `open` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `high` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `low` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `close` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `closed` BOOL NOT NULL DEFAULT TRUE,\n `last_trade_id` INT UNSIGNED NOT NULL DEFAULT 0,\n `num_trades` INT UNSIGNED NOT NULL DEFAULT 0,\n PRIMARY KEY (`gid`)\n) ENGINE = InnoDB;") + _, err = tx.ExecContext(ctx, "CREATE TABLE `klines`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(10) NOT NULL,\n `start_time` DATETIME(3) NOT NULL,\n `end_time` DATETIME(3) NOT NULL,\n `interval` VARCHAR(3) NOT NULL,\n `symbol` VARCHAR(7) NOT NULL,\n `open` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `high` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `low` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `close` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `closed` BOOL NOT NULL DEFAULT TRUE,\n `last_trade_id` INT UNSIGNED NOT NULL DEFAULT 0,\n `num_trades` INT UNSIGNED NOT NULL DEFAULT 0,\n PRIMARY KEY (`gid`)\n);") if err != nil { return err } @@ -42,7 +41,7 @@ func upKlines(ctx context.Context, tx *sql.Tx) (err error) { return err } -func downKlines(ctx context.Context, tx *sql.Tx) (err error) { +func downKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is rolled back. _, err = tx.ExecContext(ctx, "DROP INDEX `klines_end_time_symbol_interval` ON `klines`;") diff --git a/pkg/migrations/20201211175751_fix_symbol_length.go b/pkg/migrations/20201211175751_fix_symbol_length.go index a5062ffb4..6349d3763 100644 --- a/pkg/migrations/20201211175751_fix_symbol_length.go +++ b/pkg/migrations/20201211175751_fix_symbol_length.go @@ -1,7 +1,6 @@ package migrations import ( - "database/sql" "context" "github.com/c9s/rockhopper" @@ -11,7 +10,7 @@ func init() { rockhopper.AddMigration(upFixSymbolLength, downFixSymbolLength) } -func upFixSymbolLength(ctx context.Context, tx *sql.Tx) (err error) { +func upFixSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { // This code is executed when the migration is applied. _, err = tx.ExecContext(ctx, "ALTER TABLE trades MODIFY COLUMN symbol VARCHAR(9);") @@ -27,7 +26,7 @@ func upFixSymbolLength(ctx context.Context, tx *sql.Tx) (err error) { return err } -func downFixSymbolLength(ctx context.Context, tx *sql.Tx) (err error) { +func downFixSymbolLength(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 MODIFY COLUMN symbol VARCHAR(8);")