migrations: add margin info columns to nav table

This commit is contained in:
c9s 2022-05-03 14:54:16 +08:00
parent b00c9f0c0d
commit 816f05cd88
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 38 additions and 11 deletions

View File

@ -2,21 +2,21 @@
-- +begin -- +begin
CREATE TABLE nav_history_details CREATE TABLE nav_history_details
( (
gid bigint unsigned auto_increment PRIMARY KEY, gid bigint unsigned auto_increment PRIMARY KEY,
exchange VARCHAR(30) NOT NULL, exchange VARCHAR(30) NOT NULL,
subaccount VARCHAR(30) NOT NULL, subaccount VARCHAR(30) NOT NULL,
time DATETIME(3) NOT NULL, time DATETIME(3) NOT NULL,
currency VARCHAR(12) NOT NULL, currency VARCHAR(12) NOT NULL,
balance_in_usd DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL, balance_in_usd DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,
balance_in_btc DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL, balance_in_btc DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,
balance DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL, balance DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,
available DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL, available DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,
locked DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL locked DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL
); );
-- +end -- +end
-- +begin -- +begin
CREATE INDEX idx_nav_history_details CREATE INDEX idx_nav_history_details
on nav_history_details(time, currency, exchange); on nav_history_details (time, currency, exchange);
-- +end -- +end
-- +down -- +down

View File

@ -0,0 +1,19 @@
-- +up
-- +begin
ALTER TABLE `nav_history_details`
ADD COLUMN `net_asset` DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,
ADD COLUMN `borrowed` DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL,
ADD COLUMN `price_in_usd` DECIMAL(32, 8) UNSIGNED DEFAULT 0.00000000 NOT NULL
;
-- +end
-- +down
-- +begin
ALTER TABLE `nav_history_details`
DROP COLUMN `net_asset`,
DROP COLUMN `borrowed`,
DROP COLUMN `price_in_usd`
;
-- +end

View File

@ -0,0 +1,8 @@
-- +up
ALTER TABLE `nav_history_details` ADD COLUMN `borrowed` DECIMAL UNSIGNED DEFAULT 0.00000000 NOT NULL;
ALTER TABLE `nav_history_details` ADD COLUMN `net_asset` DECIMAL UNSIGNED DEFAULT 0.00000000 NOT NULL;
ALTER TABLE `nav_history_details` ADD COLUMN `price_in_usd` DECIMAL UNSIGNED DEFAULT 0.00000000 NOT NULL;
-- +down
-- we can not rollback alter table change in sqlite
SELECT 1;