diff --git a/warehouse/dbt/models/lens_sources.yml b/warehouse/dbt/models/lens_sources.yml index bbe14aea2..3153a712a 100644 --- a/warehouse/dbt/models/lens_sources.yml +++ b/warehouse/dbt/models/lens_sources.yml @@ -1,7 +1,7 @@ sources: - name: lens - database: lens-public-data - schema: v2_polygon + database: opensource-observer + schema: lens_v2_polygon tables: - name: lens_owners identifier: profile_ownership_history diff --git a/warehouse/dbt/models/staging/lens/stg_lens__owners.sql b/warehouse/dbt/models/staging/lens/stg_lens__owners.sql new file mode 100644 index 000000000..e5b7c35b1 --- /dev/null +++ b/warehouse/dbt/models/staging/lens/stg_lens__owners.sql @@ -0,0 +1,17 @@ +{# + Get the latest owners +#} + +WITH lens_owners_ordered AS ( + SELECT + *, + ROW_NUMBER() OVER (PARTITION BY profile_id ORDER BY block_number DESC) AS rn + FROM {{ source("lens", "lens_owners") }} +) + +SELECT + profile_id AS profile_id, + owned_by AS owned_by +FROM lens_owners_ordered +WHERE rn = 1 +ORDER BY profile_id diff --git a/warehouse/dbt/models/staging/lens/stg_lens__profiles.sql b/warehouse/dbt/models/staging/lens/stg_lens__profiles.sql index 62f5b6f35..4cd94f769 100644 --- a/warehouse/dbt/models/staging/lens/stg_lens__profiles.sql +++ b/warehouse/dbt/models/staging/lens/stg_lens__profiles.sql @@ -2,29 +2,10 @@ Get all profile_ids mapped to the owner address and profile metadata #} -WITH lens_owners_ordered AS ( - SELECT - *, - ROW_NUMBER() OVER (PARTITION BY profile_id ORDER BY block_number DESC) AS rn - FROM {{ source("lens", "lens_owners") }} -), - -lens_latest_owner AS ( - SELECT - profile_id AS profile_id, - owned_by AS owned_by - FROM lens_owners_ordered - WHERE rn = 1 - ORDER BY profile_id -) - SELECT profiles.profile_id AS profile_id, profiles.name AS full_name, profiles.bio AS bio, profiles.profile_picture_snapshot_location_url AS profile_picture_url, - profiles.cover_picture_snapshot_location_url AS cover_picture_url, - owners.owned_by AS owner + profiles.cover_picture_snapshot_location_url AS cover_picture_url FROM {{ source("lens", "lens_profiles") }} AS profiles -INNER JOIN lens_latest_owner AS owners - ON profiles.profile_id = owners.profile_id