add migration package name

This commit is contained in:
c9s 2024-01-18 21:36:04 +08:00
parent 9a1b50dee9
commit 3e233627be
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
86 changed files with 438 additions and 1056 deletions

View File

@ -1,34 +0,0 @@
package mysql
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upFixSymbolLength, downFixSymbolLength)
}
func upFixSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}
func downFixSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}

View File

@ -1,34 +0,0 @@
package mysql
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upFixUniqueIndex, downFixUniqueIndex)
}
func upFixUniqueIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}
func downFixUniqueIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}

View File

@ -1,34 +0,0 @@
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, "SELECT 1;")
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, "SELECT 1;")
if err != nil {
return err
}
return err
}

View File

@ -1,54 +0,0 @@
package mysql
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upUpdateTakerBuyBaseVolumn, downUpdateTakerBuyBaseVolumn)
}
func upUpdateTakerBuyBaseVolumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE binance_klines CHANGE taker_buy_base_volume taker_buy_base_volume decimal(32,8) NOT NULL;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE max_klines CHANGE taker_buy_base_volume taker_buy_base_volume decimal(32,8) NOT NULL;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE okex_klines CHANGE taker_buy_base_volume taker_buy_base_volume decimal(32,8) NOT NULL;")
if err != nil {
return err
}
return err
}
func downUpdateTakerBuyBaseVolumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE binance_klines CHANGE taker_buy_base_volume taker_buy_base_volume decimal(16,8) NOT NULL;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE max_klines CHANGE taker_buy_base_volume taker_buy_base_volume decimal(16,8) NOT NULL;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE okex_klines CHANGE taker_buy_base_volume taker_buy_base_volume decimal(16,8) NOT NULL;")
if err != nil {
return err
}
return err
}

View File

@ -1,64 +0,0 @@
package mysql
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upAddFuturesKlines, downAddFuturesKlines)
}
func upAddFuturesKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `binance_futures_klines` LIKE `binance_klines`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "CREATE TABLE `bybit_futures_klines` LIKE `bybit_klines`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "CREATE TABLE `okex_futures_klines` LIKE `okex_klines`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "CREATE TABLE `max_futures_klines` LIKE `max_klines`;")
if err != nil {
return err
}
return err
}
func downAddFuturesKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `binance_futures_klines`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `bybit_futures_klines`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `okex_futures_klines`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `max_futures_klines`;")
if err != nil {
return err
}
return err
}

View File

@ -3,62 +3,52 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTrades, downTrades) AddMigration("main", up_main_trades, down_main_trades)
} }
func upTrades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_trades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `trades`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `id` BIGINT UNSIGNED,\n `order_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(20) 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(10) 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 `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `strategy` VARCHAR(32) NULL,\n `pnl` DECIMAL NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `id` (`exchange`, `symbol`, `side`, `id`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `trades`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `id` BIGINT UNSIGNED,\n `order_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(20) 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(10) 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 `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `strategy` VARCHAR(32) NULL,\n `pnl` DECIMAL NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `id` (`exchange`, `symbol`, `side`, `id`)\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downTrades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_trades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `trades`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `trades`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol ON trades;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol ON trades;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol_fee_currency ON trades;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol_fee_currency ON trades;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at_symbol ON trades;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at_symbol ON trades;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddMarginColumns, downAddMarginColumns) AddMigration("main", up_main_tradeIndex, down_main_tradeIndex)
} }
func upAddMarginColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_tradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddMarginColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_tradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,52 +3,44 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upOrders, downOrders) AddMigration("main", up_main_orders, down_main_orders)
} }
func upOrders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_orders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // 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(122) NOT NULL DEFAULT '',\n `order_type` VARCHAR(16) NOT NULL,\n `symbol` VARCHAR(20) 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 `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n PRIMARY KEY (`gid`)\n);") _, 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(122) NOT NULL DEFAULT '',\n `order_type` VARCHAR(16) NOT NULL,\n `symbol` VARCHAR(20) 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 `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n PRIMARY KEY (`gid`)\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX orders_symbol ON orders (exchange, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX orders_symbol ON orders (exchange, symbol);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX orders_order_id ON orders (order_id, exchange);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX orders_order_id ON orders (order_id, exchange);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downOrders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_orders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX orders_symbol ON orders;") _, err = tx.ExecContext(ctx, "DROP INDEX orders_symbol ON orders;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX orders_order_id ON orders;") _, err = tx.ExecContext(ctx, "DROP INDEX orders_order_id ON orders;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE `orders`;") _, err = tx.ExecContext(ctx, "DROP TABLE `orders`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -0,0 +1,30 @@
package mysql
import (
"context"
"github.com/c9s/rockhopper/v2"
)
func init() {
AddMigration("main", up_main_tradesAddOrderId, down_main_tradesAddOrderId)
}
func up_main_tradesAddOrderId(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}
func down_main_tradesAddOrderId(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}

View File

