Browse Source
With the more resilient start-up behaviour, we can now reformat our SQL files without the application crashing.chore/sql-format
8 changed files with 108 additions and 129 deletions
@ -1,43 +1,33 @@ |
|||
-- todo: Decimal is had to deserialize as number so we use text |
|||
create table if not exists orders |
|||
( |
|||
id integer primary key autoincrement, |
|||
uuid text unique not null, |
|||
trading_pair text not null, |
|||
position text not null, |
|||
initial_price text not null, |
|||
min_quantity text not null, |
|||
max_quantity text not null, |
|||
leverage integer not null, |
|||
liquidation_price text not null, |
|||
creation_timestamp_seconds integer not null, |
|||
creation_timestamp_nanoseconds integer not null, |
|||
term_seconds integer not null, |
|||
term_nanoseconds integer not null, |
|||
origin text not null, |
|||
oracle_event_id text not null |
|||
CREATE TABLE IF NOT EXISTS orders ( |
|||
id integer PRIMARY KEY autoincrement, |
|||
uuid text UNIQUE NOT NULL, |
|||
trading_pair text NOT NULL, |
|||
position text NOT NULL, |
|||
initial_price text NOT NULL, |
|||
min_quantity text NOT NULL, |
|||
max_quantity text NOT NULL, |
|||
leverage integer NOT NULL, |
|||
liquidation_price text NOT NULL, |
|||
creation_timestamp_seconds integer NOT NULL, |
|||
creation_timestamp_nanoseconds integer NOT NULL, |
|||
term_seconds integer NOT NULL, |
|||
term_nanoseconds integer NOT NULL, |
|||
origin text NOT NULL, |
|||
oracle_event_id text NOT NULL |
|||
); |
|||
|
|||
create unique index if not exists orders_uuid |
|||
on orders (uuid); |
|||
|
|||
create table if not exists cfds |
|||
( |
|||
id integer primary key autoincrement, |
|||
order_id integer unique not null, |
|||
order_uuid text unique not null, |
|||
quantity_usd text not null, |
|||
|
|||
foreign key (order_id) references orders (id) |
|||
CREATE UNIQUE INDEX IF NOT EXISTS orders_uuid ON orders (uuid); |
|||
CREATE TABLE IF NOT EXISTS cfds ( |
|||
id integer PRIMARY KEY autoincrement, |
|||
order_id integer UNIQUE NOT NULL, |
|||
order_uuid text UNIQUE NOT NULL, |
|||
quantity_usd text NOT NULL, |
|||
FOREIGN KEY (order_id) REFERENCES orders (id) |
|||
); |
|||
|
|||
create unique index if not exists cfd_order_uuid |
|||
on cfds (order_uuid); |
|||
|
|||
create table if not exists cfd_states |
|||
( |
|||
id integer primary key autoincrement, |
|||
cfd_id integer not null, |
|||
state text not null, |
|||
foreign key (cfd_id) references cfds (id) |
|||
CREATE UNIQUE INDEX IF NOT EXISTS cfd_order_uuid ON cfds (order_uuid); |
|||
CREATE TABLE IF NOT EXISTS cfd_states ( |
|||
id integer PRIMARY KEY autoincrement, |
|||
cfd_id integer NOT NULL, |
|||
state text NOT NULL, |
|||
FOREIGN KEY (cfd_id) REFERENCES cfds (id) |
|||
); |
|||
|
@ -1,8 +1,6 @@ |
|||
alter table orders |
|||
rename column term_seconds to settlement_time_interval_seconds; |
|||
|
|||
alter table orders |
|||
drop column creation_timestamp_nanoseconds; |
|||
|
|||
alter table orders |
|||
drop column term_nanoseconds; |
|||
ALTER TABLE |
|||
orders RENAME COLUMN term_seconds TO settlement_time_interval_seconds; |
|||
ALTER TABLE |
|||
orders DROP COLUMN creation_timestamp_nanoseconds; |
|||
ALTER TABLE |
|||
orders DROP COLUMN term_nanoseconds; |
|||
|
@ -1,2 +1,5 @@ |
|||
-- Add migration script here |
|||
ALTER TABLE orders ADD COLUMN fee_rate not null default 1; |
|||
ALTER TABLE |
|||
orders |
|||
ADD |
|||
COLUMN fee_rate NOT NULL DEFAULT 1; |
|||
|
@ -1,31 +1,26 @@ |
|||
drop table cfd_states; |
|||
drop table cfds; |
|||
drop table orders; |
|||
|
|||
create table if not exists cfds |
|||
( |
|||
id integer primary key autoincrement, |
|||
uuid text unique not null, |
|||
trading_pair text not null, |
|||
position text not null, |
|||
initial_price text not null, |
|||
leverage integer not null, |
|||
liquidation_price text not null, |
|||
creation_timestamp_seconds integer not null, |
|||
settlement_time_interval_seconds integer not null, |
|||
origin text not null, |
|||
oracle_event_id text not null, |
|||
fee_rate integer not null, |
|||
quantity_usd text not null, |
|||
counterparty text not null |
|||
DROP TABLE cfd_states; |
|||
DROP TABLE cfds; |
|||
DROP TABLE orders; |
|||
CREATE TABLE IF NOT EXISTS cfds ( |
|||
id integer PRIMARY KEY autoincrement, |
|||
uuid text UNIQUE NOT NULL, |
|||
trading_pair text NOT NULL, |
|||
position text NOT NULL, |
|||
initial_price text NOT NULL, |
|||
leverage integer NOT NULL, |
|||
liquidation_price text NOT NULL, |
|||
creation_timestamp_seconds integer NOT NULL, |
|||
settlement_time_interval_seconds integer NOT NULL, |
|||
origin text NOT NULL, |
|||
oracle_event_id text NOT NULL, |
|||
fee_rate integer NOT NULL, |
|||
quantity_usd text NOT NULL, |
|||
counterparty text NOT NULL |
|||
); |
|||
|
|||
create unique index if not exists cfd_uuid on cfds (uuid); |
|||
|
|||
create table if not exists cfd_states |
|||
( |
|||
id integer primary key autoincrement, |
|||
cfd_id integer not null, |
|||
state text not null, |
|||
foreign key (cfd_id) references cfds (id) |
|||
CREATE UNIQUE INDEX IF NOT EXISTS cfd_uuid ON cfds (uuid); |
|||
CREATE TABLE IF NOT EXISTS cfd_states ( |
|||
id integer PRIMARY KEY autoincrement, |
|||
cfd_id integer NOT NULL, |
|||
state text NOT NULL, |
|||
FOREIGN KEY (cfd_id) REFERENCES cfds (id) |
|||
); |
|||
|
@ -1,29 +1,24 @@ |
|||
drop table cfd_states; |
|||
drop table cfds; |
|||
|
|||
create table if not exists cfds |
|||
( |
|||
id integer primary key autoincrement, |
|||
uuid text unique not null, |
|||
trading_pair text not null, |
|||
position text not null, |
|||
initial_price text not null, |
|||
leverage integer not null, |
|||
liquidation_price text not null, |
|||
creation_timestamp_seconds integer not null, |
|||
settlement_time_interval_seconds integer not null, |
|||
origin text not null, |
|||
fee_rate integer not null, |
|||
quantity_usd text not null, |
|||
counterparty text not null |
|||
DROP TABLE cfd_states; |
|||
DROP TABLE cfds; |
|||
CREATE TABLE IF NOT EXISTS cfds ( |
|||
id integer PRIMARY KEY autoincrement, |
|||
uuid text UNIQUE NOT NULL, |
|||
trading_pair text NOT NULL, |
|||
position text NOT NULL, |
|||
initial_price text NOT NULL, |
|||
leverage integer NOT NULL, |
|||
liquidation_price text NOT NULL, |
|||
creation_timestamp_seconds integer NOT NULL, |
|||
settlement_time_interval_seconds integer NOT NULL, |
|||
origin text NOT NULL, |
|||
fee_rate integer NOT NULL, |
|||
quantity_usd text NOT NULL, |
|||
counterparty text NOT NULL |
|||
); |
|||
|
|||
create unique index if not exists cfd_uuid on cfds (uuid); |
|||
|
|||
create table if not exists cfd_states |
|||
( |
|||
id integer primary key autoincrement, |
|||
cfd_id integer not null, |
|||
state text not null, |
|||
foreign key (cfd_id) references cfds (id) |
|||
CREATE UNIQUE INDEX IF NOT EXISTS cfd_uuid ON cfds (uuid); |
|||
CREATE TABLE IF NOT EXISTS cfd_states ( |
|||
id integer PRIMARY KEY autoincrement, |
|||
cfd_id integer NOT NULL, |
|||
state text NOT NULL, |
|||
FOREIGN KEY (cfd_id) REFERENCES cfds (id) |
|||
); |
|||
|
@ -1 +1,2 @@ |
|||
ALTER TABLE cfds RENAME COLUMN origin TO role; |
|||
ALTER TABLE |
|||
cfds RENAME COLUMN origin TO role; |
|||
|
Loading…
Reference in new issue