From 3ed59022cb9345f61e9b24986ea74576a05d3364 Mon Sep 17 00:00:00 2001 From: aubrey Date: Wed, 24 Jul 2024 18:12:12 -0700 Subject: [PATCH 1/4] pindexer: repair SQL syntax for create type/create domain --- crates/bin/pindexer/src/dex/dex.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bin/pindexer/src/dex/dex.sql b/crates/bin/pindexer/src/dex/dex.sql index 72ff858a6e..e23d37e532 100644 --- a/crates/bin/pindexer/src/dex/dex.sql +++ b/crates/bin/pindexer/src/dex/dex.sql @@ -9,13 +9,17 @@ -- that given an `penumbra_asset::asset::Id`, we always know exactly how to filter -- tables, rather than needing to do a join with another table. -CREATE DOMAIN IF NOT EXISTS Amount AS NUMERIC(39, 0) NOT NULL; +DROP TYPE IF EXISTS Value CASCADE; +DROP DOMAIN IF EXISTS Amount; + +CREATE DOMAIN Amount AS NUMERIC(39, 0) NOT NULL; CREATE TYPE Value AS ( amount Amount, - asset BYTEA NOT NULL + asset BYTEA ); + -- Keeps track of changes to the dex's value circuit breaker. CREATE TABLE IF NOT EXISTS dex_value_circuit_breaker_change ( -- The asset being moved into or out of the dex. From c8966bbfc55acadfc02beb7e970456e0d95b7a99 Mon Sep 17 00:00:00 2001 From: Conor Schaefer Date: Wed, 24 Jul 2024 18:38:16 -0700 Subject: [PATCH 2/4] dev: add sqlfluff to dev env for linting Not wired up to CI yet, but has proven useful interactively while debugging #4759. --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 55edf69204..b9a2628ed1 100644 --- a/flake.nix +++ b/flake.nix @@ -129,6 +129,7 @@ protobuf rocksdb rsync + sqlfluff ]; shellHook = '' export LIBCLANG_PATH=${LIBCLANG_PATH} From ad3a4d95bd6c9e10be6674ed3b6abb6f50b245c7 Mon Sep 17 00:00:00 2001 From: Lucas Meier Date: Wed, 24 Jul 2024 18:51:38 -0700 Subject: [PATCH 3/4] Fix more SQL definition typos --- crates/bin/pindexer/src/dex/dex.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bin/pindexer/src/dex/dex.sql b/crates/bin/pindexer/src/dex/dex.sql index e23d37e532..894cc3b506 100644 --- a/crates/bin/pindexer/src/dex/dex.sql +++ b/crates/bin/pindexer/src/dex/dex.sql @@ -33,14 +33,14 @@ CREATE TABLE IF NOT EXISTS dex_value_circuit_breaker_change ( -- One step of an execution trace. CREATE TABLE IF NOT EXISTS trace_step ( id SERIAL PRIMARY KEY, - value Value, + value Value ); -- A single trace, showing what a small amount of an input asset was exchanged for. CREATE TABLE IF NOT EXISTS trace ( id SERIAL PRIMARY KEY, step_start INTEGER REFERENCES trace_step(id), - step_end INTEGER REFERENCES trace_step(id), + step_end INTEGER REFERENCES trace_step(id) ); --- Represents instances where arb executions happened. @@ -48,6 +48,6 @@ CREATE TABLE IF NOT EXISTS arb ( height BIGINT PRIMARY KEY, input Value, output Value, - trace_start INTEGER REFERENCES arb_traces(id), - trace_end INTEGER REFERENCES arb_traces(id), + trace_start INTEGER REFERENCES trace(id), + trace_end INTEGER REFERENCES trace(id) ); From 4c87381d24cf2f3140fdef717c287a95ec60d450 Mon Sep 17 00:00:00 2001 From: Lucas Meier Date: Wed, 24 Jul 2024 19:15:13 -0700 Subject: [PATCH 4/4] Correctly handle the multi statement sql file --- crates/bin/pindexer/src/dex/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bin/pindexer/src/dex/mod.rs b/crates/bin/pindexer/src/dex/mod.rs index 1d1910c78a..18884bbc96 100644 --- a/crates/bin/pindexer/src/dex/mod.rs +++ b/crates/bin/pindexer/src/dex/mod.rs @@ -207,9 +207,9 @@ impl AppView for Component { dbtx: &mut PgTransaction, _app_state: &serde_json::Value, ) -> anyhow::Result<()> { - sqlx::query(include_str!("dex.sql")) - .execute(dbtx.as_mut()) - .await?; + for statement in include_str!("dex.sql").split(";") { + sqlx::query(statement).execute(dbtx.as_mut()).await?; + } Ok(()) }