-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1820 from c9s/c9s/record-net-profit
FEATURE: add new migration script to record the net profit values
- Loading branch information
Showing
10 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Profiling | ||
=================== | ||
|
||
```shell | ||
dotenv -f .env.local -- go run -tags pprof ./cmd/bbgo run \ | ||
--config ./makemoney-btcusdt.yaml \ | ||
--cpu-profile makemoney.pprof \ | ||
--enable-profile-server | ||
``` | ||
|
||
```shell | ||
go tool pprof http://localhost:6060/debug/pprof/heap | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- +up | ||
-- +begin | ||
ALTER TABLE `positions` | ||
ADD COLUMN `net_profit` DECIMAL(16, 8) DEFAULT 0.00000000 NOT NULL | ||
; | ||
-- +end | ||
-- +begin | ||
UPDATE positions SET net_profit = profit WHERE net_profit = 0.0; | ||
-- +end | ||
|
||
-- +down | ||
|
||
-- +begin | ||
ALTER TABLE `positions` | ||
DROP COLUMN `net_profit` | ||
; | ||
-- +end |
15 changes: 15 additions & 0 deletions
15
migrations/sqlite3/20241115165059_add_net_profit_column.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- +up | ||
-- +begin | ||
ALTER TABLE `positions` | ||
ADD COLUMN `net_profit` DECIMAL DEFAULT 0.00000000 NOT NULL | ||
; | ||
-- +end | ||
|
||
|
||
-- +down | ||
|
||
-- +begin | ||
ALTER TABLE `positions` | ||
DROP COLUMN `net_profit` | ||
; | ||
-- +end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build pprof | ||
// +build pprof | ||
|
||
package cmd | ||
|
||
import _ "net/http/pprof" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
pkg/migrations/mysql/main_20241115165059_add_net_profit_column.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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 | ||
} | ||
_, err = tx.ExecContext(ctx, "UPDATE positions SET net_profit = profit WHERE net_profit = 0.0;") | ||
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 | ||
} |
29 changes: 29 additions & 0 deletions
29
pkg/migrations/sqlite3/main_20241115165059_add_net_profit_column.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters