diff --git a/warehouse/dbt/models/intermediate/directory/int_artifacts_by_collection.sql b/warehouse/dbt/models/intermediate/directory/int_artifacts_by_collection.sql new file mode 100644 index 000000000..583b2a29c --- /dev/null +++ b/warehouse/dbt/models/intermediate/directory/int_artifacts_by_collection.sql @@ -0,0 +1,15 @@ +select distinct + artifacts.artifact_id, + artifacts.artifact_source_id, + artifacts.artifact_source, + artifacts.artifact_namespace, + artifacts.artifact_name, + artifacts.artifact_url, + projects_by_collection.collection_id, + projects_by_collection.collection_source, + projects_by_collection.collection_namespace, + projects_by_collection.collection_name +from {{ ref('int_all_artifacts') }} as artifacts +left join {{ ref('int_projects_by_collection') }} as projects_by_collection + on artifacts.project_id = projects_by_collection.project_id +where projects_by_collection.collection_id is not null diff --git a/warehouse/dbt/models/intermediate/directory/int_artifacts_by_user.sql b/warehouse/dbt/models/intermediate/directory/int_artifacts_by_user.sql new file mode 100644 index 000000000..e324b22e7 --- /dev/null +++ b/warehouse/dbt/models/intermediate/directory/int_artifacts_by_user.sql @@ -0,0 +1,129 @@ +{# + This model is responsible for generating a many-to-many table + of artifacts associated with a user. This includes + both GitHub users and various onchain users. +#} + +with event_users as ( + select + from_artifact_source_id as artifact_source_id, + event_source as artifact_source, + from_artifact_namespace as artifact_namespace, + from_artifact_name as artifact_name, + from_artifact_source_id as user_source_id, + event_source as user_source, + from_artifact_type as user_type, + from_artifact_namespace as user_namespace, + from_artifact_name as user_name + from {{ ref("int_events") }} +), + +farcaster_users as ( + with farcaster as ( + select + first_time_addresses.address, + farcaster_addresses.fid as user_source_id, + 'FARCASTER' as user_source, + 'FARCASTER_USER' as user_type, + farcaster_profiles.username as user_name, + UPPER(first_time_addresses.chain_name) as chain_name + from {{ ref ("int_first_time_addresses") }} as first_time_addresses + inner join {{ ref ("stg_farcaster__addresses") }} as farcaster_addresses + on first_time_addresses.address = farcaster_addresses.address + inner join {{ ref ("stg_farcaster__profiles") }} as farcaster_profiles + on farcaster_addresses.fid = farcaster_profiles.farcaster_id + ) + + select + address as artifact_source_id, + chain_name as artifact_source, + address as artifact_name, + user_source_id, + user_source, + user_type, + user_name, + LOWER(chain_name) as artifact_namespace, + LOWER(user_source) as user_namespace + from farcaster +), + +lens_users as ( + with lens as ( + select + first_time_addresses.address, + lens_profiles.lens_profile_id as user_source_id, + 'LENS' as user_source, + 'LENS_USER' as user_type, + lens_profiles.full_name as user_name, + UPPER(first_time_addresses.chain_name) as chain_name + from {{ ref ("int_first_time_addresses") }} as first_time_addresses + inner join {{ ref ("stg_lens__owners") }} as lens_owners + on first_time_addresses.address = lens_owners.owned_by + inner join {{ ref ("stg_lens__profiles") }} as lens_profiles + on lens_owners.profile_id = lens_profiles.lens_profile_id + ) + + select + address as artifact_source_id, + chain_name as artifact_source, + address as artifact_name, + user_source_id, + user_source, + user_type, + user_name, + LOWER(chain_name) as artifact_namespace, + LOWER(user_source) as user_namespace + from lens +), + +all_normalized_users as ( + select + artifact_source_id, + artifact_source, + artifact_namespace, + artifact_name, + user_source_id, + user_source, + user_type, + user_namespace, + user_name + from event_users + union all + select + artifact_source_id, + artifact_source, + artifact_namespace, + artifact_name, + user_source_id, + user_source, + user_type, + user_namespace, + user_name + from farcaster_users + union all + select + artifact_source_id, + artifact_source, + artifact_namespace, + artifact_name, + user_source_id, + user_source, + user_type, + user_namespace, + user_name + from lens_users +) + +select distinct + {{ oso_id("artifact_source", "artifact_source_id") }} as artifact_id, + artifact_source_id, + artifact_source, + artifact_namespace, + artifact_name, + {{ oso_id("user_source", "user_source_id") }} as user_id, + user_source_id, + user_source, + user_type, + user_namespace, + user_name +from all_normalized_users diff --git a/warehouse/dbt/models/marts/directory/artifacts_by_collection_v1.sql b/warehouse/dbt/models/marts/directory/artifacts_by_collection_v1.sql new file mode 100644 index 000000000..703c294d1 --- /dev/null +++ b/warehouse/dbt/models/marts/directory/artifacts_by_collection_v1.sql @@ -0,0 +1,22 @@ +{{ + config(meta = { + 'sync_to_db': True, + 'index': { + 'idx_collection_id': ["collection_id"], + 'idx_collection_name': ["collection_source", "collection_namespace", "collection_name"], + 'idx_artifact_id': ["artifact_id"], + } + }) +}} + +select + artifact_id, + artifact_source_id, + artifact_source, + artifact_namespace, + artifact_name, + collection_id, + collection_source, + collection_namespace, + collection_name +from {{ ref('int_artifacts_by_collection') }} diff --git a/warehouse/dbt/models/marts/directory/artifacts_by_user_v1.sql b/warehouse/dbt/models/marts/directory/artifacts_by_user_v1.sql new file mode 100644 index 000000000..12fac549a --- /dev/null +++ b/warehouse/dbt/models/marts/directory/artifacts_by_user_v1.sql @@ -0,0 +1,24 @@ +{{ + config(meta = { + 'sync_to_db': True, + 'index': { + 'idx_user_id': ["user_id"], + 'idx_user_name': ["user_source", "user_namespace", "user_name"], + 'idx_artifact_id': ["artifact_id"], + } + }) +}} + +select + artifact_id, + artifact_source_id, + artifact_source, + artifact_namespace, + artifact_name, + user_id, + user_source_id, + user_source, + user_type, + user_namespace, + user_name +from {{ ref('int_artifacts_by_user') }} diff --git a/warehouse/dbt/models/staging/lens/stg_lens__owners.sql b/warehouse/dbt/models/staging/lens/stg_lens__owners.sql index ae9ccbfa6..401f267df 100644 --- a/warehouse/dbt/models/staging/lens/stg_lens__owners.sql +++ b/warehouse/dbt/models/staging/lens/stg_lens__owners.sql @@ -12,7 +12,7 @@ with lens_owners_ordered as ( select lens_owners_ordered.profile_id, - lens_owners_ordered.owned_by + LOWER(lens_owners_ordered.owned_by) as owned_by from lens_owners_ordered where row_number = 1 order by lens_owners_ordered.profile_id