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

Doing price conversions on the SQL-level #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
90 changes: 44 additions & 46 deletions migrations/2023-04-27-141730_currency-fixes/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ create view analytics_tmp.affiliate_earnings_monthly as
and nft_contract_id <> 'deadmau5.mintbase1.near'
) e
group by date_trunc, receiver_id, currency
order by date_trunc, receiver_id, currency
;
order by date_trunc, receiver_id, currency;

create view analytics_tmp.affiliate_earnings_yearly as
select
Expand All @@ -92,50 +91,49 @@ create view analytics_tmp.affiliate_earnings_yearly as
and nft_contract_id <> 'deadmau5.mintbase1.near'
) e
group by date_trunc, receiver_id, currency
order by date_trunc, receiver_id, currency
;
order by date_trunc, receiver_id, currency;

-- recreate active listings by contract view
create view mb_views.active_listings_by_contract as
select
c.id as nft_contract_id,
c.base_uri,
cl.price,
cl.currency,
cl.created_at,
cl.metadata_id,
cl.token_id,
cl.market_id,
cl.approval_id,
cl.listed_by,
tl.total_listings,
cmd.title,
cmd.media
from nft_contracts c
left join lateral (
select distinct on (l.metadata_id)
l.price,
l.currency,
l.created_at,
l.token_id,
l.metadata_id,
l.market_id,
l.approval_id,
l.listed_by
from nft_listings l
where l.nft_contract_id = c.id and l.unlisted_at is null and l.accepted_at is null and l.invalidated_at is null
order by l.metadata_id, l.created_at desc
limit 3
) cl on true
left join lateral (
select count(*) as total_listings
from nft_listings l
where l.nft_contract_id = c.id and l.unlisted_at is null and l.accepted_at is null and l.invalidated_at is null
) tl on true
left join lateral (
select m.title, m.media -- future! select media type, other ref json fields of interest
from nft_metadata m
where cl.metadata_id = m.id and c.id = m.nft_contract_id
limit 1
) cmd on true
where cl.price is not null; -- omit null lateral appendages
select
c.id as nft_contract_id,
c.base_uri,
cl.price,
cl.currency,
cl.created_at,
cl.metadata_id,
cl.token_id,
cl.market_id,
cl.approval_id,
cl.listed_by,
tl.total_listings,
cmd.title,
cmd.media
from nft_contracts c
left join lateral (
select distinct on (l.metadata_id)
l.price,
l.currency,
l.created_at,
l.token_id,
l.metadata_id,
l.market_id,
l.approval_id,
l.listed_by
from nft_listings l
where l.nft_contract_id = c.id and l.unlisted_at is null and l.accepted_at is null and l.invalidated_at is null
order by l.metadata_id, l.created_at desc
limit 3
) cl on true
left join lateral (
select count(*) as total_listings
from nft_listings l
where l.nft_contract_id = c.id and l.unlisted_at is null and l.accepted_at is null and l.invalidated_at is null
) tl on true
left join lateral (
select m.title, m.media -- future! select media type, other ref json fields of interest
from nft_metadata m
where cl.metadata_id = m.id and c.id = m.nft_contract_id
limit 1
) cmd on true
where cl.price is not null; -- omit null lateral appendages
Loading