From be10019007e443585256cc18986882784c09e470 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 26 Dec 2021 02:31:09 +0800 Subject: [PATCH] compile and update migration package --- ...10531234123_add_kline_taker_buy_columns.go | 6 +-- .../20211211034819_add_nav_history_details.go | 39 +++++++++++++++++++ .../mysql/20211226022411_add_kucoin_klines.go | 34 ++++++++++++++++ .../sqlite3/20211211020303_add_ftx_kline.go | 2 +- .../20211211034818_add_nav_history_details.go | 39 +++++++++++++++++++ .../20211226022411_add_kucoin_klines.go | 34 ++++++++++++++++ 6 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 pkg/migrations/mysql/20211211034819_add_nav_history_details.go create mode 100644 pkg/migrations/mysql/20211226022411_add_kucoin_klines.go create mode 100644 pkg/migrations/sqlite3/20211211034818_add_nav_history_details.go create mode 100644 pkg/migrations/sqlite3/20211226022411_add_kucoin_klines.go diff --git a/pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go b/pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go index d3db7fe25..8a656d484 100644 --- a/pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go +++ b/pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go @@ -14,17 +14,17 @@ func init() { func upAddKlineTakerBuyColumns(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, 4) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0;") + _, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0;") + _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;") if err != nil { return err } - _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0;") + _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 8) NOT NULL DEFAULT 0.0;") if err != nil { return err } diff --git a/pkg/migrations/mysql/20211211034819_add_nav_history_details.go b/pkg/migrations/mysql/20211211034819_add_nav_history_details.go new file mode 100644 index 000000000..f077ce810 --- /dev/null +++ b/pkg/migrations/mysql/20211211034819_add_nav_history_details.go @@ -0,0 +1,39 @@ +package mysql + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddNavHistoryDetails, downAddNavHistoryDetails) + +} + +func upAddNavHistoryDetails(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) { + // 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/20211226022411_add_kucoin_klines.go b/pkg/migrations/mysql/20211226022411_add_kucoin_klines.go new file mode 100644 index 000000000..dfb281d3b --- /dev/null +++ b/pkg/migrations/mysql/20211226022411_add_kucoin_klines.go @@ -0,0 +1,34 @@ +package mysql + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddKucoinKlines, downAddKucoinKlines) + +} + +func upAddKucoinKlines(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) { + // 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/20211211020303_add_ftx_kline.go b/pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go index 7775e052f..4b72d8aba 100644 --- a/pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go +++ b/pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go @@ -25,7 +25,7 @@ func upAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func downAddFtxKline(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;") + _, err = tx.ExecContext(ctx, "DROP TABLE ftx_klines;") if err != nil { return err } diff --git a/pkg/migrations/sqlite3/20211211034818_add_nav_history_details.go b/pkg/migrations/sqlite3/20211211034818_add_nav_history_details.go new file mode 100644 index 000000000..63ee75254 --- /dev/null +++ b/pkg/migrations/sqlite3/20211211034818_add_nav_history_details.go @@ -0,0 +1,39 @@ +package sqlite3 + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddNavHistoryDetails, downAddNavHistoryDetails) + +} + +func upAddNavHistoryDetails(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 NOT NULL DEFAULT '',\n `subaccount` VARCHAR NOT NULL DEFAULT '',\n time DATETIME(3) NOT NULL DEFAULT (strftime('%s','now')),\n currency VARCHAR NOT NULL,\n balance_in_usd DECIMAL DEFAULT 0.00000000 NOT NULL,\n balance_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) { + // 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/20211226022411_add_kucoin_klines.go b/pkg/migrations/sqlite3/20211226022411_add_kucoin_klines.go new file mode 100644 index 000000000..caf4b96ba --- /dev/null +++ b/pkg/migrations/sqlite3/20211226022411_add_kucoin_klines.go @@ -0,0 +1,34 @@ +package sqlite3 + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddKucoinKlines, downAddKucoinKlines) + +} + +func upAddKucoinKlines(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) { + // 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 +}