Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR: add inserted_at column to trades #1646

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions migrations/mysql/20240531163411_trades_created.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- +up
-- +begin
ALTER TABLE `trades` ADD COLUMN `inserted_at` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL AFTER `traded_at`;
-- +end

-- +begin
UPDATE `trades` SET `inserted_at`=`traded_at`;
-- +end

-- +down

-- +begin
ALTER TABLE `trades` DROP COLUMN `inserted_at`;
-- +end
23 changes: 23 additions & 0 deletions migrations/sqlite3/20240531163411_trades_created.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- +up
-- +begin
ALTER TABLE trades ADD COLUMN inserted_at TEXT;

UPDATE trades SET inserted_at = traded_at;

CREATE TRIGGER set_inserted_at
AFTER INSERT ON trades
FOR EACH ROW
BEGIN
UPDATE trades
SET inserted_at = datetime('now')
WHERE rowid = NEW.rowid;
END;

-- +end

-- +down

-- +begin
DROP TRIGGER set_inserted_at;
ALTER TABLE trades DROP COLUMN inserted_at;
-- +end
2 changes: 2 additions & 0 deletions pkg/types/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ type Trade struct {

// PnL is the profit and loss value of the executed trade
PnL sql.NullFloat64 `json:"pnl" db:"pnl"`

InsertedAt Time `json:"insertedAt" db:"inserted_at"`
}

func (trade Trade) CsvHeader() []string {
Expand Down
Loading