Merge pull request #1646 from c9s/minor/add-inserted-at-to-trade

MINOR: add inserted_at column to trades
This commit is contained in:
YC 2024-06-18 18:07:27 +08:00 committed by GitHub
commit c83524a04a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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 {