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 +}