@ -1,34 +1,30 @@
package sqlite3 package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixOrderStatusLength, downFixOrderStatusLength) AddMigration("main", up_main_tradesIndexFix, down_main_tradesIndexFix)
} }
func upFixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_tradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_tradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTradeIndex, downTradeIndex) AddMigration("main", up_main_ordersAddIndex, down_main_ordersAddIndex)
} }
func upTradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_ordersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downTradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_ordersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,72 +3,60 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upKlines, downKlines) AddMigration("main", up_main_klines, down_main_klines)
} }
func upKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_klines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // 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(20) NOT NULL,\n `open` DECIMAL(20, 8) UNSIGNED NOT NULL,\n `high` DECIMAL(20, 8) UNSIGNED NOT NULL,\n `low` DECIMAL(20, 8) UNSIGNED NOT NULL,\n `close` DECIMAL(20, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(20, 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);") _, 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(20) NOT NULL,\n `open` DECIMAL(20, 8) UNSIGNED NOT NULL,\n `high` DECIMAL(20, 8) UNSIGNED NOT NULL,\n `low` DECIMAL(20, 8) UNSIGNED NOT NULL,\n `close` DECIMAL(20, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(20, 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 { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX `klines_end_time_symbol_interval` ON klines (`end_time`, `symbol`, `interval`);") _, err = tx.ExecContext(ctx, "CREATE INDEX `klines_end_time_symbol_interval` ON klines (`end_time`, `symbol`, `interval`);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE TABLE `okex_klines` LIKE `klines`;") _, err = tx.ExecContext(ctx, "CREATE TABLE `okex_klines` LIKE `klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE TABLE `binance_klines` LIKE `klines`;") _, err = tx.ExecContext(ctx, "CREATE TABLE `binance_klines` LIKE `klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE TABLE `max_klines` LIKE `klines`;") _, err = tx.ExecContext(ctx, "CREATE TABLE `max_klines` LIKE `klines`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_klines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX `klines_end_time_symbol_interval` ON `klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `klines_end_time_symbol_interval` ON `klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE `binance_klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE `binance_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE `okex_klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE `okex_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE `max_klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE `max_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE `klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE `klines`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upUpdateFeeCurrencyLength, downUpdateFeeCurrencyLength) AddMigration("main", up_main_fixSymbolLength, down_main_fixSymbolLength)
} }
func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upOrdersAddIndex, downOrdersAddIndex) AddMigration("main", up_main_fixUniqueIndex, down_main_fixUniqueIndex)
} }
func upOrdersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixUniqueIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downOrdersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixUniqueIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -0,0 +1,30 @@
package mysql
import (
"context"
"github.com/c9s/rockhopper/v2"
)
func init() {
AddMigration("main", up_main_addMarginColumns, down_main_addMarginColumns)
}
func up_main_addMarginColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}
func down_main_addMarginColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTradePriceQuantityIndex, downTradePriceQuantityIndex) AddMigration("main", up_main_tradePriceQuantityIndex, down_main_tradePriceQuantityIndex)
} }
func upTradePriceQuantityIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_tradePriceQuantityIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_price_quantity ON trades (order_id,price,quantity);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_price_quantity ON trades (order_id,price,quantity);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downTradePriceQuantityIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_tradePriceQuantityIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX trades_price_quantity ON trades") _, err = tx.ExecContext(ctx, "DROP INDEX trades_price_quantity ON trades")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTradesAddOrderId, downTradesAddOrderId) AddMigration("main", up_main_addPnlColumn, down_main_addPnlColumn)
} }
func upTradesAddOrderId(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addPnlColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downTradesAddOrderId(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addPnlColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddRewardsTable, downAddRewardsTable) AddMigration("main", up_main_addRewardsTable, down_main_addRewardsTable)
} }
func upAddRewardsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addRewardsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `rewards`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n -- for exchange\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- reward record id\n `uuid` VARCHAR(32) NOT NULL,\n `reward_type` VARCHAR(24) NOT NULL DEFAULT '',\n -- currency symbol, BTC, MAX, USDT ... etc\n `currency` VARCHAR(5) NOT NULL,\n -- the quantity of the rewards\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `state` VARCHAR(5) NOT NULL,\n `created_at` DATETIME NOT NULL,\n `spent` BOOLEAN NOT NULL DEFAULT FALSE,\n `note` TEXT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `uuid` (`exchange`, `uuid`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `rewards`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n -- for exchange\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- reward record id\n `uuid` VARCHAR(32) NOT NULL,\n `reward_type` VARCHAR(24) NOT NULL DEFAULT '',\n -- currency symbol, BTC, MAX, USDT ... etc\n `currency` VARCHAR(5) NOT NULL,\n -- the quantity of the rewards\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `state` VARCHAR(5) NOT NULL,\n `created_at` DATETIME NOT NULL,\n `spent` BOOLEAN NOT NULL DEFAULT FALSE,\n `note` TEXT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `uuid` (`exchange`, `uuid`)\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddRewardsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addRewardsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `rewards`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `rewards`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddWithdrawsTable, downAddWithdrawsTable) AddMigration("main", up_main_addWithdrawsTable, down_main_addWithdrawsTable)
} }
func upAddWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `withdraws`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(128) NOT NULL,\n `network` VARCHAR(32) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(256) NOT NULL,\n `txn_fee` DECIMAL(16, 8) NOT NULL DEFAULT 0,\n `txn_fee_currency` VARCHAR(32) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `txn_id` (`exchange`, `txn_id`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `withdraws`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(128) NOT NULL,\n `network` VARCHAR(32) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(256) NOT NULL,\n `txn_fee` DECIMAL(16, 8) NOT NULL DEFAULT 0,\n `txn_fee_currency` VARCHAR(32) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `txn_id` (`exchange`, `txn_id`)\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `withdraws`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `withdraws`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddDepositsTable, downAddDepositsTable) AddMigration("main", up_main_addDepositsTable, down_main_addDepositsTable)
} }
func upAddDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `deposits`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL,\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(128) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(256) NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `txn_id` (`exchange`, `txn_id`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `deposits`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL,\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(128) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(256) NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `txn_id` (`exchange`, `txn_id`)\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `deposits`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `deposits`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,62 +3,52 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upKlinesSymbolLength, downKlinesSymbolLength) AddMigration("main", up_main_klinesSymbolLength, down_main_klinesSymbolLength)
} }
func upKlinesSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_klinesSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downKlinesSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_klinesSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,62 +3,52 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upIncreaseSymbolLength, downIncreaseSymbolLength) AddMigration("main", up_main_increaseSymbolLength, down_main_increaseSymbolLength)
} }
func upIncreaseSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_increaseSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downIncreaseSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_increaseSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,62 +3,52 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upIncreaseDecimalLength, downIncreaseDecimalLength) AddMigration("main", up_main_increaseDecimalLength, down_main_increaseDecimalLength)
} }
func upIncreaseDecimalLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_increaseDecimalLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';") _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';") _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';") _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';") _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downIncreaseDecimalLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_increaseDecimalLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';") _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';") _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';") _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';") _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,57 +3,48 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddKlineTakerBuyColumns, downAddKlineTakerBuyColumns) AddMigration("main", up_main_addKlineTakerBuyColumns, down_main_addKlineTakerBuyColumns)
} }
func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;") _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;") _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;") _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;") _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n DROP COLUMN `quote_volume`,\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n DROP COLUMN `quote_volume`,\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n DROP COLUMN `quote_volume`,\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n DROP COLUMN `quote_volume`,\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n DROP COLUMN `quote_volume`,\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n DROP COLUMN `quote_volume`,\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,42 +3,36 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddIsFuturesColumn, downAddIsFuturesColumn) AddMigration("main", up_main_addIsFuturesColumn, down_main_addIsFuturesColumn)
} }
func upAddIsFuturesColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addIsFuturesColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;") _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddIsFuturesColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addIsFuturesColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` DROP COLUMN `is_futures`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` DROP COLUMN `is_futures`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders` DROP COLUMN `is_futures`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` DROP COLUMN `is_futures`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,37 +3,32 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddFtxKline, downAddFtxKline) AddMigration("main", up_main_addFtxKline, down_main_addFtxKline)
} }
func upAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "create table if not exists ftx_klines\n(\n gid bigint unsigned auto_increment\n primary key,\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(20) not null,\n open decimal(20,8) unsigned not null,\n high decimal(20,8) unsigned not null,\n low decimal(20,8) unsigned not null,\n close decimal(20,8) unsigned default 0.00000000 not null,\n volume decimal(20,8) unsigned default 0.00000000 not null,\n closed tinyint(1) default 1 not null,\n last_trade_id int unsigned default '0' not null,\n num_trades int unsigned default '0' not null,\n quote_volume decimal(32,4) default 0.0000 not null,\n taker_buy_base_volume decimal(32,8) not null,\n taker_buy_quote_volume decimal(32,4) default 0.0000 not null\n );") _, err = tx.ExecContext(ctx, "create table if not exists ftx_klines\n(\n gid bigint unsigned auto_increment\n primary key,\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(20) not null,\n open decimal(20,8) unsigned not null,\n high decimal(20,8) unsigned not null,\n low decimal(20,8) unsigned not null,\n close decimal(20,8) unsigned default 0.00000000 not null,\n volume decimal(20,8) unsigned default 0.00000000 not null,\n closed tinyint(1) default 1 not null,\n last_trade_id int unsigned default '0' not null,\n num_trades int unsigned default '0' not null,\n quote_volume decimal(32,4) default 0.0000 not null,\n taker_buy_base_volume decimal(32,8) not null,\n taker_buy_quote_volume decimal(32,4) default 0.0000 not null\n );")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "create index klines_end_time_symbol_interval\n on ftx_klines (end_time, symbol, `interval`);") _, err = tx.ExecContext(ctx, "create index klines_end_time_symbol_interval\n on ftx_klines (end_time, symbol, `interval`);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "drop table ftx_klines;") _, err = tx.ExecContext(ctx, "drop table ftx_klines;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,37 +3,32 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddNavHistoryDetails, downAddNavHistoryDetails) AddMigration("main", up_main_addNavHistoryDetails, down_main_addNavHistoryDetails)
} }
func upAddNavHistoryDetails(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addNavHistoryDetails(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE nav_history_details\n(\n gid bigint unsigned auto_increment PRIMARY KEY,\n exchange VARCHAR(30) NOT NULL,\n subaccount VARCHAR(30) NOT NULL,\n time DATETIME(3) NOT NULL,\n currency VARCHAR(12) NOT NULL,\n balance_in_usd DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n balance_in_btc DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n balance DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n available DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n locked DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE nav_history_details\n(\n gid bigint unsigned auto_increment PRIMARY KEY,\n exchange VARCHAR(30) NOT NULL,\n subaccount VARCHAR(30) NOT NULL,\n time DATETIME(3) NOT NULL,\n currency VARCHAR(12) NOT NULL,\n balance_in_usd DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n balance_in_btc DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n balance DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n available DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n locked DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX idx_nav_history_details\n on nav_history_details (time, currency, exchange);") _, err = tx.ExecContext(ctx, "CREATE INDEX idx_nav_history_details\n on nav_history_details (time, currency, exchange);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddNavHistoryDetails(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addNavHistoryDetails(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE nav_history_details;") _, err = tx.ExecContext(ctx, "DROP TABLE nav_history_details;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTradesIndexFix, downTradesIndexFix) AddMigration("main", up_main_updateFeeCurrencyLength, down_main_updateFeeCurrencyLength)
} }
func upTradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_updateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downTradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_updateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddKucoinKlines, downAddKucoinKlines) AddMigration("main", up_main_addKucoinKlines, down_main_addKucoinKlines)
} }
func upAddKucoinKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addKucoinKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `kucoin_klines` LIKE `binance_klines`;") _, err = tx.ExecContext(ctx, "CREATE TABLE `kucoin_klines` LIKE `binance_klines`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddKucoinKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addKucoinKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE `kucoin_klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE `kucoin_klines`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddProfitTable, downAddProfitTable) AddMigration("main", up_main_addProfitTable, down_main_addProfitTable)
} }
func upAddProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `profits`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `strategy` VARCHAR(32) NOT NULL,\n `strategy_instance_id` VARCHAR(64) NOT NULL,\n `symbol` VARCHAR(8) NOT NULL,\n -- average_cost is the position average cost\n `average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- profit is the pnl (profit and loss)\n `profit` DECIMAL(16, 8) NOT NULL,\n -- net_profit is the pnl (profit and loss)\n `net_profit` DECIMAL(16, 8) NOT NULL,\n -- profit_margin is the pnl (profit and loss)\n `profit_margin` DECIMAL(16, 8) NOT NULL,\n -- net_profit_margin is the pnl (profit and loss)\n `net_profit_margin` DECIMAL(16, 8) NOT NULL,\n `quote_currency` VARCHAR(10) NOT NULL,\n `base_currency` VARCHAR(10) NOT NULL,\n -- -------------------------------------------------------\n -- embedded trade data --\n -- -------------------------------------------------------\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `is_futures` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `trade_id` BIGINT UNSIGNED NOT NULL,\n -- side is the side of the trade that makes profit\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n -- price is the price of the trade that makes profit\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- quantity is the quantity of the trade that makes profit\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- quote_quantity is the quote quantity of the trade that makes profit\n `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `traded_at` DATETIME(3) NOT NULL,\n -- fee\n `fee_in_usd` DECIMAL(16, 8),\n `fee` DECIMAL(16, 8) NOT NULL,\n `fee_currency` VARCHAR(10) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `trade_id` (`trade_id`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `profits`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `strategy` VARCHAR(32) NOT NULL,\n `strategy_instance_id` VARCHAR(64) NOT NULL,\n `symbol` VARCHAR(8) NOT NULL,\n -- average_cost is the position average cost\n `average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- profit is the pnl (profit and loss)\n `profit` DECIMAL(16, 8) NOT NULL,\n -- net_profit is the pnl (profit and loss)\n `net_profit` DECIMAL(16, 8) NOT NULL,\n -- profit_margin is the pnl (profit and loss)\n `profit_margin` DECIMAL(16, 8) NOT NULL,\n -- net_profit_margin is the pnl (profit and loss)\n `net_profit_margin` DECIMAL(16, 8) NOT NULL,\n `quote_currency` VARCHAR(10) NOT NULL,\n `base_currency` VARCHAR(10) NOT NULL,\n -- -------------------------------------------------------\n -- embedded trade data --\n -- -------------------------------------------------------\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `is_futures` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `trade_id` BIGINT UNSIGNED NOT NULL,\n -- side is the side of the trade that makes profit\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n -- price is the price of the trade that makes profit\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- quantity is the quantity of the trade that makes profit\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- quote_quantity is the quote quantity of the trade that makes profit\n `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `traded_at` DATETIME(3) NOT NULL,\n -- fee\n `fee_in_usd` DECIMAL(16, 8),\n `fee` DECIMAL(16, 8) NOT NULL,\n `fee_currency` VARCHAR(10) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `trade_id` (`trade_id`)\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `profits`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `profits`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddPositions, downAddPositions) AddMigration("main", up_main_addPositions, down_main_addPositions)
} }
func upAddPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `positions`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\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) UNSIGNED 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 UNSIGNED NOT NULL, -- the trade id in the exchange\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, -- millisecond timestamp\n PRIMARY KEY (`gid`),\n UNIQUE KEY `trade_id` (`trade_id`, `side`, `exchange`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `positions`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\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) UNSIGNED 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 UNSIGNED NOT NULL, -- the trade id in the exchange\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, -- millisecond timestamp\n PRIMARY KEY (`gid`),\n UNIQUE KEY `trade_id` (`trade_id`, `side`, `exchange`)\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `positions`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `positions`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,82 +3,68 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixTradeIndexes, downFixTradeIndexes) AddMigration("main", up_main_fixTradeIndexes, down_main_fixTradeIndexes)
} }
func upFixTradeIndexes(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixTradeIndexes(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol ON trades;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol ON trades;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol_fee_currency ON trades;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol_fee_currency ON trades;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at_symbol ON trades;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at_symbol ON trades;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at ON trades (traded_at, symbol, exchange, id, fee_currency, fee);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at ON trades (traded_at, symbol, exchange, id, fee_currency, fee);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_id_traded_at ON trades (id, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_id_traded_at ON trades (id, traded_at);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_order_id_traded_at ON trades (order_id, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_order_id_traded_at ON trades (order_id, traded_at);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixTradeIndexes(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixTradeIndexes(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at ON trades;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at ON trades;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX trades_id_traded_at ON trades;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_id_traded_at ON trades;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX trades_order_id_traded_at ON trades;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_order_id_traded_at ON trades;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,42 +3,36 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixFeeColumn, downFixFeeColumn) AddMigration("main", up_main_fixFeeColumn, down_main_fixFeeColumn)
} }
func upFixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE trades\n CHANGE fee fee DECIMAL(16, 8) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE trades\n CHANGE fee fee DECIMAL(16, 8) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE fee fee DECIMAL(16, 8) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE fee fee DECIMAL(16, 8) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE fee_in_usd fee_in_usd DECIMAL(16, 8);") _, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE fee_in_usd fee_in_usd DECIMAL(16, 8);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddMarginInfoToNav, downAddMarginInfoToNav) AddMigration("main", up_main_addMarginInfoToNav, down_main_addMarginInfoToNav)
} }
func upAddMarginInfoToNav(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addMarginInfoToNav(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n ADD COLUMN `session` VARCHAR(30) NOT NULL,\n ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n ADD COLUMN `isolated_symbol` VARCHAR(30) NOT NULL DEFAULT '',\n ADD COLUMN `net_asset` DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n ADD COLUMN `borrowed` DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n ADD COLUMN `price_in_usd` DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL\n;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n ADD COLUMN `session` VARCHAR(30) NOT NULL,\n ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n ADD COLUMN `isolated_symbol` VARCHAR(30) NOT NULL DEFAULT '',\n ADD COLUMN `net_asset` DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n ADD COLUMN `borrowed` DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,\n ADD COLUMN `price_in_usd` DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL\n;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddMarginInfoToNav(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addMarginInfoToNav(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n DROP COLUMN `session`,\n DROP COLUMN `net_asset`,\n DROP COLUMN `borrowed`,\n DROP COLUMN `price_in_usd`,\n DROP COLUMN `is_margin`,\n DROP COLUMN `is_isolated`,\n DROP COLUMN `isolated_symbol`\n;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n DROP COLUMN `session`,\n DROP COLUMN `net_asset`,\n DROP COLUMN `borrowed`,\n DROP COLUMN `price_in_usd`,\n DROP COLUMN `is_margin`,\n DROP COLUMN `is_isolated`,\n DROP COLUMN `isolated_symbol`\n;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,37 +3,32 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixNetAssetColumn, downFixNetAssetColumn) AddMigration("main", up_main_fixNetAssetColumn, down_main_fixNetAssetColumn)
} }
func upFixNetAssetColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixNetAssetColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n MODIFY COLUMN `net_asset` DECIMAL(32, 8) DEFAULT 0.00000000 NOT NULL,\n CHANGE COLUMN `balance_in_usd` `net_asset_in_usd` DECIMAL(32, 2) DEFAULT 0.00000000 NOT NULL,\n CHANGE COLUMN `balance_in_btc` `net_asset_in_btc` DECIMAL(32, 20) DEFAULT 0.00000000 NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n MODIFY COLUMN `net_asset` DECIMAL(32, 8) DEFAULT 0.00000000 NOT NULL,\n CHANGE COLUMN `balance_in_usd` `net_asset_in_usd` DECIMAL(32, 2) DEFAULT 0.00000000 NOT NULL,\n CHANGE COLUMN `balance_in_btc` `net_asset_in_btc` DECIMAL(32, 20) DEFAULT 0.00000000 NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n ADD COLUMN `interest` DECIMAL(32, 20) UNSIGNED DEFAULT 0.00000000 NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n ADD COLUMN `interest` DECIMAL(32, 20) UNSIGNED DEFAULT 0.00000000 NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixNetAssetColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixNetAssetColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n DROP COLUMN `interest`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n DROP COLUMN `interest`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixProfitSymbolLength, downFixProfitSymbolLength) AddMigration("main", up_main_fixProfitSymbolLength, down_main_fixProfitSymbolLength)
} }
func upFixProfitSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixProfitSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE symbol symbol VARCHAR(20) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE symbol symbol VARCHAR(20) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixProfitSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixProfitSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,72 +3,60 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upKlineUniqueIdx, downKlineUniqueIdx) AddMigration("main", up_main_klineUniqueIdx, down_main_klineUniqueIdx)
} }
func upKlineUniqueIdx(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_klineUniqueIdx(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_binance_unique\n ON binance_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_binance_unique\n ON binance_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_max_unique\n ON max_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_max_unique\n ON max_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_ftx_unique`\n ON ftx_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_ftx_unique`\n ON ftx_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_kucoin_unique`\n ON kucoin_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_kucoin_unique`\n ON kucoin_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_okex_unique`\n ON okex_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_okex_unique`\n ON okex_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downKlineUniqueIdx(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_klineUniqueIdx(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_ftx_unique` ON `ftx_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_ftx_unique` ON `ftx_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_max_unique` ON `max_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_max_unique` ON `max_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_binance_unique` ON `binance_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_binance_unique` ON `binance_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_kucoin_unique` ON `kucoin_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_kucoin_unique` ON `kucoin_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_okex_unique` ON `okex_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_okex_unique` ON `okex_klines`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upMarginLoans, downMarginLoans) AddMigration("main", up_main_marginLoans, down_main_marginLoans)
} }
func upMarginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_marginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_loans`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `transaction_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY (`transaction_id`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `margin_loans`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `transaction_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY (`transaction_id`)\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downMarginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_marginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_loans`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_loans`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upMarginRepays, downMarginRepays) AddMigration("main", up_main_marginRepays, down_main_marginRepays)
} }
func upMarginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_marginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_repays`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `transaction_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY (`transaction_id`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `margin_repays`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `transaction_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY (`transaction_id`)\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downMarginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_marginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_repays`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_repays`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upMarginInterests, downMarginInterests) AddMigration("main", up_main_marginInterests, down_main_marginInterests)
} }
func upMarginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_marginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_interests`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `principle` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `interest` DECIMAL(20, 16) UNSIGNED NOT NULL,\n `interest_rate` DECIMAL(20, 16) UNSIGNED NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `margin_interests`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `principle` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `interest` DECIMAL(20, 16) UNSIGNED NOT NULL,\n `interest_rate` DECIMAL(20, 16) UNSIGNED NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`)\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downMarginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_marginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_interests`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_interests`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upMarginLiquidations, downMarginLiquidations) AddMigration("main", up_main_marginLiquidations, down_main_marginLiquidations)
} }
func upMarginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_marginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_liquidations`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `order_id` BIGINT UNSIGNED NOT NULL,\n `is_isolated` BOOL NOT NULL DEFAULT false,\n `average_price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `executed_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `side` VARCHAR(5) NOT NULL DEFAULT '',\n `time_in_force` VARCHAR(5) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY (`order_id`, `exchange`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `margin_liquidations`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `order_id` BIGINT UNSIGNED NOT NULL,\n `is_isolated` BOOL NOT NULL DEFAULT false,\n `average_price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `executed_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `side` VARCHAR(5) NOT NULL DEFAULT '',\n `time_in_force` VARCHAR(5) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY (`order_id`, `exchange`)\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downMarginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_marginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_liquidations`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_liquidations`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddBybitKlines, downAddBybitKlines) AddMigration("main", up_main_addBybitKlines, down_main_addBybitKlines)
} }
func upAddBybitKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addBybitKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `bybit_klines` LIKE `binance_klines`;") _, err = tx.ExecContext(ctx, "CREATE TABLE `bybit_klines` LIKE `binance_klines`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddBybitKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addBybitKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE `bybit_klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE `bybit_klines`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package mysql
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixOrderStatusLength, downFixOrderStatusLength) AddMigration("main", up_main_fixOrderStatusLength, down_main_fixOrderStatusLength)
} }
func upFixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders`\n CHANGE `status` `status` varchar(20) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `orders`\n CHANGE `status` `status` varchar(20) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -6,22 +6,27 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
var registeredGoMigrations map[int64]*rockhopper.Migration type registryKey struct {
Package string
Version int64
}
func MergeMigrationsMap(ms map[int64]*rockhopper.Migration) { var registeredGoMigrations = map[registryKey]*rockhopper.Migration{}
func MergeMigrationsMap(ms map[registryKey]*rockhopper.Migration) {
for k, m := range ms { for k, m := range ms {
if _, ok := registeredGoMigrations[k]; !ok { if _, ok := registeredGoMigrations[k]; !ok {
registeredGoMigrations[k] = m registeredGoMigrations[k] = m
} else { } else {
log.Printf("the migration key %d is duplicated: %+v", k, m) log.Printf("the migration key %+v is duplicated: %+v", k, m)
} }
} }
} }
func GetMigrationsMap() map[int64]*rockhopper.Migration { func GetMigrationsMap() map[registryKey]*rockhopper.Migration {
return registeredGoMigrations return registeredGoMigrations
} }
@ -41,11 +46,14 @@ func Migrations() rockhopper.MigrationSlice {
} }
// AddMigration adds a migration with its runtime caller information // AddMigration adds a migration with its runtime caller information
func AddMigration(up, down rockhopper.TransactionHandler) { func AddMigration(packageName string, up, down rockhopper.TransactionHandler) {
pc, filename, _, _ := runtime.Caller(1) pc, filename, _, _ := runtime.Caller(1)
if packageName == "" {
funcName := runtime.FuncForPC(pc).Name() funcName := runtime.FuncForPC(pc).Name()
packageName := _parseFuncPackageName(funcName) packageName = _parseFuncPackageName(funcName)
}
AddNamedMigration(packageName, filename, up, down) AddNamedMigration(packageName, filename, up, down)
} }
@ -64,10 +72,13 @@ func _parseFuncPackageName(funcName string) string {
// AddNamedMigration adds a named migration to the registered go migration map // AddNamedMigration adds a named migration to the registered go migration map
func AddNamedMigration(packageName, filename string, up, down rockhopper.TransactionHandler) { func AddNamedMigration(packageName, filename string, up, down rockhopper.TransactionHandler) {
if registeredGoMigrations == nil { if registeredGoMigrations == nil {
registeredGoMigrations = make(map[int64]*rockhopper.Migration) registeredGoMigrations = make(map[registryKey]*rockhopper.Migration)
} }
v, _ := rockhopper.FileNumericComponent(filename) v, err := rockhopper.FileNumericComponent(filename)
if err != nil {
panic(fmt.Errorf("unable to parse numeric component from filename %s: %v", filename, err))
}
migration := &rockhopper.Migration{ migration := &rockhopper.Migration{
Package: packageName, Package: packageName,
@ -80,8 +91,10 @@ func AddNamedMigration(packageName, filename string, up, down rockhopper.Transac
UseTx: true, UseTx: true,
} }
if existing, ok := registeredGoMigrations[v]; ok { key := registryKey{Package: packageName, Version: v}
panic(fmt.Sprintf("failed to add migration %q: version conflicts with %q", filename, existing.Source)) if existing, ok := registeredGoMigrations[key]; ok {
panic(fmt.Sprintf("failed to add migration %q: version conflicts with key %+v: %+v", filename, key, existing))
} }
registeredGoMigrations[v] = migration
registeredGoMigrations[key] = migration
} }

View File

@ -3,7 +3,8 @@ package mysql
import ( import (
"testing" "testing"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -13,8 +14,8 @@ func TestGetMigrationsMap(t *testing.T) {
} }
func TestMergeMigrationsMap(t *testing.T) { func TestMergeMigrationsMap(t *testing.T) {
MergeMigrationsMap(map[int64]*rockhopper.Migration{ MergeMigrationsMap(map[registryKey]*rockhopper.Migration{
2: &rockhopper.Migration{}, registryKey{Version: 2}: &rockhopper.Migration{},
3: &rockhopper.Migration{}, registryKey{Version: 2}: &rockhopper.Migration{},
}) })
} }

View File

@ -1,34 +0,0 @@
package sqlite3
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upUpdateTakerBuyBaseVolumn, downUpdateTakerBuyBaseVolumn)
}
func upUpdateTakerBuyBaseVolumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "")
if err != nil {
return err
}
return err
}
func downUpdateTakerBuyBaseVolumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "")
if err != nil {
return err
}
return err
}

View File

@ -1,74 +0,0 @@
package sqlite3
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upAddFuturesKlines, downAddFuturesKlines)
}
func upAddFuturesKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `bybit_futures_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0,\n `quote_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0\n);")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "CREATE TABLE `okex_futures_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "CREATE TABLE `binance_futures_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "CREATE TABLE `max_futures_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "CREATE INDEX `bybit_futures_klines_end_time_symbol_interval` ON `bybit_futures_klines` (`end_time`, `symbol`, `interval`);\nCREATE INDEX `okex_futures_klines_end_time_symbol_interval` ON `okex_futures_klines` (`end_time`, `symbol`, `interval`);\nCREATE INDEX `binance_futures_klines_end_time_symbol_interval` ON `binance_futures_klines` (`end_time`, `symbol`, `interval`);\nCREATE INDEX `max_futures_klines_end_time_symbol_interval` ON `max_futures_klines` (`end_time`, `symbol`, `interval`);")
if err != nil {
return err
}
return err
}
func downAddFuturesKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `bybit_futures_klines_end_time_symbol_interval`;\nDROP INDEX IF EXISTS `okex_futures_klines_end_time_symbol_interval`;\nDROP INDEX IF EXISTS `binance_futures_klines_end_time_symbol_interval`;\nDROP INDEX IF EXISTS `max_futures_klines_end_time_symbol_interval`;\n")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `bybit_futures_klines`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `okex_futures_klines`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `binance_futures_klines`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `max_futures_klines`;")
if err != nil {
return err
}
return err
}

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTrades, downTrades) AddMigration("main", up_main_trades, down_main_trades)
} }
func upTrades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_trades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // 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);") _, 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 { if err != nil {
return err return err
} }
return err return err
} }
func downTrades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_trades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `trades`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `trades`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,52 +3,44 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTradeIndex, downTradeIndex) AddMigration("main", up_main_tradeIndex, down_main_tradeIndex)
} }
func upTradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_tradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades(symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades(symbol);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades(symbol, fee_currency, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades(symbol, fee_currency, traded_at);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades(traded_at, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades(traded_at, symbol);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downTradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_tradeIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol_fee_currency;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol_fee_currency;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at_symbol;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at_symbol;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upOrders, downOrders) AddMigration("main", up_main_orders, down_main_orders)
} }
func upOrders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_orders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `orders`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR NOT NULL DEFAULT '',\n -- order_id is the order id returned from the exchange\n `order_id` INTEGER NOT NULL,\n `client_order_id` VARCHAR NOT NULL DEFAULT '',\n `order_type` VARCHAR NOT NULL,\n `symbol` VARCHAR NOT NULL,\n `status` VARCHAR NOT NULL,\n `time_in_force` VARCHAR NOT NULL,\n `price` DECIMAL(16, 8) NOT NULL,\n `stop_price` DECIMAL(16, 8) NOT NULL,\n `quantity` DECIMAL(16, 8) NOT NULL,\n `executed_quantity` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `side` VARCHAR NOT NULL DEFAULT '',\n `is_working` BOOLEAN NOT NULL DEFAULT FALSE,\n `created_at` DATETIME(3) NOT NULL,\n `updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `orders`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR NOT NULL DEFAULT '',\n -- order_id is the order id returned from the exchange\n `order_id` INTEGER NOT NULL,\n `client_order_id` VARCHAR NOT NULL DEFAULT '',\n `order_type` VARCHAR NOT NULL,\n `symbol` VARCHAR NOT NULL,\n `status` VARCHAR NOT NULL,\n `time_in_force` VARCHAR NOT NULL,\n `price` DECIMAL(16, 8) NOT NULL,\n `stop_price` DECIMAL(16, 8) NOT NULL,\n `quantity` DECIMAL(16, 8) NOT NULL,\n `executed_quantity` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `side` VARCHAR NOT NULL DEFAULT '',\n `is_working` BOOLEAN NOT NULL DEFAULT FALSE,\n `created_at` DATETIME(3) NOT NULL,\n `updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downOrders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_orders(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `orders`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `orders`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTradesAddOrderId, downTradesAddOrderId) AddMigration("main", up_main_tradesAddOrderId, down_main_tradesAddOrderId)
} }
func upTradesAddOrderId(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_tradesAddOrderId(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `order_id` INTEGER;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `order_id` INTEGER;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downTradesAddOrderId(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_tradesAddOrderId(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `order_id` TO `order_id_deleted`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `order_id` TO `order_id_deleted`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,82 +3,68 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTradesIndexFix, downTradesIndexFix) AddMigration("main", up_main_tradesIndexFix, down_main_tradesIndexFix)
} }
func upTradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_tradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol_fee_currency;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol_fee_currency;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at_symbol;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at_symbol;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downTradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_tradesIndexFix(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol_fee_currency;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol_fee_currency;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at_symbol;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at_symbol;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (symbol);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (symbol, fee_currency, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (symbol, fee_currency, traded_at);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (traded_at, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (traded_at, symbol);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,42 +3,36 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upOrdersAddIndex, downOrdersAddIndex) AddMigration("main", up_main_ordersAddIndex, down_main_ordersAddIndex)
} }
func upOrdersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_ordersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE INDEX orders_symbol ON orders (exchange, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX orders_symbol ON orders (exchange, symbol);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX orders_order_id ON orders (order_id, exchange);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX orders_order_id ON orders (order_id, exchange);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downOrdersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_ordersAddIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS orders_symbol;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS orders_symbol;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS orders_order_id;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS orders_order_id;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,72 +3,60 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upKlines, downKlines) AddMigration("main", up_main_klines, down_main_klines)
} }
func upKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_klines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE TABLE `okex_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `okex_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE TABLE `binance_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `binance_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE TABLE `max_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `max_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX `klines_end_time_symbol_interval` ON `klines` (`end_time`, `symbol`, `interval`);\nCREATE INDEX `binance_klines_end_time_symbol_interval` ON `binance_klines` (`end_time`, `symbol`, `interval`);\nCREATE INDEX `okex_klines_end_time_symbol_interval` ON `okex_klines` (`end_time`, `symbol`, `interval`);\nCREATE INDEX `max_klines_end_time_symbol_interval` ON `max_klines` (`end_time`, `symbol`, `interval`);") _, err = tx.ExecContext(ctx, "CREATE INDEX `klines_end_time_symbol_interval` ON `klines` (`end_time`, `symbol`, `interval`);\nCREATE INDEX `binance_klines_end_time_symbol_interval` ON `binance_klines` (`end_time`, `symbol`, `interval`);\nCREATE INDEX `okex_klines_end_time_symbol_interval` ON `okex_klines` (`end_time`, `symbol`, `interval`);\nCREATE INDEX `max_klines_end_time_symbol_interval` ON `max_klines` (`end_time`, `symbol`, `interval`);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_klines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `klines_end_time_symbol_interval`;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `klines_end_time_symbol_interval`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `binance_klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `binance_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `okex_klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `okex_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `max_klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `max_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `klines`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `klines`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixProfitSymbolLength, downFixProfitSymbolLength) AddMigration("main", up_main_fixSymbolLength, down_main_fixSymbolLength)
} }
func upFixProfitSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixProfitSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixUniqueIndex, downFixUniqueIndex) AddMigration("main", up_main_fixUniqueIndex, down_main_fixUniqueIndex)
} }
func upFixUniqueIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixUniqueIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `trade_unique_id` ON `trades` (`exchange`,`symbol`, `side`, `id`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `trade_unique_id` ON `trades` (`exchange`,`symbol`, `side`, `id`);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixUniqueIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixUniqueIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `trade_unique_id`;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `trade_unique_id`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,62 +3,52 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddMarginColumns, downAddMarginColumns) AddMigration("main", up_main_addMarginColumns, down_main_addMarginColumns)
} }
func upAddMarginColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addMarginColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE;") _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE;") _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddMarginColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addMarginColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `is_margin` TO `is_margin_deleted`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `is_margin` TO `is_margin_deleted`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `is_isolated` TO `is_isolated_deleted`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `is_isolated` TO `is_isolated_deleted`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders` RENAME COLUMN `is_margin` TO `is_margin_deleted`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` RENAME COLUMN `is_margin` TO `is_margin_deleted`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders` RENAME COLUMN `is_isolated` TO `is_isolated_deleted`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` RENAME COLUMN `is_isolated` TO `is_isolated_deleted`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upTradePriceQuantityIndex, downTradePriceQuantityIndex) AddMigration("main", up_main_tradePriceQuantityIndex, down_main_tradePriceQuantityIndex)
} }
func upTradePriceQuantityIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_tradePriceQuantityIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_price_quantity ON trades (order_id,price,quantity);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_price_quantity ON trades (order_id,price,quantity);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downTradePriceQuantityIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_tradePriceQuantityIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX trades_price_quantity;") _, err = tx.ExecContext(ctx, "DROP INDEX trades_price_quantity;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,42 +3,36 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddPnlColumn, downAddPnlColumn) AddMigration("main", up_main_addPnlColumn, down_main_addPnlColumn)
} }
func upAddPnlColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addPnlColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `pnl` DECIMAL NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `pnl` DECIMAL NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `strategy` TEXT;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `strategy` TEXT;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddPnlColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addPnlColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `pnl` TO `pnl_deleted`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `pnl` TO `pnl_deleted`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `strategy` TO `strategy_deleted`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `strategy` TO `strategy_deleted`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddRewardsTable, downAddRewardsTable) AddMigration("main", up_main_addRewardsTable, down_main_addRewardsTable)
} }
func upAddRewardsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addRewardsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `rewards`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n -- for exchange\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- reward record id\n `uuid` VARCHAR(32) NOT NULL,\n `reward_type` VARCHAR(24) NOT NULL DEFAULT '',\n -- currency symbol, BTC, MAX, USDT ... etc\n `currency` VARCHAR(5) NOT NULL,\n -- the quantity of the rewards\n `quantity` DECIMAL(16, 8) NOT NULL,\n `state` VARCHAR(5) NOT NULL,\n `created_at` DATETIME NOT NULL,\n `spent` BOOLEAN NOT NULL DEFAULT FALSE,\n `note` TEXT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `rewards`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n -- for exchange\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- reward record id\n `uuid` VARCHAR(32) NOT NULL,\n `reward_type` VARCHAR(24) NOT NULL DEFAULT '',\n -- currency symbol, BTC, MAX, USDT ... etc\n `currency` VARCHAR(5) NOT NULL,\n -- the quantity of the rewards\n `quantity` DECIMAL(16, 8) NOT NULL,\n `state` VARCHAR(5) NOT NULL,\n `created_at` DATETIME NOT NULL,\n `spent` BOOLEAN NOT NULL DEFAULT FALSE,\n `note` TEXT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddRewardsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addRewardsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `rewards`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `rewards`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,42 +3,36 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddWithdrawsTable, downAddWithdrawsTable) AddMigration("main", up_main_addWithdrawsTable, down_main_addWithdrawsTable)
} }
func upAddWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `withdraws`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(128) NOT NULL,\n `network` VARCHAR(32) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(256) NOT NULL,\n `txn_fee` DECIMAL(16, 8) NOT NULL DEFAULT 0,\n `txn_fee_currency` VARCHAR(32) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `withdraws`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(128) NOT NULL,\n `network` VARCHAR(32) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(256) NOT NULL,\n `txn_fee` DECIMAL(16, 8) NOT NULL DEFAULT 0,\n `txn_fee_currency` VARCHAR(32) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `withdraws_txn_id` ON `withdraws` (`exchange`, `txn_id`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `withdraws_txn_id` ON `withdraws` (`exchange`, `txn_id`);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `withdraws_txn_id`;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `withdraws_txn_id`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `withdraws`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `withdraws`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,42 +3,36 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddDepositsTable, downAddDepositsTable) AddMigration("main", up_main_addDepositsTable, down_main_addDepositsTable)
} }
func upAddDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `deposits`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL,\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(128) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(256) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `deposits`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL,\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(128) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(256) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `deposits_txn_id` ON `deposits` (`exchange`, `txn_id`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `deposits_txn_id` ON `deposits` (`exchange`, `txn_id`);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `deposits_txn_id`;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `deposits_txn_id`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `deposits`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `deposits`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,42 +3,36 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddKlineTakerBuyColumns, downAddKlineTakerBuyColumns) AddMigration("main", up_main_addKlineTakerBuyColumns, down_main_addKlineTakerBuyColumns)
} }
func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `binance_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `binance_klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;") _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `binance_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `binance_klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `max_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `max_klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;") _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `max_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `max_klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `okex_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `okex_klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;") _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `okex_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `okex_klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;") _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
return err return err
} }

View File

@ -3,42 +3,36 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddIsFuturesColumn, downAddIsFuturesColumn) AddMigration("main", up_main_addIsFuturesColumn, down_main_addIsFuturesColumn)
} }
func upAddIsFuturesColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addIsFuturesColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;") _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddIsFuturesColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addIsFuturesColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `is_futures` TO `is_futures_deleted`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `is_futures` TO `is_futures_deleted`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders` RENAME COLUMN `is_futures` TO `is_futures_deleted`;") _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` RENAME COLUMN `is_futures` TO `is_futures_deleted`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddFtxKline, downAddFtxKline) AddMigration("main", up_main_addFtxKline, down_main_addFtxKline)
} }
func upAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `ftx_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0,\n `quote_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `ftx_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0,\n `quote_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE ftx_klines;") _, err = tx.ExecContext(ctx, "DROP TABLE ftx_klines;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,37 +3,32 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddNavHistoryDetails, downAddNavHistoryDetails) AddMigration("main", up_main_addNavHistoryDetails, down_main_addNavHistoryDetails)
} }
func upAddNavHistoryDetails(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addNavHistoryDetails(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `nav_history_details`\n(\n `gid` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n `exchange` VARCHAR(30) NOT NULL DEFAULT '',\n `subaccount` VARCHAR(30) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL DEFAULT (strftime('%s', 'now')),\n `currency` VARCHAR(30) NOT NULL,\n `net_asset_in_usd` DECIMAL DEFAULT 0.00000000 NOT NULL,\n `net_asset_in_btc` DECIMAL DEFAULT 0.00000000 NOT NULL,\n `balance` DECIMAL DEFAULT 0.00000000 NOT NULL,\n `available` DECIMAL DEFAULT 0.00000000 NOT NULL,\n `locked` DECIMAL DEFAULT 0.00000000 NOT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `nav_history_details`\n(\n `gid` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n `exchange` VARCHAR(30) NOT NULL DEFAULT '',\n `subaccount` VARCHAR(30) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL DEFAULT (strftime('%s', 'now')),\n `currency` VARCHAR(30) NOT NULL,\n `net_asset_in_usd` DECIMAL DEFAULT 0.00000000 NOT NULL,\n `net_asset_in_btc` DECIMAL DEFAULT 0.00000000 NOT NULL,\n `balance` DECIMAL DEFAULT 0.00000000 NOT NULL,\n `available` DECIMAL DEFAULT 0.00000000 NOT NULL,\n `locked` DECIMAL DEFAULT 0.00000000 NOT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX idx_nav_history_details\n on nav_history_details (time, currency, exchange);") _, err = tx.ExecContext(ctx, "CREATE INDEX idx_nav_history_details\n on nav_history_details (time, currency, exchange);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddNavHistoryDetails(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addNavHistoryDetails(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE nav_history_details;") _, err = tx.ExecContext(ctx, "DROP TABLE nav_history_details;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -0,0 +1,30 @@
package sqlite3
import (
"context"
"github.com/c9s/rockhopper/v2"
)
func init() {
AddMigration("main", up_main_updateFeeCurrencyLength, down_main_updateFeeCurrencyLength)
}
func up_main_updateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}
func down_main_updateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddKucoinKlines, downAddKucoinKlines) AddMigration("main", up_main_addKucoinKlines, down_main_addKucoinKlines)
} }
func upAddKucoinKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addKucoinKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `kucoin_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0,\n `quote_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `kucoin_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0,\n `quote_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddKucoinKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addKucoinKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE kucoin_klines;") _, err = tx.ExecContext(ctx, "DROP TABLE kucoin_klines;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddProfitTable, downAddProfitTable) AddMigration("main", up_main_addProfitTable, down_main_addProfitTable)
} }
func upAddProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `profits`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `strategy` VARCHAR(32) NOT NULL,\n `strategy_instance_id` VARCHAR(64) NOT NULL,\n `symbol` VARCHAR(8) NOT NULL,\n -- average_cost is the position average cost\n `average_cost` DECIMAL(16, 8) NOT NULL,\n -- profit is the pnl (profit and loss)\n `profit` DECIMAL(16, 8) NOT NULL,\n -- net_profit is the pnl (profit and loss)\n `net_profit` DECIMAL(16, 8) NOT NULL,\n -- profit_margin is the pnl (profit and loss)\n `profit_margin` DECIMAL(16, 8) NOT NULL,\n -- net_profit_margin is the pnl (profit and loss)\n `net_profit_margin` DECIMAL(16, 8) NOT NULL,\n `quote_currency` VARCHAR(10) NOT NULL,\n `base_currency` VARCHAR(10) NOT NULL,\n -- -------------------------------------------------------\n -- embedded trade data --\n -- -------------------------------------------------------\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `is_futures` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `trade_id` BIGINT NOT NULL,\n -- side is the side of the trade that makes profit\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n -- price is the price of the trade that makes profit\n `price` DECIMAL(16, 8) NOT NULL,\n -- quantity is the quantity of the trade that makes profit\n `quantity` DECIMAL(16, 8) NOT NULL,\n -- trade_amount is the quote quantity of the trade that makes profit\n `quote_quantity` DECIMAL(16, 8) NOT NULL,\n `traded_at` DATETIME(3) NOT NULL,\n -- fee\n `fee_in_usd` DECIMAL(16, 8),\n `fee` DECIMAL(16, 8) NOT NULL,\n `fee_currency` VARCHAR(10) NOT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `profits`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `strategy` VARCHAR(32) NOT NULL,\n `strategy_instance_id` VARCHAR(64) NOT NULL,\n `symbol` VARCHAR(8) NOT NULL,\n -- average_cost is the position average cost\n `average_cost` DECIMAL(16, 8) NOT NULL,\n -- profit is the pnl (profit and loss)\n `profit` DECIMAL(16, 8) NOT NULL,\n -- net_profit is the pnl (profit and loss)\n `net_profit` DECIMAL(16, 8) NOT NULL,\n -- profit_margin is the pnl (profit and loss)\n `profit_margin` DECIMAL(16, 8) NOT NULL,\n -- net_profit_margin is the pnl (profit and loss)\n `net_profit_margin` DECIMAL(16, 8) NOT NULL,\n `quote_currency` VARCHAR(10) NOT NULL,\n `base_currency` VARCHAR(10) NOT NULL,\n -- -------------------------------------------------------\n -- embedded trade data --\n -- -------------------------------------------------------\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `is_futures` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `trade_id` BIGINT NOT NULL,\n -- side is the side of the trade that makes profit\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n -- price is the price of the trade that makes profit\n `price` DECIMAL(16, 8) NOT NULL,\n -- quantity is the quantity of the trade that makes profit\n `quantity` DECIMAL(16, 8) NOT NULL,\n -- trade_amount is the quote quantity of the trade that makes profit\n `quote_quantity` DECIMAL(16, 8) NOT NULL,\n `traded_at` DATETIME(3) NOT NULL,\n -- fee\n `fee_in_usd` DECIMAL(16, 8),\n `fee` DECIMAL(16, 8) NOT NULL,\n `fee_currency` VARCHAR(10) NOT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `profits`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `profits`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddPositions, downAddPositions) AddMigration("main", up_main_addPositions, down_main_addPositions)
} }
func upAddPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, 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);") _, 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);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `positions`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `positions`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,82 +3,68 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixTradeIndexes, downFixTradeIndexes) AddMigration("main", up_main_fixTradeIndexes, down_main_fixTradeIndexes)
} }
func upFixTradeIndexes(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixTradeIndexes(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol_fee_currency;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol_fee_currency;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at_symbol;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at_symbol;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at ON trades (traded_at, symbol, exchange, id, fee_currency, fee);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at ON trades (traded_at, symbol, exchange, id, fee_currency, fee);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_id_traded_at ON trades (id, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_id_traded_at ON trades (id, traded_at);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_order_id_traded_at ON trades (order_id, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_order_id_traded_at ON trades (order_id, traded_at);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixTradeIndexes(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixTradeIndexes(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_id_traded_at;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_id_traded_at;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_order_id_traded_at;") _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_order_id_traded_at;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);") _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixFeeColumn, downFixFeeColumn) AddMigration("main", up_main_fixFeeColumn, down_main_fixFeeColumn)
} }
func upFixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,62 +3,52 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddMarginInfoToNav, downAddMarginInfoToNav) AddMigration("main", up_main_addMarginInfoToNav, down_main_addMarginInfoToNav)
} }
func upAddMarginInfoToNav(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addMarginInfoToNav(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `session` VARCHAR(50) NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `session` VARCHAR(50) NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `borrowed` DECIMAL DEFAULT 0.00000000 NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `borrowed` DECIMAL DEFAULT 0.00000000 NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `net_asset` DECIMAL DEFAULT 0.00000000 NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `net_asset` DECIMAL DEFAULT 0.00000000 NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `price_in_usd` DECIMAL DEFAULT 0.00000000 NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `price_in_usd` DECIMAL DEFAULT 0.00000000 NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `is_margin` BOOL DEFAULT FALSE NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `is_margin` BOOL DEFAULT FALSE NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `is_isolated` BOOL DEFAULT FALSE NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `is_isolated` BOOL DEFAULT FALSE NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `isolated_symbol` VARCHAR(30) DEFAULT '' NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `isolated_symbol` VARCHAR(30) DEFAULT '' NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddMarginInfoToNav(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addMarginInfoToNav(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixNetAssetColumn, downFixNetAssetColumn) AddMigration("main", up_main_fixNetAssetColumn, down_main_fixNetAssetColumn)
} }
func upFixNetAssetColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixNetAssetColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `interest` DECIMAL DEFAULT 0.00000000 NOT NULL;") _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `interest` DECIMAL DEFAULT 0.00000000 NOT NULL;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixNetAssetColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixNetAssetColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upUpdateFeeCurrencyLength, downUpdateFeeCurrencyLength) AddMigration("main", up_main_fixProfitSymbolLength, down_main_fixProfitSymbolLength)
} }
func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixProfitSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixProfitSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,72 +3,60 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upKlineUniqueIdx, downKlineUniqueIdx) AddMigration("main", up_main_klineUniqueIdx, down_main_klineUniqueIdx)
} }
func upKlineUniqueIdx(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_klineUniqueIdx(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_binance_unique\n ON binance_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_binance_unique\n ON binance_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_max_unique\n ON max_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_max_unique\n ON max_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_ftx_unique`\n ON ftx_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_ftx_unique`\n ON ftx_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_kucoin_unique`\n ON kucoin_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_kucoin_unique`\n ON kucoin_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_okex_unique`\n ON okex_klines (`symbol`, `interval`, `start_time`);") _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_okex_unique`\n ON okex_klines (`symbol`, `interval`, `start_time`);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downKlineUniqueIdx(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_klineUniqueIdx(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_ftx_unique` ON `ftx_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_ftx_unique` ON `ftx_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_max_unique` ON `max_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_max_unique` ON `max_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_binance_unique` ON `binance_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_binance_unique` ON `binance_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_kucoin_unique` ON `kucoin_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_kucoin_unique` ON `kucoin_klines`;")
if err != nil { if err != nil {
return err return err
} }
_, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_okex_unique` ON `okex_klines`;") _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_okex_unique` ON `okex_klines`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upMarginLoans, downMarginLoans) AddMigration("main", up_main_marginLoans, down_main_marginLoans)
} }
func upMarginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_marginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_loans`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `transaction_id` INTEGER NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `margin_loans`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `transaction_id` INTEGER NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downMarginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_marginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_loans`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_loans`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upMarginRepays, downMarginRepays) AddMigration("main", up_main_marginRepays, down_main_marginRepays)
} }
func upMarginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_marginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_repays`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `transaction_id` INTEGER NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `margin_repays`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `transaction_id` INTEGER NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downMarginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_marginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_repays`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_repays`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upMarginInterests, downMarginInterests) AddMigration("main", up_main_marginInterests, down_main_marginInterests)
} }
func upMarginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_marginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_interests`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `principle` DECIMAL(16, 8) NOT NULL,\n `interest` DECIMAL(20, 16) NOT NULL,\n `interest_rate` DECIMAL(20, 16) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `margin_interests`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `principle` DECIMAL(16, 8) NOT NULL,\n `interest` DECIMAL(20, 16) NOT NULL,\n `interest_rate` DECIMAL(20, 16) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downMarginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_marginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_interests`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_interests`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upMarginLiquidations, downMarginLiquidations) AddMigration("main", up_main_marginLiquidations, down_main_marginLiquidations)
} }
func upMarginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_marginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_liquidations`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `order_id` INTEGER NOT NULL,\n `is_isolated` BOOL NOT NULL DEFAULT false,\n `average_price` DECIMAL(16, 8) NOT NULL,\n `price` DECIMAL(16, 8) NOT NULL,\n `quantity` DECIMAL(16, 8) NOT NULL,\n `executed_quantity` DECIMAL(16, 8) NOT NULL,\n `side` VARCHAR(5) NOT NULL DEFAULT '',\n `time_in_force` VARCHAR(5) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `margin_liquidations`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `order_id` INTEGER NOT NULL,\n `is_isolated` BOOL NOT NULL DEFAULT false,\n `average_price` DECIMAL(16, 8) NOT NULL,\n `price` DECIMAL(16, 8) NOT NULL,\n `quantity` DECIMAL(16, 8) NOT NULL,\n `executed_quantity` DECIMAL(16, 8) NOT NULL,\n `side` VARCHAR(5) NOT NULL DEFAULT '',\n `time_in_force` VARCHAR(5) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downMarginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_marginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_liquidations`;") _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_liquidations`;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upAddBybitKlines, downAddBybitKlines) AddMigration("main", up_main_addBybitKlines, down_main_addBybitKlines)
} }
func upAddBybitKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_addBybitKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `bybit_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0,\n `quote_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `bybit_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0,\n `quote_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0\n);")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downAddBybitKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_addBybitKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "DROP TABLE bybit_klines;") _, err = tx.ExecContext(ctx, "DROP TABLE bybit_klines;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -3,32 +3,28 @@ package sqlite3
import ( import (
"context" "context"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
func init() { func init() {
AddMigration(upFixSymbolLength, downFixSymbolLength) AddMigration("main", up_main_fixOrderStatusLength, down_main_fixOrderStatusLength)
} }
func upFixSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func up_main_fixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }
func downFixSymbolLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func down_main_fixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
return err return err
} }

