From ff5708e1bc8b1e9197ba7eb5b054f5cadfcffb4b Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 14 Dec 2021 20:23:03 +1100 Subject: [PATCH] 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. --- ...0903050345_create_cfd_and_order_tables.sql | 68 ++++++++----------- ...ename_term_to_settlement_time_interval.sql | 14 ++-- .../20211207035936_add-fee-to-order.sql | 5 +- ...ssociate_counterpart_identity_with_cfd.sql | 37 ++++------ ...11210000000_remove-order-from-database.sql | 53 +++++++-------- ...000000_remove-oracle_event_id_from_cfd.sql | 49 ++++++------- ...0211214055426_replace-origin-with-role.sql | 3 +- dprint.json | 8 ++- 8 files changed, 108 insertions(+), 129 deletions(-) diff --git a/daemon/migrations/20210903050345_create_cfd_and_order_tables.sql b/daemon/migrations/20210903050345_create_cfd_and_order_tables.sql index f9a08f3..cd01ff7 100644 --- a/daemon/migrations/20210903050345_create_cfd_and_order_tables.sql +++ b/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) ); diff --git a/daemon/migrations/20211025050345_rename_term_to_settlement_time_interval.sql b/daemon/migrations/20211025050345_rename_term_to_settlement_time_interval.sql index d0eadac..557a28f 100644 --- a/daemon/migrations/20211025050345_rename_term_to_settlement_time_interval.sql +++ b/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; diff --git a/daemon/migrations/20211207035936_add-fee-to-order.sql b/daemon/migrations/20211207035936_add-fee-to-order.sql index c5c4114..e08705b 100644 --- a/daemon/migrations/20211207035936_add-fee-to-order.sql +++ b/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; diff --git a/daemon/migrations/20211208000000_associate_counterpart_identity_with_cfd.sql b/daemon/migrations/20211208000000_associate_counterpart_identity_with_cfd.sql index eb1f57d..a88a24d 100644 --- a/daemon/migrations/20211208000000_associate_counterpart_identity_with_cfd.sql +++ b/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) ); - diff --git a/daemon/migrations/20211210000000_remove-order-from-database.sql b/daemon/migrations/20211210000000_remove-order-from-database.sql index 44f39ac..8125758 100644 --- a/daemon/migrations/20211210000000_remove-order-from-database.sql +++ b/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) ); diff --git a/daemon/migrations/20211213000000_remove-oracle_event_id_from_cfd.sql b/daemon/migrations/20211213000000_remove-oracle_event_id_from_cfd.sql index 61f8fc3..224e646 100644 --- a/daemon/migrations/20211213000000_remove-oracle_event_id_from_cfd.sql +++ b/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) ); diff --git a/daemon/migrations/20211214055426_replace-origin-with-role.sql b/daemon/migrations/20211214055426_replace-origin-with-role.sql index 73fd0ad..0d88c47 100644 --- a/daemon/migrations/20211214055426_replace-origin-with-role.sql +++ b/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; diff --git a/dprint.json b/dprint.json index 1a07a93..5cea00a 100644 --- a/dprint.json +++ b/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" ] }