Browse Source

Use dprint's SQL plugin to format SQL files

With the more resilient start-up behaviour, we can now reformat
our SQL files without the application crashing.
chore/sql-format
Thomas Eizinger 3 years ago
parent
commit
ff5708e1bc
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 68
      daemon/migrations/20210903050345_create_cfd_and_order_tables.sql
  2. 14
      daemon/migrations/20211025050345_rename_term_to_settlement_time_interval.sql
  3. 5
      daemon/migrations/20211207035936_add-fee-to-order.sql
  4. 37
      daemon/migrations/20211208000000_associate_counterpart_identity_with_cfd.sql
  5. 53
      daemon/migrations/20211210000000_remove-order-from-database.sql
  6. 49
      daemon/migrations/20211213000000_remove-oracle_event_id_from_cfd.sql
  7. 3
      daemon/migrations/20211214055426_replace-origin-with-role.sql
  8. 8
      dprint.json

68
daemon/migrations/20210903050345_create_cfd_and_order_tables.sql

@ -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)
);

14
daemon/migrations/20211025050345_rename_term_to_settlement_time_interval.sql

@ -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;

5
daemon/migrations/20211207035936_add-fee-to-order.sql

@ -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;

37
daemon/migrations/20211208000000_associate_counterpart_identity_with_cfd.sql

@ -1,25 +1,18 @@
-- Add migration script here
drop table cfd_states;
drop table cfds;
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,
counterparty text not null,
foreign key (order_id) references orders (id)
DROP TABLE cfd_states;
DROP TABLE cfds;
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,
counterparty 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)
);

53
daemon/migrations/20211210000000_remove-order-from-database.sql

@ -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)
);

49
daemon/migrations/20211213000000_remove-oracle_event_id_from_cfd.sql

@ -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)
);

3
daemon/migrations/20211214055426_replace-origin-with-role.sql

@ -1 +1,2 @@
ALTER TABLE cfds RENAME COLUMN origin TO role;
ALTER TABLE
cfds RENAME COLUMN origin TO role;

8
dprint.json

@ -7,13 +7,17 @@
"wrap_comments": true,
"comment_width": 120
},
"includes": ["**/*.{md,rs,toml,ts,tsx,js,json}"],
"sql": {
"uppercase": true
},
"includes": ["**/*.{md,rs,toml,ts,tsx,js,json,sql}"],
"excludes": ["**/target", "**/sqlx-data.json", "maker-frontend/dist", "taker-frontend/dist", "**/node_modules"],
"plugins": [
"https://plugins.dprint.dev/markdown-0.9.2.wasm",
"https://plugins.dprint.dev/rustfmt-0.4.0.exe-plugin@c6bb223ef6e5e87580177f6461a0ab0554ac9ea6b54f78ea7ae8bf63b14f5bc2",
"https://plugins.dprint.dev/toml-0.4.0.wasm",
"https://plugins.dprint.dev/typescript-0.35.0.wasm",
"https://plugins.dprint.dev/json-0.7.2.wasm"
"https://plugins.dprint.dev/json-0.7.2.wasm",
"https://plugins.dprint.dev/sql-0.1.1.wasm"
]
}

Loading…
Cancel
Save