bbgo_origin/migrations/sqlite3/20240531163411_trades_created.sql
Yu-Cheng 49d567c8f2 trade: add inserted_at column
A trade may be missed initially and fetched after it has occurred.
2024-06-17 17:42:32 +08:00

24 lines
385 B
SQL

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