-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admin UI: Identities with multiple devices appear multiple times in i…
…dentities table (#620) * fix: sql server migration to fix identities overview * fix: postgres migration to fix identities overview * fix: formatting
- Loading branch information
1 parent
e357e67
commit c0e45a6
Showing
4 changed files
with
578 additions
and
0 deletions.
There are no files selected for viewing
206 changes: 206 additions & 0 deletions
206
...e.Postgres/Migrations/20240424173240_Fix_Multiple_Entries_Identities_Overview.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
...e.Database.Postgres/Migrations/20240424173240_Fix_Multiple_Entries_Identities_Overview.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace Backbone.AdminApi.Infrastructure.Database.Postgres.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class Fix_Multiple_Entries_Identities_Overview : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.Sql(""" | ||
CREATE OR REPLACE VIEW "AdminUi"."IdentityOverviews" AS | ||
SELECT | ||
IDENTITIES."Address", | ||
IDENTITIES."CreatedAt", | ||
USERS."LastLoginAt", | ||
IDENTITIES."ClientId" AS "CreatedWithClient", | ||
DATAWALLETS."Version" AS "DatawalletVersion", | ||
IDENTITIES."IdentityVersion", | ||
TIERS."Id" AS "TierId", | ||
TIERS."Name" AS "TierName", | ||
DEVICES."NumberOfDevices" | ||
FROM "Devices"."Identities" IDENTITIES | ||
LEFT JOIN ( | ||
SELECT | ||
"IdentityAddress", | ||
COUNT(*) AS "NumberOfDevices" | ||
FROM "Devices"."Devices" | ||
GROUP BY "IdentityAddress" | ||
) as DEVICES ON DEVICES."IdentityAddress" = IDENTITIES."Address" | ||
LEFT JOIN ( | ||
SELECT | ||
DEVICES."IdentityAddress", | ||
MAX(USERS."LastLoginAt") AS "LastLoginAt" | ||
FROM "Devices"."AspNetUsers" USERS | ||
INNER JOIN "Devices"."Devices" DEVICES ON DEVICES."Id" = USERS."DeviceId" | ||
GROUP BY DEVICES."IdentityAddress" | ||
) AS USERS ON USERS."IdentityAddress" = IDENTITIES."Address" | ||
LEFT JOIN "Synchronization"."Datawallets" DATAWALLETS ON DATAWALLETS."Owner" = IDENTITIES."Address" | ||
LEFT JOIN "Devices"."Tiers" TIERS ON TIERS."Id" = IDENTITIES."TierId" | ||
"""); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.Sql(""" | ||
CREATE OR REPLACE VIEW "AdminUi"."IdentityOverviews" AS | ||
SELECT | ||
IDENTITIES."Address", | ||
IDENTITIES."CreatedAt", | ||
USERS."LastLoginAt", | ||
IDENTITIES."ClientId" AS "CreatedWithClient", | ||
DATAWALLETS."Version" AS "DatawalletVersion", | ||
IDENTITIES."IdentityVersion", | ||
TIERS."Id" AS "TierId", | ||
TIERS."Name" AS "TierName", | ||
DEVICES."NumberOfDevices" | ||
FROM "Devices"."Identities" IDENTITIES | ||
LEFT JOIN ( | ||
SELECT | ||
"IdentityAddress", | ||
COUNT(*) AS "NumberOfDevices" | ||
FROM "Devices"."Devices" | ||
GROUP BY "IdentityAddress" | ||
) as DEVICES ON DEVICES."IdentityAddress" = IDENTITIES."Address" | ||
LEFT JOIN ( | ||
SELECT | ||
USERS."DeviceId", | ||
DEVICES."IdentityAddress", | ||
MAX(USERS."LastLoginAt") AS "LastLoginAt" | ||
FROM "Devices"."AspNetUsers" USERS | ||
INNER JOIN "Devices"."Devices" DEVICES ON DEVICES."Id" = USERS."DeviceId" | ||
GROUP BY USERS."DeviceId", DEVICES."IdentityAddress" | ||
) AS USERS ON USERS."IdentityAddress" = IDENTITIES."Address" | ||
LEFT JOIN "Synchronization"."Datawallets" DATAWALLETS ON DATAWALLETS."Owner" = IDENTITIES."Address" | ||
LEFT JOIN "Devices"."Tiers" TIERS ON TIERS."Id" = IDENTITIES."TierId" | ||
"""); | ||
} | ||
} | ||
} |
Oops, something went wrong.