View File

@ -6,31 +6,36 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
) )
var registeredGoMigrations map[int64]*rockhopper.Migration type registryKey struct {
Package string
Version int64
}
func MergeMigrationsMap(ms map[int64]*rockhopper.Migration) { var registeredGoMigrations = map[registryKey]*rockhopper.Migration{}
func MergeMigrationsMap(ms map[registryKey]*rockhopper.Migration) {
for k, m := range ms { for k, m := range ms {
if _, ok := registeredGoMigrations[k]; !ok { if _, ok := registeredGoMigrations[k]; !ok {
registeredGoMigrations[k] = m registeredGoMigrations[k] = m
} else { } else {
log.Printf("the migration key %d is duplicated: %+v", k, m) log.Printf("the migration key %+v is duplicated: %+v", k, m)
} }
} }
} }
func GetMigrationsMap() map[int64]*rockhopper.Migration { func GetMigrationsMap() map[registryKey]*rockhopper.Migration {
return registeredGoMigrations return registeredGoMigrations
} }
// SortedMigrations build up the migration objects, sort them by timestamp and return as a slice // SortedMigrations builds up the migration objects, sort them by timestamp and return as a slice
func SortedMigrations() rockhopper.MigrationSlice { func SortedMigrations() rockhopper.MigrationSlice {
return Migrations() return Migrations()
} }
// Migrations build up the migration objects, sort them by timestamp and return as a slice // Migrations builds up the migration objects, sort them by timestamp and return as a slice
func Migrations() rockhopper.MigrationSlice { func Migrations() rockhopper.MigrationSlice {
var migrations = rockhopper.MigrationSlice{} var migrations = rockhopper.MigrationSlice{}
for _, migration := range registeredGoMigrations { for _, migration := range registeredGoMigrations {
@ -41,11 +46,14 @@ func Migrations() rockhopper.MigrationSlice {
} }
// AddMigration adds a migration with its runtime caller information // AddMigration adds a migration with its runtime caller information
func AddMigration(up, down rockhopper.TransactionHandler) { func AddMigration(packageName string, up, down rockhopper.TransactionHandler) {
pc, filename, _, _ := runtime.Caller(1) pc, filename, _, _ := runtime.Caller(1)
if packageName == "" {
funcName := runtime.FuncForPC(pc).Name() funcName := runtime.FuncForPC(pc).Name()
packageName := _parseFuncPackageName(funcName) packageName = _parseFuncPackageName(funcName)
}
AddNamedMigration(packageName, filename, up, down) AddNamedMigration(packageName, filename, up, down)
} }
@ -64,10 +72,13 @@ func _parseFuncPackageName(funcName string) string {
// AddNamedMigration adds a named migration to the registered go migration map // AddNamedMigration adds a named migration to the registered go migration map
func AddNamedMigration(packageName, filename string, up, down rockhopper.TransactionHandler) { func AddNamedMigration(packageName, filename string, up, down rockhopper.TransactionHandler) {
if registeredGoMigrations == nil { if registeredGoMigrations == nil {
registeredGoMigrations = make(map[int64]*rockhopper.Migration) registeredGoMigrations = make(map[registryKey]*rockhopper.Migration)
} }
v, _ := rockhopper.FileNumericComponent(filename) v, err := rockhopper.FileNumericComponent(filename)
if err != nil {
panic(fmt.Errorf("unable to parse numeric component from filename %s: %v", filename, err))
}
migration := &rockhopper.Migration{ migration := &rockhopper.Migration{
Package: packageName, Package: packageName,
@ -80,8 +91,10 @@ func AddNamedMigration(packageName, filename string, up, down rockhopper.Transac
UseTx: true, UseTx: true,
} }
if existing, ok := registeredGoMigrations[v]; ok { key := registryKey{Package: packageName, Version: v}
panic(fmt.Sprintf("failed to add migration %q: version conflicts with %q", filename, existing.Source)) if existing, ok := registeredGoMigrations[key]; ok {
panic(fmt.Sprintf("failed to add migration %q: version conflicts with key %+v: %+v", filename, key, existing))
} }
registeredGoMigrations[v] = migration
registeredGoMigrations[key] = migration
} }

View File

@ -3,7 +3,8 @@ package sqlite3
import ( import (
"testing" "testing"
"github.com/c9s/rockhopper" "github.com/c9s/rockhopper/v2"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -13,8 +14,8 @@ func TestGetMigrationsMap(t *testing.T) {
} }
func TestMergeMigrationsMap(t *testing.T) { func TestMergeMigrationsMap(t *testing.T) {
MergeMigrationsMap(map[int64]*rockhopper.Migration{ MergeMigrationsMap(map[registryKey]*rockhopper.Migration{
2: &rockhopper.Migration{}, registryKey{Version: 2}: &rockhopper.Migration{},
3: &rockhopper.Migration{}, registryKey{Version: 2}: &rockhopper.Migration{},
}) })
} }

View File

@ -3,6 +3,7 @@
--- ---
driver: mysql driver: mysql
dialect: mysql dialect: mysql
package: main
# unix socket connection to mysql with password # unix socket connection to mysql with password
# dsn: "root:123123@unix(/opt/local/var/run/mysql57/mysqld.sock)/bbgo_dev?parseTime=true" # dsn: "root:123123@unix(/opt/local/var/run/mysql57/mysqld.sock)/bbgo_dev?parseTime=true"

View File

@ -2,4 +2,6 @@
driver: sqlite3 driver: sqlite3
dialect: sqlite3 dialect: sqlite3
dsn: "bbgo.sqlite3" dsn: "bbgo.sqlite3"
# package: bbgo
package: main
migrationsDir: migrations/sqlite3 migrationsDir: migrations/sqlite3