Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pindexer: repair SQL syntax for create type/create domain #4760

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions crates/bin/pindexer/src/dex/dex.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the NOT NULL constraint intended here previously is critical, this could be refactored with something like CREATE DOMAIN Asset AS BYTEA NOT NULL; but that might cause translation issues & require a bit more work that this

);


-- 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.
Expand All @@ -29,21 +33,21 @@ 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.
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)
);
6 changes: 3 additions & 3 deletions crates/bin/pindexer/src/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
protobuf
rocksdb
rsync
sqlfluff
];
shellHook = ''
export LIBCLANG_PATH=${LIBCLANG_PATH}
Expand Down
Loading