From 7b290afc2a5524f4e85c6c6cf57bce3b1cb09d43 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 8 Dec 2021 19:57:55 +0800 Subject: [PATCH] compile and update migration package --- .../20211205162043_add_is_futures_column.go | 44 +++++++++++++++++++ .../20211205162302_add_is_futures_column.go | 44 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 pkg/migrations/mysql/20211205162043_add_is_futures_column.go create mode 100644 pkg/migrations/sqlite3/20211205162302_add_is_futures_column.go diff --git a/pkg/migrations/mysql/20211205162043_add_is_futures_column.go b/pkg/migrations/mysql/20211205162043_add_is_futures_column.go new file mode 100644 index 000000000..1ee5ac34b --- /dev/null +++ b/pkg/migrations/mysql/20211205162043_add_is_futures_column.go @@ -0,0 +1,44 @@ +package mysql + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddIsFuturesColumn, downAddIsFuturesColumn) + +} + +func upAddIsFuturesColumn(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) { + // 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/sqlite3/20211205162302_add_is_futures_column.go b/pkg/migrations/sqlite3/20211205162302_add_is_futures_column.go new file mode 100644 index 000000000..7970df098 --- /dev/null +++ b/pkg/migrations/sqlite3/20211205162302_add_is_futures_column.go @@ -0,0 +1,44 @@ +package sqlite3 + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddIsFuturesColumn, downAddIsFuturesColumn) + +} + +func upAddIsFuturesColumn(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) { + // 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 +}