diff --git a/Circles.Index.CirclesViews/DatabaseSchema.cs b/Circles.Index.CirclesViews/DatabaseSchema.cs
index b5d3e61..d461563 100644
--- a/Circles.Index.CirclesViews/DatabaseSchema.cs
+++ b/Circles.Index.CirclesViews/DatabaseSchema.cs
@@ -152,67 +152,77 @@ UNION ALL
])
{
SqlMigrationItem = new SqlMigrationItem(@"
- create or replace view ""V_CrcV2_Avatars"" as
- with ""avatars"" as (
- select ""blockNumber"",
- ""timestamp"",
- ""transactionIndex"",
- ""logIndex"",
- ""transactionHash"",
- 'organization' as ""type"",
- null as ""invitedBy"",
- ""organization"" as ""avatar"",
- null as ""tokenId"",
- ""name""
- from ""CrcV2_RegisterOrganization""
- union all
- select ""blockNumber"",
- ""timestamp"",
- ""transactionIndex"",
- ""logIndex"",
- ""transactionHash"",
- 'group' as ""type"",
- null as ""invitedBy"",
- ""group"" as ""avatar"",
- ""group"" as ""tokenId"",
- ""name""
- from ""CrcV2_RegisterGroup""
- union all
- select ""blockNumber"",
- ""timestamp"",
- ""transactionIndex"",
- ""logIndex"",
- ""transactionHash"",
- 'human' as ""type"",
- null as ""invitedBy"",
- ""avatar"",
- ""avatar"" as ""tokenId"",
- null as ""name""
- from ""CrcV2_RegisterHuman""
- union all
- select ""blockNumber"",
- ""timestamp"",
- ""transactionIndex"",
- ""logIndex"",
- ""transactionHash"",
- 'human' as ""type"",
- ""inviter"" as ""invitedBy"",
- ""invited"",
- ""invited"" as ""tokenId"",
- null as ""name""
- from ""CrcV2_InviteHuman""
+ create or replace view public.""V_CrcV2_Avatars""
+ (""blockNumber"", timestamp, ""transactionIndex"", ""logIndex"", ""transactionHash"", type, ""invitedBy"", avatar,
+ ""tokenId"", name, ""cidV0Digest"")
+ as
+ WITH avatars AS (
+ SELECT ""CrcV2_RegisterOrganization"".""blockNumber"",
+ ""CrcV2_RegisterOrganization"".""timestamp"",
+ ""CrcV2_RegisterOrganization"".""transactionIndex"",
+ ""CrcV2_RegisterOrganization"".""logIndex"",
+ ""CrcV2_RegisterOrganization"".""transactionHash"",
+ 'organization'::text AS type,
+ NULL::text AS ""invitedBy"",
+ ""CrcV2_RegisterOrganization"".organization AS avatar,
+ NULL::text AS ""tokenId"",
+ ""CrcV2_RegisterOrganization"".name
+ FROM ""CrcV2_RegisterOrganization""
+ UNION ALL
+ SELECT ""CrcV2_RegisterGroup"".""blockNumber"",
+ ""CrcV2_RegisterGroup"".""timestamp"",
+ ""CrcV2_RegisterGroup"".""transactionIndex"",
+ ""CrcV2_RegisterGroup"".""logIndex"",
+ ""CrcV2_RegisterGroup"".""transactionHash"",
+ 'group'::text AS type,
+ NULL::text AS ""invitedBy"",
+ ""CrcV2_RegisterGroup"".""group"" AS avatar,
+ ""CrcV2_RegisterGroup"".""group"" AS ""tokenId"",
+ ""CrcV2_RegisterGroup"".name
+ FROM ""CrcV2_RegisterGroup""
+ UNION ALL
+ SELECT ""CrcV2_RegisterHuman"".""blockNumber"",
+ ""CrcV2_RegisterHuman"".""timestamp"",
+ ""CrcV2_RegisterHuman"".""transactionIndex"",
+ ""CrcV2_RegisterHuman"".""logIndex"",
+ ""CrcV2_RegisterHuman"".""transactionHash"",
+ 'human'::text AS type,
+ NULL::text AS ""invitedBy"",
+ ""CrcV2_RegisterHuman"".avatar,
+ ""CrcV2_RegisterHuman"".avatar AS ""tokenId"",
+ NULL::text AS name
+ FROM ""CrcV2_RegisterHuman""
+ UNION ALL
+ SELECT ""CrcV2_InviteHuman"".""blockNumber"",
+ ""CrcV2_InviteHuman"".""timestamp"",
+ ""CrcV2_InviteHuman"".""transactionIndex"",
+ ""CrcV2_InviteHuman"".""logIndex"",
+ ""CrcV2_InviteHuman"".""transactionHash"",
+ 'human'::text AS type,
+ ""CrcV2_InviteHuman"".inviter AS ""invitedBy"",
+ ""CrcV2_InviteHuman"".invited,
+ ""CrcV2_InviteHuman"".invited AS ""tokenId"",
+ NULL::text AS name
+ FROM ""CrcV2_InviteHuman""
)
- select a.*, cid.""cidV0Digest""
- from ""avatars"" a
- left join (
+ SELECT a.""blockNumber"",
+ a.""timestamp"",
+ a.""transactionIndex"",
+ a.""logIndex"",
+ a.""transactionHash"",
+ a.type,
+ a.""invitedBy"",
+ a.avatar,
+ a.""tokenId"",
+ a.name,
+ cid.""cidV0Digest""
+ FROM avatars a
+ LEFT JOIN (
SELECT cid_1.avatar,
- cid_1.""metadataDigest"" AS ""cidV0Digest"",
- max(cid_1.""blockNumber"") AS ""blockNumber"",
- max(cid_1.""transactionIndex"") AS ""transactionIndex"",
- max(cid_1.""logIndex"") AS ""logIndex""
- FROM ""CrcV2_UpdateMetadataDigest"" cid_1
- GROUP BY cid_1.avatar, cid_1.""metadataDigest""
- ) as cid on cid.""avatar"" = a.""avatar"";
+ cid_1.""metadataDigest"" AS ""cidV0Digest"",
+ ROW_NUMBER() OVER (PARTITION BY cid_1.avatar ORDER BY cid_1.""blockNumber"" DESC, cid_1.""transactionIndex"" DESC, cid_1.""logIndex"" DESC) as rn
+ FROM ""CrcV2_UpdateMetadataDigest"" cid_1
+ ) cid ON cid.avatar = a.avatar AND cid.rn = 1;
")
};
diff --git a/Circles.Index/Circles.Index.csproj b/Circles.Index/Circles.Index.csproj
index d6e4240..4b52ba3 100644
--- a/Circles.Index/Circles.Index.csproj
+++ b/Circles.Index/Circles.Index.csproj
@@ -8,8 +8,8 @@
Daniel Janz (Gnosis Service GmbH)
Gnosis Service GmbH
Circles
- 1.3.7
- 1.3.7
+ 1.3.8
+ 1.3.8