mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
add sqlite3 migrations
This commit is contained in:
parent
8cb77075d0
commit
007b679768
|
@ -19,5 +19,6 @@ CREATE TABLE `trades`
|
||||||
PRIMARY KEY (`gid`),
|
PRIMARY KEY (`gid`),
|
||||||
UNIQUE KEY `id` (`id`)
|
UNIQUE KEY `id` (`id`)
|
||||||
);
|
);
|
||||||
|
|
||||||
-- +down
|
-- +down
|
||||||
DROP TABLE `trades`;
|
DROP TABLE IF EXISTS `trades`;
|
||||||
|
|
20
migrations/sqlite3/20200721225616_trades.sql
Normal file
20
migrations/sqlite3/20200721225616_trades.sql
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
-- +up
|
||||||
|
CREATE TABLE `trades`
|
||||||
|
(
|
||||||
|
`gid` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`id` INTEGER,
|
||||||
|
`exchange` TEXT NOT NULL DEFAULT '',
|
||||||
|
`symbol` TEXT NOT NULL,
|
||||||
|
`price` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`quantity` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`quote_quantity` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`fee` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`fee_currency` VARCHAR(4) NOT NULL,
|
||||||
|
`is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
`is_maker` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
`side` VARCHAR(4) NOT NULL DEFAULT '',
|
||||||
|
`traded_at` DATETIME(3) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
DROP TABLE IF EXISTS `trades`;
|
9
migrations/sqlite3/20200819054742_trade_index.sql
Normal file
9
migrations/sqlite3/20200819054742_trade_index.sql
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
-- +up
|
||||||
|
CREATE INDEX trades_symbol ON trades(symbol);
|
||||||
|
CREATE INDEX trades_symbol_fee_currency ON trades(symbol, fee_currency, traded_at);
|
||||||
|
CREATE INDEX trades_traded_at_symbol ON trades(traded_at, symbol);
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
DROP INDEX trades_symbol ON trades;
|
||||||
|
DROP INDEX trades_symbol_fee_currency ON trades;
|
||||||
|
DROP INDEX trades_traded_at_symbol ON trades;
|
25
migrations/sqlite3/20201102222546_orders.sql
Normal file
25
migrations/sqlite3/20201102222546_orders.sql
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
-- +up
|
||||||
|
CREATE TABLE `orders`
|
||||||
|
(
|
||||||
|
`gid` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
|
`exchange` VARCHAR NOT NULL DEFAULT '',
|
||||||
|
-- order_id is the order id returned from the exchange
|
||||||
|
`order_id` INTEGER NOT NULL,
|
||||||
|
`client_order_id` VARCHAR NOT NULL DEFAULT '',
|
||||||
|
`order_type` VARCHAR NOT NULL,
|
||||||
|
`symbol` VARCHAR NOT NULL,
|
||||||
|
`status` VARCHAR NOT NULL,
|
||||||
|
`time_in_force` VARCHAR NOT NULL,
|
||||||
|
`price` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`stop_price` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`quantity` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`executed_quantity` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,
|
||||||
|
`side` VARCHAR NOT NULL DEFAULT '',
|
||||||
|
`is_working` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
`created_at` DATETIME(3) NOT NULL,
|
||||||
|
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
DROP TABLE IF EXISTS `orders`;
|
|
@ -0,0 +1,5 @@
|
||||||
|
-- +up
|
||||||
|
ALTER TABLE `trades` ADD COLUMN `order_id` INTEGER NOT NULL;
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
ALTER TABLE `trades` RENAME COLUMN `order_id` TO `order_id_deleted`;
|
19
migrations/sqlite3/20201105092857_trades_index_fix.sql
Normal file
19
migrations/sqlite3/20201105092857_trades_index_fix.sql
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
-- +up
|
||||||
|
DROP INDEX IF EXISTS trades_symbol;
|
||||||
|
DROP INDEX IF EXISTS trades_symbol_fee_currency;
|
||||||
|
DROP INDEX IF EXISTS trades_traded_at_symbol;
|
||||||
|
|
||||||
|
CREATE INDEX trades_symbol ON trades (exchange, symbol);
|
||||||
|
CREATE INDEX trades_symbol_fee_currency ON trades (exchange, symbol, fee_currency, traded_at);
|
||||||
|
CREATE INDEX trades_traded_at_symbol ON trades (exchange, traded_at, symbol);
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
DROP INDEX IF EXISTS trades_symbol ON trades;
|
||||||
|
DROP INDEX IF EXISTS trades_symbol_fee_currency ON trades;
|
||||||
|
DROP INDEX IF EXISTS trades_traded_at_symbol ON trades;
|
||||||
|
|
||||||
|
CREATE INDEX trades_symbol ON trades (symbol);
|
||||||
|
CREATE INDEX trades_symbol_fee_currency ON trades (symbol, fee_currency, traded_at);
|
||||||
|
CREATE INDEX trades_traded_at_symbol ON trades (traded_at, symbol);
|
||||||
|
|
||||||
|
|
7
migrations/sqlite3/20201105093056_orders_add_index.sql
Normal file
7
migrations/sqlite3/20201105093056_orders_add_index.sql
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
-- +up
|
||||||
|
CREATE INDEX orders_symbol ON orders (exchange, symbol);
|
||||||
|
CREATE UNIQUE INDEX orders_order_id ON orders (order_id, exchange);
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
DROP INDEX IF EXISTS orders_symbol;
|
||||||
|
DROP INDEX IF EXISTS orders_order_id;
|
44
migrations/sqlite3/20201106114742_klines.sql
Normal file
44
migrations/sqlite3/20201106114742_klines.sql
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
-- +up
|
||||||
|
-- +begin
|
||||||
|
CREATE TABLE `klines`
|
||||||
|
(
|
||||||
|
`gid` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`exchange` VARCHAR(10) NOT NULL,
|
||||||
|
`start_time` DATETIME(3) NOT NULL,
|
||||||
|
`end_time` DATETIME(3) NOT NULL,
|
||||||
|
`interval` VARCHAR(3) NOT NULL,
|
||||||
|
`symbol` VARCHAR(7) NOT NULL,
|
||||||
|
`open` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`high` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`low` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,
|
||||||
|
`volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,
|
||||||
|
`closed` BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
`last_trade_id` INT NOT NULL DEFAULT 0,
|
||||||
|
`num_trades` INT NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
CREATE INDEX `klines_end_time_symbol_interval` ON klines (`end_time`, `symbol`, `interval`);
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
CREATE TABLE `okex_klines` AS SELECT * FROM `klines` WHERE 0
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
CREATE TABLE `binance_klines` AS SELECT * FROM `klines` WHERE 0
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
CREATE TABLE `max_klines` AS SELECT * FROM `klines` WHERE 0
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
DROP INDEX IF EXISTS `klines_end_time_symbol_interval`;
|
||||||
|
DROP TABLE IF EXISTS `binance_klines`;
|
||||||
|
DROP TABLE IF EXISTS `okex_klines`;
|
||||||
|
DROP TABLE IF EXISTS `max_klines`;
|
||||||
|
DROP TABLE IF EXISTS `klines`;
|
||||||
|
|
5
migrations/sqlite3/20201211175751_fix_symbol_length.sql
Normal file
5
migrations/sqlite3/20201211175751_fix_symbol_length.sql
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
-- +up
|
||||||
|
SELECT 1;
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
SELECT 1;
|
9
migrations/sqlite3/20210118163847_fix_unique_index.sql
Normal file
9
migrations/sqlite3/20210118163847_fix_unique_index.sql
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
-- +up
|
||||||
|
-- +begin
|
||||||
|
CREATE UNIQUE INDEX `trade_unique_id` ON `trades` (`exchange`,`symbol`, `side`, `id`);
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
-- +begin
|
||||||
|
DROP INDEX IF EXISTS `trade_unique_id`;
|
||||||
|
-- +end
|
33
migrations/sqlite3/20210119232826_add_margin_columns.sql
Normal file
33
migrations/sqlite3/20210119232826_add_margin_columns.sql
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
-- +up
|
||||||
|
-- +begin
|
||||||
|
ALTER TABLE `trades` ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE;
|
||||||
|
-- +end
|
||||||
|
-- +begin
|
||||||
|
ALTER TABLE `trades` ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE;
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
ALTER TABLE `orders` ADD COLUMN `is_margin` BOOLEAN NOT NULL DEFAULT FALSE;
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
ALTER TABLE `orders` ADD COLUMN `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE;
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
ALTER TABLE `trades` RENAME COLUMN `is_margin` TO `is_margin_deleted`;
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
ALTER TABLE `trades` RENAME COLUMN `is_isolated` TO `is_isolated_deleted`;
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
ALTER TABLE `orders` RENAME COLUMN `is_margin` TO `is_margin_deleted`;
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
ALTER TABLE `orders` RENAME COLUMN `is_isolated` TO `is_isolated_deleted`;
|
||||||
|
-- +end
|
|
@ -0,0 +1,10 @@
|
||||||
|
-- +up
|
||||||
|
-- +begin
|
||||||
|
CREATE INDEX trades_price_quantity ON trades (order_id,price,quantity);
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
DROP INDEX trades_price_quantity;
|
||||||
|
-- +end
|
Loading…
Reference in New Issue
Block a user