diff --git a/pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go b/pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go new file mode 100644 index 000000000..52fd1ff84 --- /dev/null +++ b/pkg/migrations/mysql/20210531234123_add_kline_taker_buy_columns.go @@ -0,0 +1,54 @@ +package mysql + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddKlineTakerBuyColumns, downAddKlineTakerBuyColumns) + +} + +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 `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0;") + if err != nil { + return err + } + + _, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0;") + if err != nil { + return err + } + + _, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0;") + if err != nil { + return err + } + + return err +} + +func downAddKlineTakerBuyColumns(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 `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 `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 `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;") + if err != nil { + return err + } + + return err +} diff --git a/pkg/migrations/sqlite3/20210531234123_add_kline_taker_buy_columns.go b/pkg/migrations/sqlite3/20210531234123_add_kline_taker_buy_columns.go new file mode 100644 index 000000000..456d6b04b --- /dev/null +++ b/pkg/migrations/sqlite3/20210531234123_add_kline_taker_buy_columns.go @@ -0,0 +1,34 @@ +package sqlite3 + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddKlineTakerBuyColumns, downAddKlineTakerBuyColumns) + +} + +func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is applied. + + _, err = tx.ExecContext(ctx, "SELECT 'up SQL query';") + if err != nil { + return err + } + + return err +} + +func downAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is rolled back. + + _, err = tx.ExecContext(ctx, "SELECT 'down SQL query';") + if err != nil { + return err + } + + return err +}