From 1ae9dd5d35b816213f77722b029b609a6403053e Mon Sep 17 00:00:00 2001 From: Renee Tso <8248583+rtso@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:02:27 -0700 Subject: [PATCH] view (#485) --- .../down.sql | 18 ++++++++++++++++++ .../up.sql | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 rust/processor/src/db/postgres/migrations/2024-08-16-213505_fix_collections_view/down.sql create mode 100644 rust/processor/src/db/postgres/migrations/2024-08-16-213505_fix_collections_view/up.sql diff --git a/rust/processor/src/db/postgres/migrations/2024-08-16-213505_fix_collections_view/down.sql b/rust/processor/src/db/postgres/migrations/2024-08-16-213505_fix_collections_view/down.sql new file mode 100644 index 000000000..5e5320207 --- /dev/null +++ b/rust/processor/src/db/postgres/migrations/2024-08-16-213505_fix_collections_view/down.sql @@ -0,0 +1,18 @@ +-- This file should undo anything in `up.sql` +CREATE OR REPLACE VIEW current_collection_ownership_v2_view as +select owner_address, + creator_address, + collection_name, + b.collection_id, + max(a.last_transaction_version) as last_transaction_version, + count(distinct a.token_data_id) as distinct_tokens, + min(c.uri) as collection_uri, + min(token_uri) as single_token_uri +from current_token_ownerships_v2 a + join token_datas_v2 b on a.token_data_id = b.token_data_id + join current_collections_v2 c on b.collection_id = c.collection_id +where amount > 0 +group by 1, + 2, + 3, + 4; \ No newline at end of file diff --git a/rust/processor/src/db/postgres/migrations/2024-08-16-213505_fix_collections_view/up.sql b/rust/processor/src/db/postgres/migrations/2024-08-16-213505_fix_collections_view/up.sql new file mode 100644 index 000000000..0fd2cc736 --- /dev/null +++ b/rust/processor/src/db/postgres/migrations/2024-08-16-213505_fix_collections_view/up.sql @@ -0,0 +1,18 @@ +-- Your SQL goes here +CREATE OR REPLACE VIEW current_collection_ownership_v2_view as +select owner_address, + creator_address, + collection_name, + b.collection_id, + max(a.last_transaction_version) as last_transaction_version, + count(distinct a.token_data_id) as distinct_tokens, + min(c.uri) as collection_uri, + min(token_uri) as single_token_uri +from current_token_ownerships_v2 a + join current_token_datas_v2 b on a.token_data_id = b.token_data_id + join current_collections_v2 c on b.collection_id = c.collection_id +where amount > 0 +group by 1, + 2, + 3, + 4; \ No newline at end of file