From f2ae512e3fe7190384411f715e50feeb0fbd1e3e Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 15 Nov 2024 16:54:33 +0800 Subject: [PATCH] compile and update migration package --- ...in_20241115165059_add_net_profit_column.go | 29 +++++++++++++++++++ ...in_20241115165059_add_net_profit_column.go | 29 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 pkg/migrations/mysql/main_20241115165059_add_net_profit_column.go create mode 100644 pkg/migrations/sqlite3/main_20241115165059_add_net_profit_column.go diff --git a/pkg/migrations/mysql/main_20241115165059_add_net_profit_column.go b/pkg/migrations/mysql/main_20241115165059_add_net_profit_column.go new file mode 100644 index 000000000..15307b315 --- /dev/null +++ b/pkg/migrations/mysql/main_20241115165059_add_net_profit_column.go @@ -0,0 +1,29 @@ +package mysql + +import ( + "context" + + "github.com/c9s/rockhopper/v2" +) + +func init() { + AddMigration("main", up_main_addNetProfitColumn, down_main_addNetProfitColumn) +} + +func up_main_addNetProfitColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is applied. + _, err = tx.ExecContext(ctx, "ALTER TABLE `positions`\n ADD COLUMN `net_profit` DECIMAL(16, 8) DEFAULT 0.00000000 NOT NULL\n;") + if err != nil { + return err + } + return err +} + +func down_main_addNetProfitColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is rolled back. + _, err = tx.ExecContext(ctx, "ALTER TABLE `positions`\nDROP COLUMN `net_profit`\n;") + if err != nil { + return err + } + return err +} diff --git a/pkg/migrations/sqlite3/main_20241115165059_add_net_profit_column.go b/pkg/migrations/sqlite3/main_20241115165059_add_net_profit_column.go new file mode 100644 index 000000000..e397eb71a --- /dev/null +++ b/pkg/migrations/sqlite3/main_20241115165059_add_net_profit_column.go @@ -0,0 +1,29 @@ +package sqlite3 + +import ( + "context" + + "github.com/c9s/rockhopper/v2" +) + +func init() { + AddMigration("main", up_main_addNetProfitColumn, down_main_addNetProfitColumn) +} + +func up_main_addNetProfitColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is applied. + _, err = tx.ExecContext(ctx, "ALTER TABLE `positions`\n ADD COLUMN `net_profit` DECIMAL DEFAULT 0.00000000 NOT NULL\n;") + if err != nil { + return err + } + return err +} + +func down_main_addNetProfitColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is rolled back. + _, err = tx.ExecContext(ctx, "ALTER TABLE `positions`\nDROP COLUMN `net_profit`\n;") + if err != nil { + return err + } + return err +}