mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
fix built-in migrations
This commit is contained in:
parent
d04e1e7816
commit
293d889276
5
Makefile
5
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
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
6
go.sum
6
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=
|
||||
|
|
|
@ -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`;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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`;
|
||||
|
|
|
@ -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`;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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`;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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`;")
|
||||
|
|
|
@ -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;")
|
||||
|
|
|
@ -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`;")
|
||||
|
|
|
@ -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`;")
|
||||
|
|
|
@ -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;")
|
||||
|
|
|
@ -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;")
|
||||
|
|
|
@ -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`;")
|
||||
|
|
|
@ -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);")
|
||||
|
|
Loading…
Reference in New Issue
Block a user