diff --git a/pkg/migrations/mysql/20201211175751_fix_symbol_length.go b/pkg/migrations/mysql/20201211175751_fix_symbol_length.go deleted file mode 100644 index 56456075f..000000000 --- a/pkg/migrations/mysql/20201211175751_fix_symbol_length.go +++ /dev/null @@ -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 -} diff --git a/pkg/migrations/mysql/20210118163847_fix_unique_index.go b/pkg/migrations/mysql/20210118163847_fix_unique_index.go deleted file mode 100644 index f370b2195..000000000 --- a/pkg/migrations/mysql/20210118163847_fix_unique_index.go +++ /dev/null @@ -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 -} diff --git a/pkg/migrations/mysql/20210215203116_add_pnl_column.go b/pkg/migrations/mysql/20210215203116_add_pnl_column.go deleted file mode 100644 index 712b5e848..000000000 --- a/pkg/migrations/mysql/20210215203116_add_pnl_column.go +++ /dev/null @@ -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 -} diff --git a/pkg/migrations/mysql/20211204014905_update_taker_buy_base_volumn.go b/pkg/migrations/mysql/20211204014905_update_taker_buy_base_volumn.go deleted file mode 100644 index 86131a3f3..000000000 --- a/pkg/migrations/mysql/20211204014905_update_taker_buy_base_volumn.go +++ /dev/null @@ -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 -} diff --git a/pkg/migrations/mysql/20231221121432_add_futures_klines.go b/pkg/migrations/mysql/20231221121432_add_futures_klines.go deleted file mode 100644 index d30558dfc..000000000 --- a/pkg/migrations/mysql/20231221121432_add_futures_klines.go +++ /dev/null @@ -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 -} diff --git a/pkg/migrations/mysql/20200721225616_trades.go b/pkg/migrations/mysql/main_20200721225616_trades.go similarity index 90% rename from pkg/migrations/mysql/20200721225616_trades.go rename to pkg/migrations/mysql/main_20200721225616_trades.go index 1a40f3c32..7d07aa5fb 100644 --- a/pkg/migrations/mysql/20200721225616_trades.go +++ b/pkg/migrations/mysql/main_20200721225616_trades.go @@ -3,62 +3,52 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `trades`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol ON trades;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol_fee_currency ON trades;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at_symbol ON trades;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20210119232826_add_margin_columns.go b/pkg/migrations/mysql/main_20200819054742_trade_index.go similarity index 64% rename from pkg/migrations/mysql/20210119232826_add_margin_columns.go rename to pkg/migrations/mysql/main_20200819054742_trade_index.go index f7b8bdc58..0ae23b361 100644 --- a/pkg/migrations/mysql/20210119232826_add_margin_columns.go +++ b/pkg/migrations/mysql/main_20200819054742_trade_index.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20201102222546_orders.go b/pkg/migrations/mysql/main_20201102222546_orders.go similarity index 89% rename from pkg/migrations/mysql/20201102222546_orders.go rename to pkg/migrations/mysql/main_20201102222546_orders.go index a7cca310a..59af3bfb0 100644 --- a/pkg/migrations/mysql/20201102222546_orders.go +++ b/pkg/migrations/mysql/main_20201102222546_orders.go @@ -3,52 +3,44 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX orders_symbol ON orders (exchange, symbol);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX orders_order_id ON orders (order_id, exchange);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX orders_symbol ON orders;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX orders_order_id ON orders;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE `orders`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/main_20201103173342_trades_add_order_id.go b/pkg/migrations/mysql/main_20201103173342_trades_add_order_id.go new file mode 100644 index 000000000..318066f3e --- /dev/null +++ b/pkg/migrations/mysql/main_20201103173342_trades_add_order_id.go @@ -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 +} diff --git a/pkg/migrations/sqlite3/20231123125402_fix_order_status_length.go b/pkg/migrations/mysql/main_20201105092857_trades_index_fix.go similarity index 61% rename from pkg/migrations/sqlite3/20231123125402_fix_order_status_length.go rename to pkg/migrations/mysql/main_20201105092857_trades_index_fix.go index 2ef640879..358942917 100644 --- a/pkg/migrations/sqlite3/20231123125402_fix_order_status_length.go +++ b/pkg/migrations/mysql/main_20201105092857_trades_index_fix.go @@ -1,34 +1,30 @@ -package sqlite3 +package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20200819054742_trade_index.go b/pkg/migrations/mysql/main_20201105093056_orders_add_index.go similarity index 55% rename from pkg/migrations/mysql/20200819054742_trade_index.go rename to pkg/migrations/mysql/main_20201105093056_orders_add_index.go index 60ba7925b..19681e4b4 100644 --- a/pkg/migrations/mysql/20200819054742_trade_index.go +++ b/pkg/migrations/mysql/main_20201105093056_orders_add_index.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20201106114742_klines.go b/pkg/migrations/mysql/main_20201106114742_klines.go similarity index 89% rename from pkg/migrations/mysql/20201106114742_klines.go rename to pkg/migrations/mysql/main_20201106114742_klines.go index 43fd04ca4..18b229073 100644 --- a/pkg/migrations/mysql/20201106114742_klines.go +++ b/pkg/migrations/mysql/main_20201106114742_klines.go @@ -3,72 +3,60 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX `klines_end_time_symbol_interval` ON klines (`end_time`, `symbol`, `interval`);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE TABLE `okex_klines` LIKE `klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE TABLE `binance_klines` LIKE `klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE TABLE `max_klines` LIKE `klines`;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX `klines_end_time_symbol_interval` ON `klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE `binance_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE `okex_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE `max_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE `klines`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20211211103657_update_fee_currency_length.go b/pkg/migrations/mysql/main_20201211175751_fix_symbol_length.go similarity index 59% rename from pkg/migrations/mysql/20211211103657_update_fee_currency_length.go rename to pkg/migrations/mysql/main_20201211175751_fix_symbol_length.go index 36c21ae84..88be892d2 100644 --- a/pkg/migrations/mysql/20211211103657_update_fee_currency_length.go +++ b/pkg/migrations/mysql/main_20201211175751_fix_symbol_length.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20201105093056_orders_add_index.go b/pkg/migrations/mysql/main_20210118163847_fix_unique_index.go similarity index 55% rename from pkg/migrations/mysql/20201105093056_orders_add_index.go rename to pkg/migrations/mysql/main_20210118163847_fix_unique_index.go index 7dec0d805..c1573ac93 100644 --- a/pkg/migrations/mysql/20201105093056_orders_add_index.go +++ b/pkg/migrations/mysql/main_20210118163847_fix_unique_index.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/main_20210119232826_add_margin_columns.go b/pkg/migrations/mysql/main_20210119232826_add_margin_columns.go new file mode 100644 index 000000000..b624b8158 --- /dev/null +++ b/pkg/migrations/mysql/main_20210119232826_add_margin_columns.go @@ -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 +} diff --git a/pkg/migrations/mysql/20210129182704_trade_price_quantity_index.go b/pkg/migrations/mysql/main_20210129182704_trade_price_quantity_index.go similarity index 58% rename from pkg/migrations/mysql/20210129182704_trade_price_quantity_index.go rename to pkg/migrations/mysql/main_20210129182704_trade_price_quantity_index.go index 9b6a5753b..9ff09a78a 100644 --- a/pkg/migrations/mysql/20210129182704_trade_price_quantity_index.go +++ b/pkg/migrations/mysql/main_20210129182704_trade_price_quantity_index.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_price_quantity ON trades (order_id,price,quantity);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX trades_price_quantity ON trades") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20201103173342_trades_add_order_id.go b/pkg/migrations/mysql/main_20210215203116_add_pnl_column.go similarity index 59% rename from pkg/migrations/mysql/20201103173342_trades_add_order_id.go rename to pkg/migrations/mysql/main_20210215203116_add_pnl_column.go index e9c8c24da..831d79d1d 100644 --- a/pkg/migrations/mysql/20201103173342_trades_add_order_id.go +++ b/pkg/migrations/mysql/main_20210215203116_add_pnl_column.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20210223080622_add_rewards_table.go b/pkg/migrations/mysql/main_20210223080622_add_rewards_table.go similarity index 80% rename from pkg/migrations/mysql/20210223080622_add_rewards_table.go rename to pkg/migrations/mysql/main_20210223080622_add_rewards_table.go index edf0f9ab8..06652355c 100644 --- a/pkg/migrations/mysql/20210223080622_add_rewards_table.go +++ b/pkg/migrations/mysql/main_20210223080622_add_rewards_table.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `rewards`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20210301140656_add_withdraws_table.go b/pkg/migrations/mysql/main_20210301140656_add_withdraws_table.go similarity index 78% rename from pkg/migrations/mysql/20210301140656_add_withdraws_table.go rename to pkg/migrations/mysql/main_20210301140656_add_withdraws_table.go index 3f6c296a4..402aab3ec 100644 --- a/pkg/migrations/mysql/20210301140656_add_withdraws_table.go +++ b/pkg/migrations/mysql/main_20210301140656_add_withdraws_table.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `withdraws`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20210307201830_add_deposits_table.go b/pkg/migrations/mysql/main_20210307201830_add_deposits_table.go similarity index 74% rename from pkg/migrations/mysql/20210307201830_add_deposits_table.go rename to pkg/migrations/mysql/main_20210307201830_add_deposits_table.go index 753658b03..35e9a59da 100644 --- a/pkg/migrations/mysql/20210307201830_add_deposits_table.go +++ b/pkg/migrations/mysql/main_20210307201830_add_deposits_table.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `deposits`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20210416230730_klines_symbol_length.go b/pkg/migrations/mysql/main_20210416230730_klines_symbol_length.go similarity index 81% rename from pkg/migrations/mysql/20210416230730_klines_symbol_length.go rename to pkg/migrations/mysql/main_20210416230730_klines_symbol_length.go index 4a5672beb..ab818858a 100644 --- a/pkg/migrations/mysql/20210416230730_klines_symbol_length.go +++ b/pkg/migrations/mysql/main_20210416230730_klines_symbol_length.go @@ -3,62 +3,52 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(7) NOT NULL;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20210421091430_increase_symbol_length.go b/pkg/migrations/mysql/main_20210421091430_increase_symbol_length.go similarity index 80% rename from pkg/migrations/mysql/20210421091430_increase_symbol_length.go rename to pkg/migrations/mysql/main_20210421091430_increase_symbol_length.go index 8ade5fd7e..f3f19fe41 100644 --- a/pkg/migrations/mysql/20210421091430_increase_symbol_length.go +++ b/pkg/migrations/mysql/main_20210421091430_increase_symbol_length.go @@ -3,62 +3,52 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(12) NOT NULL;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `symbol` VARCHAR(10) NOT NULL;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20210421095030_increase_decimal_length.go b/pkg/migrations/mysql/main_20210421095030_increase_decimal_length.go similarity index 83% rename from pkg/migrations/mysql/20210421095030_increase_decimal_length.go rename to pkg/migrations/mysql/main_20210421095030_increase_decimal_length.go index 3524e01e0..141599d4e 100644 --- a/pkg/migrations/mysql/20210421095030_increase_decimal_length.go +++ b/pkg/migrations/mysql/main_20210421095030_increase_decimal_length.go @@ -3,62 +3,52 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `volume` decimal(20,8) unsigned NOT NULL DEFAULT '0.00000000';") if err != nil { 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\nMODIFY COLUMN `volume` decimal(16,8) unsigned NOT NULL DEFAULT '0.00000000';") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go b/pkg/migrations/mysql/main_20210531234123_add_kline_taker_buy_columns.go similarity index 86% rename from pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go rename to pkg/migrations/mysql/main_20210531234123_add_kline_taker_buy_columns.go index 3687cf0d0..47af2b54c 100644 --- a/pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go +++ b/pkg/migrations/mysql/main_20210531234123_add_kline_taker_buy_columns.go @@ -3,57 +3,48 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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;") if err != nil { 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;") if err != nil { 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;") if err != nil { 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. - _, 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 { 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`;") if err != nil { 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`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20211205162043_add_is_futures_column.go b/pkg/migrations/mysql/main_20211205162043_add_is_futures_column.go similarity index 70% rename from pkg/migrations/mysql/20211205162043_add_is_futures_column.go rename to pkg/migrations/mysql/main_20211205162043_add_is_futures_column.go index 1ee5ac34b..d9b85ce25 100644 --- a/pkg/migrations/mysql/20211205162043_add_is_futures_column.go +++ b/pkg/migrations/mysql/main_20211205162043_add_is_futures_column.go @@ -3,42 +3,36 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` DROP COLUMN `is_futures`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` DROP COLUMN `is_futures`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20211211020303_add_ftx_kline.go b/pkg/migrations/mysql/main_20211211020303_add_ftx_kline.go similarity index 83% rename from pkg/migrations/mysql/20211211020303_add_ftx_kline.go rename to pkg/migrations/mysql/main_20211211020303_add_ftx_kline.go index f13600a40..0ef496467 100644 --- a/pkg/migrations/mysql/20211211020303_add_ftx_kline.go +++ b/pkg/migrations/mysql/main_20211211020303_add_ftx_kline.go @@ -3,37 +3,32 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { return err } - _, err = tx.ExecContext(ctx, "create index klines_end_time_symbol_interval\n on ftx_klines (end_time, symbol, `interval`);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "drop table ftx_klines;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20211211034819_add_nav_history_details.go b/pkg/migrations/mysql/main_20211211034819_add_nav_history_details.go similarity index 80% rename from pkg/migrations/mysql/20211211034819_add_nav_history_details.go rename to pkg/migrations/mysql/main_20211211034819_add_nav_history_details.go index f98de36fd..f8740b452 100644 --- a/pkg/migrations/mysql/20211211034819_add_nav_history_details.go +++ b/pkg/migrations/mysql/main_20211211034819_add_nav_history_details.go @@ -3,37 +3,32 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX idx_nav_history_details\n on nav_history_details (time, currency, exchange);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE nav_history_details;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20201105092857_trades_index_fix.go b/pkg/migrations/mysql/main_20211211103657_update_fee_currency_length.go similarity index 52% rename from pkg/migrations/mysql/20201105092857_trades_index_fix.go rename to pkg/migrations/mysql/main_20211211103657_update_fee_currency_length.go index fdbea09a6..998206a4d 100644 --- a/pkg/migrations/mysql/20201105092857_trades_index_fix.go +++ b/pkg/migrations/mysql/main_20211211103657_update_fee_currency_length.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20211226022411_add_kucoin_klines.go b/pkg/migrations/mysql/main_20211226022411_add_kucoin_klines.go similarity index 58% rename from pkg/migrations/mysql/20211226022411_add_kucoin_klines.go rename to pkg/migrations/mysql/main_20211226022411_add_kucoin_klines.go index dfb281d3b..97cfb617f 100644 --- a/pkg/migrations/mysql/20211226022411_add_kucoin_klines.go +++ b/pkg/migrations/mysql/main_20211226022411_add_kucoin_klines.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE TABLE `kucoin_klines` LIKE `binance_klines`;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE `kucoin_klines`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220304153317_add_profit_table.go b/pkg/migrations/mysql/main_20220304153317_add_profit_table.go similarity index 90% rename from pkg/migrations/mysql/20220304153317_add_profit_table.go rename to pkg/migrations/mysql/main_20220304153317_add_profit_table.go index dd5d4e082..08c4b1018 100644 --- a/pkg/migrations/mysql/20220304153317_add_profit_table.go +++ b/pkg/migrations/mysql/main_20220304153317_add_profit_table.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `profits`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220307132917_add_positions.go b/pkg/migrations/mysql/main_20220307132917_add_positions.go similarity index 84% rename from pkg/migrations/mysql/20220307132917_add_positions.go rename to pkg/migrations/mysql/main_20220307132917_add_positions.go index 6670419fd..700fde1d7 100644 --- a/pkg/migrations/mysql/20220307132917_add_positions.go +++ b/pkg/migrations/mysql/main_20220307132917_add_positions.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `positions`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220317125555_fix_trade_indexes.go b/pkg/migrations/mysql/main_20220317125555_fix_trade_indexes.go similarity index 85% rename from pkg/migrations/mysql/20220317125555_fix_trade_indexes.go rename to pkg/migrations/mysql/main_20220317125555_fix_trade_indexes.go index 3e0e519a6..23aaf3f10 100644 --- a/pkg/migrations/mysql/20220317125555_fix_trade_indexes.go +++ b/pkg/migrations/mysql/main_20220317125555_fix_trade_indexes.go @@ -3,82 +3,68 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol ON trades;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol_fee_currency ON trades;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at_symbol ON trades;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at ON trades (traded_at, symbol, exchange, id, fee_currency, fee);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_id_traded_at ON trades (id, traded_at);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_order_id_traded_at ON trades (order_id, traded_at);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at ON trades;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX trades_id_traded_at ON trades;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX trades_order_id_traded_at ON trades;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220419121046_fix_fee_column.go b/pkg/migrations/mysql/main_20220419121046_fix_fee_column.go similarity index 70% rename from pkg/migrations/mysql/20220419121046_fix_fee_column.go rename to pkg/migrations/mysql/main_20220419121046_fix_fee_column.go index aa544c92e..912816eca 100644 --- a/pkg/migrations/mysql/20220419121046_fix_fee_column.go +++ b/pkg/migrations/mysql/main_20220419121046_fix_fee_column.go @@ -3,42 +3,36 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE trades\n CHANGE fee fee DECIMAL(16, 8) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE fee fee DECIMAL(16, 8) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE fee_in_usd fee_in_usd DECIMAL(16, 8);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220503144849_add_margin_info_to_nav.go b/pkg/migrations/mysql/main_20220503144849_add_margin_info_to_nav.go similarity index 80% rename from pkg/migrations/mysql/20220503144849_add_margin_info_to_nav.go rename to pkg/migrations/mysql/main_20220503144849_add_margin_info_to_nav.go index 98b25028a..8298ab0c4 100644 --- a/pkg/migrations/mysql/20220503144849_add_margin_info_to_nav.go +++ b/pkg/migrations/mysql/main_20220503144849_add_margin_info_to_nav.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, 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 { return err } - return err } diff --git a/pkg/migrations/mysql/20220504184155_fix_net_asset_column.go b/pkg/migrations/mysql/main_20220504184155_fix_net_asset_column.go similarity index 74% rename from pkg/migrations/mysql/20220504184155_fix_net_asset_column.go rename to pkg/migrations/mysql/main_20220504184155_fix_net_asset_column.go index c986d66fe..b284a023c 100644 --- a/pkg/migrations/mysql/20220504184155_fix_net_asset_column.go +++ b/pkg/migrations/mysql/main_20220504184155_fix_net_asset_column.go @@ -3,37 +3,32 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { return err } - _, 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 { 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details`\n DROP COLUMN `interest`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220512170322_fix_profit_symbol_length.go b/pkg/migrations/mysql/main_20220512170322_fix_profit_symbol_length.go similarity index 56% rename from pkg/migrations/mysql/20220512170322_fix_profit_symbol_length.go rename to pkg/migrations/mysql/main_20220512170322_fix_profit_symbol_length.go index 1196c4d06..668ac1f5b 100644 --- a/pkg/migrations/mysql/20220512170322_fix_profit_symbol_length.go +++ b/pkg/migrations/mysql/main_20220512170322_fix_profit_symbol_length.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE symbol symbol VARCHAR(20) NOT NULL;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220520140707_kline_unique_idx.go b/pkg/migrations/mysql/main_20220520140707_kline_unique_idx.go similarity index 85% rename from pkg/migrations/mysql/20220520140707_kline_unique_idx.go rename to pkg/migrations/mysql/main_20220520140707_kline_unique_idx.go index 84dfb5030..98b801ba0 100644 --- a/pkg/migrations/mysql/20220520140707_kline_unique_idx.go +++ b/pkg/migrations/mysql/main_20220520140707_kline_unique_idx.go @@ -3,72 +3,60 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_binance_unique\n ON binance_klines (`symbol`, `interval`, `start_time`);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_max_unique\n ON max_klines (`symbol`, `interval`, `start_time`);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_ftx_unique`\n ON ftx_klines (`symbol`, `interval`, `start_time`);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_kucoin_unique`\n ON kucoin_klines (`symbol`, `interval`, `start_time`);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_okex_unique`\n ON okex_klines (`symbol`, `interval`, `start_time`);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_ftx_unique` ON `ftx_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_max_unique` ON `max_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_binance_unique` ON `binance_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_kucoin_unique` ON `kucoin_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_okex_unique` ON `okex_klines`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220531012226_margin_loans.go b/pkg/migrations/mysql/main_20220531012226_margin_loans.go similarity index 78% rename from pkg/migrations/mysql/20220531012226_margin_loans.go rename to pkg/migrations/mysql/main_20220531012226_margin_loans.go index 1857a18ee..c752e2747 100644 --- a/pkg/migrations/mysql/20220531012226_margin_loans.go +++ b/pkg/migrations/mysql/main_20220531012226_margin_loans.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_loans`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220531013327_margin_repays.go b/pkg/migrations/mysql/main_20220531013327_margin_repays.go similarity index 77% rename from pkg/migrations/mysql/20220531013327_margin_repays.go rename to pkg/migrations/mysql/main_20220531013327_margin_repays.go index 66582d977..fc7435f10 100644 --- a/pkg/migrations/mysql/20220531013327_margin_repays.go +++ b/pkg/migrations/mysql/main_20220531013327_margin_repays.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_repays`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220531013542_margin_interests.go b/pkg/migrations/mysql/main_20220531013542_margin_interests.go similarity index 76% rename from pkg/migrations/mysql/20220531013542_margin_interests.go rename to pkg/migrations/mysql/main_20220531013542_margin_interests.go index b6f3be151..ebf15cabb 100644 --- a/pkg/migrations/mysql/20220531013542_margin_interests.go +++ b/pkg/migrations/mysql/main_20220531013542_margin_interests.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_interests`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20220531015005_margin_liquidations.go b/pkg/migrations/mysql/main_20220531015005_margin_liquidations.go similarity index 80% rename from pkg/migrations/mysql/20220531015005_margin_liquidations.go rename to pkg/migrations/mysql/main_20220531015005_margin_liquidations.go index 194c0a67f..3bd3aaa2c 100644 --- a/pkg/migrations/mysql/20220531015005_margin_liquidations.go +++ b/pkg/migrations/mysql/main_20220531015005_margin_liquidations.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_liquidations`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20230815173104_add_bybit_klines.go b/pkg/migrations/mysql/main_20230815173104_add_bybit_klines.go similarity index 59% rename from pkg/migrations/mysql/20230815173104_add_bybit_klines.go rename to pkg/migrations/mysql/main_20230815173104_add_bybit_klines.go index dcaa29fa5..67e6dcb67 100644 --- a/pkg/migrations/mysql/20230815173104_add_bybit_klines.go +++ b/pkg/migrations/mysql/main_20230815173104_add_bybit_klines.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE TABLE `bybit_klines` LIKE `binance_klines`;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE `bybit_klines`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/20231123125402_fix_order_status_length.go b/pkg/migrations/mysql/main_20231123125402_fix_order_status_length.go similarity index 57% rename from pkg/migrations/mysql/20231123125402_fix_order_status_length.go rename to pkg/migrations/mysql/main_20231123125402_fix_order_status_length.go index df7e3f62c..3be1c57bf 100644 --- a/pkg/migrations/mysql/20231123125402_fix_order_status_length.go +++ b/pkg/migrations/mysql/main_20231123125402_fix_order_status_length.go @@ -3,32 +3,28 @@ package mysql import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `orders`\n CHANGE `status` `status` varchar(20) NOT NULL;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/mysql/migration_api.go b/pkg/migrations/mysql/migration_api.go index b68c5f81d..04311c1cc 100644 --- a/pkg/migrations/mysql/migration_api.go +++ b/pkg/migrations/mysql/migration_api.go @@ -6,22 +6,27 @@ import ( "runtime" "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 { if _, ok := registeredGoMigrations[k]; !ok { registeredGoMigrations[k] = m } 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 } @@ -41,11 +46,14 @@ func Migrations() rockhopper.MigrationSlice { } // 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) - funcName := runtime.FuncForPC(pc).Name() - packageName := _parseFuncPackageName(funcName) + if packageName == "" { + funcName := runtime.FuncForPC(pc).Name() + packageName = _parseFuncPackageName(funcName) + } + 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 func AddNamedMigration(packageName, filename string, up, down rockhopper.TransactionHandler) { 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{ Package: packageName, @@ -80,8 +91,10 @@ func AddNamedMigration(packageName, filename string, up, down rockhopper.Transac UseTx: true, } - if existing, ok := registeredGoMigrations[v]; ok { - panic(fmt.Sprintf("failed to add migration %q: version conflicts with %q", filename, existing.Source)) + key := registryKey{Package: packageName, Version: v} + 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 } diff --git a/pkg/migrations/mysql/migration_api_test.go b/pkg/migrations/mysql/migration_api_test.go index 2684076d3..36f387b44 100644 --- a/pkg/migrations/mysql/migration_api_test.go +++ b/pkg/migrations/mysql/migration_api_test.go @@ -3,7 +3,8 @@ package mysql import ( "testing" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" + "github.com/stretchr/testify/assert" ) @@ -13,8 +14,8 @@ func TestGetMigrationsMap(t *testing.T) { } func TestMergeMigrationsMap(t *testing.T) { - MergeMigrationsMap(map[int64]*rockhopper.Migration{ - 2: &rockhopper.Migration{}, - 3: &rockhopper.Migration{}, + MergeMigrationsMap(map[registryKey]*rockhopper.Migration{ + registryKey{Version: 2}: &rockhopper.Migration{}, + registryKey{Version: 2}: &rockhopper.Migration{}, }) } diff --git a/pkg/migrations/sqlite3/20211204014905_update_taker_buy_base_volumn.go b/pkg/migrations/sqlite3/20211204014905_update_taker_buy_base_volumn.go deleted file mode 100644 index 2155ea7b4..000000000 --- a/pkg/migrations/sqlite3/20211204014905_update_taker_buy_base_volumn.go +++ /dev/null @@ -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 -} diff --git a/pkg/migrations/sqlite3/20231221121432_add_futures_klines.go b/pkg/migrations/sqlite3/20231221121432_add_futures_klines.go deleted file mode 100644 index 18225a93a..000000000 --- a/pkg/migrations/sqlite3/20231221121432_add_futures_klines.go +++ /dev/null @@ -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 -} diff --git a/pkg/migrations/sqlite3/20200721225616_trades.go b/pkg/migrations/sqlite3/main_20200721225616_trades.go similarity index 80% rename from pkg/migrations/sqlite3/20200721225616_trades.go rename to pkg/migrations/sqlite3/main_20200721225616_trades.go index dbc677683..8903aaab6 100644 --- a/pkg/migrations/sqlite3/20200721225616_trades.go +++ b/pkg/migrations/sqlite3/main_20200721225616_trades.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE TABLE `trades`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `id` INTEGER,\n `exchange` TEXT NOT NULL DEFAULT '',\n `symbol` TEXT NOT NULL,\n `price` DECIMAL(16, 8) NOT NULL,\n `quantity` DECIMAL(16, 8) NOT NULL,\n `quote_quantity` DECIMAL(16, 8) NOT NULL,\n `fee` DECIMAL(16, 8) NOT NULL,\n `fee_currency` VARCHAR(4) NOT NULL,\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `traded_at` DATETIME(3) NOT NULL\n);") if err != nil { return err } - return err } -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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `trades`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20200819054742_trade_index.go b/pkg/migrations/sqlite3/main_20200819054742_trade_index.go similarity index 76% rename from pkg/migrations/sqlite3/20200819054742_trade_index.go rename to pkg/migrations/sqlite3/main_20200819054742_trade_index.go index 50d3a9514..f1fe76da6 100644 --- a/pkg/migrations/sqlite3/20200819054742_trade_index.go +++ b/pkg/migrations/sqlite3/main_20200819054742_trade_index.go @@ -3,52 +3,44 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades(symbol);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades(symbol, fee_currency, traded_at);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades(traded_at, symbol);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX trades_symbol_fee_currency;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX trades_traded_at_symbol;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20201102222546_orders.go b/pkg/migrations/sqlite3/main_20201102222546_orders.go similarity index 84% rename from pkg/migrations/sqlite3/20201102222546_orders.go rename to pkg/migrations/sqlite3/main_20201102222546_orders.go index 1930783d5..50fea710f 100644 --- a/pkg/migrations/sqlite3/20201102222546_orders.go +++ b/pkg/migrations/sqlite3/main_20201102222546_orders.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `orders`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20201103173342_trades_add_order_id.go b/pkg/migrations/sqlite3/main_20201103173342_trades_add_order_id.go similarity index 60% rename from pkg/migrations/sqlite3/20201103173342_trades_add_order_id.go rename to pkg/migrations/sqlite3/main_20201103173342_trades_add_order_id.go index 05608ffb5..7cdbf2dc7 100644 --- a/pkg/migrations/sqlite3/20201103173342_trades_add_order_id.go +++ b/pkg/migrations/sqlite3/main_20201103173342_trades_add_order_id.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `order_id` INTEGER;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `order_id` TO `order_id_deleted`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20201105092857_trades_index_fix.go b/pkg/migrations/sqlite3/main_20201105092857_trades_index_fix.go similarity index 85% rename from pkg/migrations/sqlite3/20201105092857_trades_index_fix.go rename to pkg/migrations/sqlite3/main_20201105092857_trades_index_fix.go index 969449027..6b3a133b1 100644 --- a/pkg/migrations/sqlite3/20201105092857_trades_index_fix.go +++ b/pkg/migrations/sqlite3/main_20201105092857_trades_index_fix.go @@ -3,82 +3,68 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol_fee_currency;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at_symbol;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol_fee_currency;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at_symbol;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (symbol);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (symbol, fee_currency, traded_at);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (traded_at, symbol);") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20201105093056_orders_add_index.go b/pkg/migrations/sqlite3/main_20201105093056_orders_add_index.go similarity index 70% rename from pkg/migrations/sqlite3/20201105093056_orders_add_index.go rename to pkg/migrations/sqlite3/main_20201105093056_orders_add_index.go index fcb730bb5..ae5df7bd9 100644 --- a/pkg/migrations/sqlite3/20201105093056_orders_add_index.go +++ b/pkg/migrations/sqlite3/main_20201105093056_orders_add_index.go @@ -3,42 +3,36 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE INDEX orders_symbol ON orders (exchange, symbol);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX orders_order_id ON orders (order_id, exchange);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS orders_symbol;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS orders_order_id;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20201106114742_klines.go b/pkg/migrations/sqlite3/main_20201106114742_klines.go similarity index 94% rename from pkg/migrations/sqlite3/20201106114742_klines.go rename to pkg/migrations/sqlite3/main_20201106114742_klines.go index 5678f77d8..801071948 100644 --- a/pkg/migrations/sqlite3/20201106114742_klines.go +++ b/pkg/migrations/sqlite3/main_20201106114742_klines.go @@ -3,72 +3,60 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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);") if err != nil { 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);") if err != nil { 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);") if err != nil { 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`);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `klines_end_time_symbol_interval`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `binance_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `okex_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `max_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `klines`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220512170330_fix_profit_symbol_length.go b/pkg/migrations/sqlite3/main_20201211175751_fix_symbol_length.go similarity index 63% rename from pkg/migrations/sqlite3/20220512170330_fix_profit_symbol_length.go rename to pkg/migrations/sqlite3/main_20201211175751_fix_symbol_length.go index 31b378360..ec208a3ec 100644 --- a/pkg/migrations/sqlite3/20220512170330_fix_profit_symbol_length.go +++ b/pkg/migrations/sqlite3/main_20201211175751_fix_symbol_length.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20210118163847_fix_unique_index.go b/pkg/migrations/sqlite3/main_20210118163847_fix_unique_index.go similarity index 61% rename from pkg/migrations/sqlite3/20210118163847_fix_unique_index.go rename to pkg/migrations/sqlite3/main_20210118163847_fix_unique_index.go index 649e9cd7f..e1140c573 100644 --- a/pkg/migrations/sqlite3/20210118163847_fix_unique_index.go +++ b/pkg/migrations/sqlite3/main_20210118163847_fix_unique_index.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `trade_unique_id` ON `trades` (`exchange`,`symbol`, `side`, `id`);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `trade_unique_id`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20210119232826_add_margin_columns.go b/pkg/migrations/sqlite3/main_20210119232826_add_margin_columns.go similarity index 81% rename from pkg/migrations/sqlite3/20210119232826_add_margin_columns.go rename to pkg/migrations/sqlite3/main_20210119232826_add_margin_columns.go index a04974d78..5a240ec9f 100644 --- a/pkg/migrations/sqlite3/20210119232826_add_margin_columns.go +++ b/pkg/migrations/sqlite3/main_20210119232826_add_margin_columns.go @@ -3,62 +3,52 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `is_margin` TO `is_margin_deleted`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `is_isolated` TO `is_isolated_deleted`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` RENAME COLUMN `is_margin` TO `is_margin_deleted`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` RENAME COLUMN `is_isolated` TO `is_isolated_deleted`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20210129182704_trade_price_quantity_index.go b/pkg/migrations/sqlite3/main_20210129182704_trade_price_quantity_index.go similarity index 57% rename from pkg/migrations/sqlite3/20210129182704_trade_price_quantity_index.go rename to pkg/migrations/sqlite3/main_20210129182704_trade_price_quantity_index.go index 33c06c155..b1a2d0b59 100644 --- a/pkg/migrations/sqlite3/20210129182704_trade_price_quantity_index.go +++ b/pkg/migrations/sqlite3/main_20210129182704_trade_price_quantity_index.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_price_quantity ON trades (order_id,price,quantity);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX trades_price_quantity;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20210215203111_add_pnl_column.go b/pkg/migrations/sqlite3/main_20210215203111_add_pnl_column.go similarity index 71% rename from pkg/migrations/sqlite3/20210215203111_add_pnl_column.go rename to pkg/migrations/sqlite3/main_20210215203111_add_pnl_column.go index a752d057e..71edce5a7 100644 --- a/pkg/migrations/sqlite3/20210215203111_add_pnl_column.go +++ b/pkg/migrations/sqlite3/main_20210215203111_add_pnl_column.go @@ -3,42 +3,36 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `pnl` DECIMAL NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `strategy` TEXT;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `pnl` TO `pnl_deleted`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `strategy` TO `strategy_deleted`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20210223080622_add_rewards_table.go b/pkg/migrations/sqlite3/main_20210223080622_add_rewards_table.go similarity index 77% rename from pkg/migrations/sqlite3/20210223080622_add_rewards_table.go rename to pkg/migrations/sqlite3/main_20210223080622_add_rewards_table.go index 5118f443f..2fdd3f4a5 100644 --- a/pkg/migrations/sqlite3/20210223080622_add_rewards_table.go +++ b/pkg/migrations/sqlite3/main_20210223080622_add_rewards_table.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `rewards`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20210301140656_add_withdraws_table.go b/pkg/migrations/sqlite3/main_20210301140656_add_withdraws_table.go similarity index 80% rename from pkg/migrations/sqlite3/20210301140656_add_withdraws_table.go rename to pkg/migrations/sqlite3/main_20210301140656_add_withdraws_table.go index d6e4d0a5f..e159bcf5a 100644 --- a/pkg/migrations/sqlite3/20210301140656_add_withdraws_table.go +++ b/pkg/migrations/sqlite3/main_20210301140656_add_withdraws_table.go @@ -3,42 +3,36 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `withdraws_txn_id` ON `withdraws` (`exchange`, `txn_id`);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `withdraws_txn_id`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `withdraws`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20210307201830_add_deposits_table.go b/pkg/migrations/sqlite3/main_20210307201830_add_deposits_table.go similarity index 77% rename from pkg/migrations/sqlite3/20210307201830_add_deposits_table.go rename to pkg/migrations/sqlite3/main_20210307201830_add_deposits_table.go index 0416c5439..2956724b9 100644 --- a/pkg/migrations/sqlite3/20210307201830_add_deposits_table.go +++ b/pkg/migrations/sqlite3/main_20210307201830_add_deposits_table.go @@ -3,42 +3,36 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `deposits_txn_id` ON `deposits` (`exchange`, `txn_id`);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `deposits_txn_id`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `deposits`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20210531234123_add_kline_taker_buy_columns.go b/pkg/migrations/sqlite3/main_20210531234123_add_kline_taker_buy_columns.go similarity index 83% rename from pkg/migrations/sqlite3/20210531234123_add_kline_taker_buy_columns.go rename to pkg/migrations/sqlite3/main_20210531234123_add_kline_taker_buy_columns.go index a5f1c8c2c..862fd11b5 100644 --- a/pkg/migrations/sqlite3/20210531234123_add_kline_taker_buy_columns.go +++ b/pkg/migrations/sqlite3/main_20210531234123_add_kline_taker_buy_columns.go @@ -3,42 +3,36 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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;") if err != nil { 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;") if err != nil { 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;") if err != nil { 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. - return err } diff --git a/pkg/migrations/sqlite3/20211205162302_add_is_futures_column.go b/pkg/migrations/sqlite3/main_20211205162302_add_is_futures_column.go similarity index 71% rename from pkg/migrations/sqlite3/20211205162302_add_is_futures_column.go rename to pkg/migrations/sqlite3/main_20211205162302_add_is_futures_column.go index 7970df098..51f538a90 100644 --- a/pkg/migrations/sqlite3/20211205162302_add_is_futures_column.go +++ b/pkg/migrations/sqlite3/main_20211205162302_add_is_futures_column.go @@ -3,42 +3,36 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` ADD COLUMN `is_futures` BOOLEAN NOT NULL DEFAULT FALSE;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `trades` RENAME COLUMN `is_futures` TO `is_futures_deleted`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `orders` RENAME COLUMN `is_futures` TO `is_futures_deleted`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go b/pkg/migrations/sqlite3/main_20211211020303_add_ftx_kline.go similarity index 82% rename from pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go rename to pkg/migrations/sqlite3/main_20211211020303_add_ftx_kline.go index 4b72d8aba..bf811ef90 100644 --- a/pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go +++ b/pkg/migrations/sqlite3/main_20211211020303_add_ftx_kline.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE ftx_klines;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20211211034818_add_nav_history_details.go b/pkg/migrations/sqlite3/main_20211211034818_add_nav_history_details.go similarity index 80% rename from pkg/migrations/sqlite3/20211211034818_add_nav_history_details.go rename to pkg/migrations/sqlite3/main_20211211034818_add_nav_history_details.go index 4dc6eda9e..e1d34ad84 100644 --- a/pkg/migrations/sqlite3/20211211034818_add_nav_history_details.go +++ b/pkg/migrations/sqlite3/main_20211211034818_add_nav_history_details.go @@ -3,37 +3,32 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX idx_nav_history_details\n on nav_history_details (time, currency, exchange);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE nav_history_details;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/main_20211211103657_update_fee_currency_length.go b/pkg/migrations/sqlite3/main_20211211103657_update_fee_currency_length.go new file mode 100644 index 000000000..92cace767 --- /dev/null +++ b/pkg/migrations/sqlite3/main_20211211103657_update_fee_currency_length.go @@ -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 +} diff --git a/pkg/migrations/sqlite3/20211226022411_add_kucoin_klines.go b/pkg/migrations/sqlite3/main_20211226022411_add_kucoin_klines.go similarity index 83% rename from pkg/migrations/sqlite3/20211226022411_add_kucoin_klines.go rename to pkg/migrations/sqlite3/main_20211226022411_add_kucoin_klines.go index caf4b96ba..a3c67fe23 100644 --- a/pkg/migrations/sqlite3/20211226022411_add_kucoin_klines.go +++ b/pkg/migrations/sqlite3/main_20211226022411_add_kucoin_klines.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE kucoin_klines;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220304153309_add_profit_table.go b/pkg/migrations/sqlite3/main_20220304153309_add_profit_table.go similarity index 89% rename from pkg/migrations/sqlite3/20220304153309_add_profit_table.go rename to pkg/migrations/sqlite3/main_20220304153309_add_profit_table.go index b95968be2..ea1abac0b 100644 --- a/pkg/migrations/sqlite3/20220304153309_add_profit_table.go +++ b/pkg/migrations/sqlite3/main_20220304153309_add_profit_table.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `profits`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220307132917_add_positions.go b/pkg/migrations/sqlite3/main_20220307132917_add_positions.go similarity index 82% rename from pkg/migrations/sqlite3/20220307132917_add_positions.go rename to pkg/migrations/sqlite3/main_20220307132917_add_positions.go index 21c1e757f..bf2a48bb5 100644 --- a/pkg/migrations/sqlite3/20220307132917_add_positions.go +++ b/pkg/migrations/sqlite3/main_20220307132917_add_positions.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `positions`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220317125555_fix_trade_indexes.go b/pkg/migrations/sqlite3/main_20220317125555_fix_trade_indexes.go similarity index 85% rename from pkg/migrations/sqlite3/20220317125555_fix_trade_indexes.go rename to pkg/migrations/sqlite3/main_20220317125555_fix_trade_indexes.go index 1e68af699..e93c01fee 100644 --- a/pkg/migrations/sqlite3/20220317125555_fix_trade_indexes.go +++ b/pkg/migrations/sqlite3/main_20220317125555_fix_trade_indexes.go @@ -3,82 +3,68 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_symbol_fee_currency;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at_symbol;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at ON trades (traded_at, symbol, exchange, id, fee_currency, fee);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_id_traded_at ON trades (id, traded_at);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_order_id_traded_at ON trades (order_id, traded_at);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_traded_at;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_id_traded_at;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS trades_order_id_traded_at;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol ON trades (exchange, symbol);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220419121046_fix_fee_column.go b/pkg/migrations/sqlite3/main_20220419121046_fix_fee_column.go similarity index 56% rename from pkg/migrations/sqlite3/20220419121046_fix_fee_column.go rename to pkg/migrations/sqlite3/main_20220419121046_fix_fee_column.go index 788f34b87..ee7548579 100644 --- a/pkg/migrations/sqlite3/20220419121046_fix_fee_column.go +++ b/pkg/migrations/sqlite3/main_20220419121046_fix_fee_column.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220503144849_add_margin_info_to_nav.go b/pkg/migrations/sqlite3/main_20220503144849_add_margin_info_to_nav.go similarity index 81% rename from pkg/migrations/sqlite3/20220503144849_add_margin_info_to_nav.go rename to pkg/migrations/sqlite3/main_20220503144849_add_margin_info_to_nav.go index 849e7e19a..d0309bb6a 100644 --- a/pkg/migrations/sqlite3/20220503144849_add_margin_info_to_nav.go +++ b/pkg/migrations/sqlite3/main_20220503144849_add_margin_info_to_nav.go @@ -3,62 +3,52 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `session` VARCHAR(50) NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `borrowed` DECIMAL DEFAULT 0.00000000 NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `net_asset` DECIMAL DEFAULT 0.00000000 NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `price_in_usd` DECIMAL DEFAULT 0.00000000 NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `is_margin` BOOL DEFAULT FALSE NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `is_isolated` BOOL DEFAULT FALSE NOT NULL;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `isolated_symbol` VARCHAR(30) DEFAULT '' NOT NULL;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220504184155_fix_net_asset_column.go b/pkg/migrations/sqlite3/main_20220504184155_fix_net_asset_column.go similarity index 59% rename from pkg/migrations/sqlite3/20220504184155_fix_net_asset_column.go rename to pkg/migrations/sqlite3/main_20220504184155_fix_net_asset_column.go index d398ad527..4850a7973 100644 --- a/pkg/migrations/sqlite3/20220504184155_fix_net_asset_column.go +++ b/pkg/migrations/sqlite3/main_20220504184155_fix_net_asset_column.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "ALTER TABLE `nav_history_details` ADD COLUMN `interest` DECIMAL DEFAULT 0.00000000 NOT NULL;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20211211103657_update_fee_currency_length.go b/pkg/migrations/sqlite3/main_20220512170330_fix_profit_symbol_length.go similarity index 53% rename from pkg/migrations/sqlite3/20211211103657_update_fee_currency_length.go rename to pkg/migrations/sqlite3/main_20220512170330_fix_profit_symbol_length.go index c9df8bfcb..4c2510b49 100644 --- a/pkg/migrations/sqlite3/20211211103657_update_fee_currency_length.go +++ b/pkg/migrations/sqlite3/main_20220512170330_fix_profit_symbol_length.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220520140707_kline_unique_idx.go b/pkg/migrations/sqlite3/main_20220520140707_kline_unique_idx.go similarity index 85% rename from pkg/migrations/sqlite3/20220520140707_kline_unique_idx.go rename to pkg/migrations/sqlite3/main_20220520140707_kline_unique_idx.go index 605187154..4431f8b1a 100644 --- a/pkg/migrations/sqlite3/20220520140707_kline_unique_idx.go +++ b/pkg/migrations/sqlite3/main_20220520140707_kline_unique_idx.go @@ -3,72 +3,60 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_binance_unique\n ON binance_klines (`symbol`, `interval`, `start_time`);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX idx_kline_max_unique\n ON max_klines (`symbol`, `interval`, `start_time`);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_ftx_unique`\n ON ftx_klines (`symbol`, `interval`, `start_time`);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_kucoin_unique`\n ON kucoin_klines (`symbol`, `interval`, `start_time`);") if err != nil { return err } - _, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `idx_kline_okex_unique`\n ON okex_klines (`symbol`, `interval`, `start_time`);") if err != nil { 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. - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_ftx_unique` ON `ftx_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_max_unique` ON `max_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_binance_unique` ON `binance_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_kucoin_unique` ON `kucoin_klines`;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "DROP INDEX `idx_kline_okex_unique` ON `okex_klines`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220531012226_margin_loans.go b/pkg/migrations/sqlite3/main_20220531012226_margin_loans.go similarity index 75% rename from pkg/migrations/sqlite3/20220531012226_margin_loans.go rename to pkg/migrations/sqlite3/main_20220531012226_margin_loans.go index 25bfc68b9..87f72ccf7 100644 --- a/pkg/migrations/sqlite3/20220531012226_margin_loans.go +++ b/pkg/migrations/sqlite3/main_20220531012226_margin_loans.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_loans`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220531013327_margin_repays.go b/pkg/migrations/sqlite3/main_20220531013327_margin_repays.go similarity index 75% rename from pkg/migrations/sqlite3/20220531013327_margin_repays.go rename to pkg/migrations/sqlite3/main_20220531013327_margin_repays.go index d91564322..120727575 100644 --- a/pkg/migrations/sqlite3/20220531013327_margin_repays.go +++ b/pkg/migrations/sqlite3/main_20220531013327_margin_repays.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_repays`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220531013541_margin_interests.go b/pkg/migrations/sqlite3/main_20220531013541_margin_interests.go similarity index 74% rename from pkg/migrations/sqlite3/20220531013541_margin_interests.go rename to pkg/migrations/sqlite3/main_20220531013541_margin_interests.go index 0c06a2ce6..e10bc8043 100644 --- a/pkg/migrations/sqlite3/20220531013541_margin_interests.go +++ b/pkg/migrations/sqlite3/main_20220531013541_margin_interests.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_interests`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20220531015005_margin_liquidations.go b/pkg/migrations/sqlite3/main_20220531015005_margin_liquidations.go similarity index 78% rename from pkg/migrations/sqlite3/20220531015005_margin_liquidations.go rename to pkg/migrations/sqlite3/main_20220531015005_margin_liquidations.go index 5f1e07f76..152932ae8 100644 --- a/pkg/migrations/sqlite3/20220531015005_margin_liquidations.go +++ b/pkg/migrations/sqlite3/main_20220531015005_margin_liquidations.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `margin_liquidations`;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20230815173104_add_bybit_klines.go b/pkg/migrations/sqlite3/main_20230815173104_add_bybit_klines.go similarity index 83% rename from pkg/migrations/sqlite3/20230815173104_add_bybit_klines.go rename to pkg/migrations/sqlite3/main_20230815173104_add_bybit_klines.go index 54afcd9ca..cbe565154 100644 --- a/pkg/migrations/sqlite3/20230815173104_add_bybit_klines.go +++ b/pkg/migrations/sqlite3/main_20230815173104_add_bybit_klines.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, 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 { 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. - _, err = tx.ExecContext(ctx, "DROP TABLE bybit_klines;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/20201211175751_fix_symbol_length.go b/pkg/migrations/sqlite3/main_20231123125402_fix_order_status_length.go similarity index 53% rename from pkg/migrations/sqlite3/20201211175751_fix_symbol_length.go rename to pkg/migrations/sqlite3/main_20231123125402_fix_order_status_length.go index 3b029b2ca..9c5cb3711 100644 --- a/pkg/migrations/sqlite3/20201211175751_fix_symbol_length.go +++ b/pkg/migrations/sqlite3/main_20231123125402_fix_order_status_length.go @@ -3,32 +3,28 @@ package sqlite3 import ( "context" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" ) 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { 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. - _, err = tx.ExecContext(ctx, "SELECT 1;") if err != nil { return err } - return err } diff --git a/pkg/migrations/sqlite3/migration_api.go b/pkg/migrations/sqlite3/migration_api.go index 5e73bfea0..bf3dcfd66 100644 --- a/pkg/migrations/sqlite3/migration_api.go +++ b/pkg/migrations/sqlite3/migration_api.go @@ -6,31 +6,36 @@ import ( "runtime" "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 { if _, ok := registeredGoMigrations[k]; !ok { registeredGoMigrations[k] = m } 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 } -// 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 { 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 { var migrations = rockhopper.MigrationSlice{} for _, migration := range registeredGoMigrations { @@ -41,11 +46,14 @@ func Migrations() rockhopper.MigrationSlice { } // 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) - funcName := runtime.FuncForPC(pc).Name() - packageName := _parseFuncPackageName(funcName) + if packageName == "" { + funcName := runtime.FuncForPC(pc).Name() + packageName = _parseFuncPackageName(funcName) + } + 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 func AddNamedMigration(packageName, filename string, up, down rockhopper.TransactionHandler) { 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{ Package: packageName, @@ -80,8 +91,10 @@ func AddNamedMigration(packageName, filename string, up, down rockhopper.Transac UseTx: true, } - if existing, ok := registeredGoMigrations[v]; ok { - panic(fmt.Sprintf("failed to add migration %q: version conflicts with %q", filename, existing.Source)) + key := registryKey{Package: packageName, Version: v} + 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 } diff --git a/pkg/migrations/sqlite3/migration_api_test.go b/pkg/migrations/sqlite3/migration_api_test.go index d1f4fe1ab..85fd38165 100644 --- a/pkg/migrations/sqlite3/migration_api_test.go +++ b/pkg/migrations/sqlite3/migration_api_test.go @@ -3,7 +3,8 @@ package sqlite3 import ( "testing" - "github.com/c9s/rockhopper" + "github.com/c9s/rockhopper/v2" + "github.com/stretchr/testify/assert" ) @@ -13,8 +14,8 @@ func TestGetMigrationsMap(t *testing.T) { } func TestMergeMigrationsMap(t *testing.T) { - MergeMigrationsMap(map[int64]*rockhopper.Migration{ - 2: &rockhopper.Migration{}, - 3: &rockhopper.Migration{}, + MergeMigrationsMap(map[registryKey]*rockhopper.Migration{ + registryKey{Version: 2}: &rockhopper.Migration{}, + registryKey{Version: 2}: &rockhopper.Migration{}, }) } diff --git a/rockhopper_mysql.yaml b/rockhopper_mysql.yaml index 2519de0ae..00bccb324 100644 --- a/rockhopper_mysql.yaml +++ b/rockhopper_mysql.yaml @@ -3,6 +3,7 @@ --- driver: mysql dialect: mysql +package: main # unix socket connection to mysql with password # dsn: "root:123123@unix(/opt/local/var/run/mysql57/mysqld.sock)/bbgo_dev?parseTime=true" diff --git a/rockhopper_sqlite.yaml b/rockhopper_sqlite.yaml index 259e7fe67..934cbbf41 100644 --- a/rockhopper_sqlite.yaml +++ b/rockhopper_sqlite.yaml @@ -2,4 +2,6 @@ driver: sqlite3 dialect: sqlite3 dsn: "bbgo.sqlite3" +# package: bbgo +package: main migrationsDir: migrations/sqlite3