Files
eventbook-exchange/crates/exchange/src/lot_migration.sql
T

19 lines
1.1 KiB
SQL

-- Caller holds an IMMEDIATE transaction and checks the format marker under the lock.
-- Fail the transaction if any integer would be promoted to SQLite REAL.
CREATE TABLE order_lot_format (version INTEGER PRIMARY KEY CHECK(version=1));
INSERT INTO order_lot_format
SELECT CASE WHEN EXISTS(SELECT 1 FROM orders WHERE MAX(quantity,remaining)>92233720368547758)
OR EXISTS(SELECT 1 FROM fills WHERE quantity>92233720368547758)
OR EXISTS(SELECT 1 FROM paired_fills WHERE quantity>92233720368547758)
OR EXISTS(SELECT 1 FROM trade_prices WHERE quantity>92233720368547758)
THEN 0 ELSE 1 END;
UPDATE orders SET quantity=quantity*100,remaining=remaining*100;
UPDATE fills SET quantity=quantity*100;
UPDATE paired_fills SET quantity=quantity*100;
UPDATE trade_prices SET quantity=quantity*100;
DROP VIEW position_units;
CREATE VIEW position_units AS
SELECT p.account,p.market,p.outcome,p.available*1000000+COALESCE(r.micros,0) AS available,
p.reserved*10000 AS reserved,p.phase,p.payout_per_share
FROM position_sizes p LEFT JOIN position_remainders r USING(account,market,outcome);