Skip to content

Commit

Permalink
Admin UI: Identities with multiple devices appear multiple times in i…
Browse files Browse the repository at this point in the history
…dentities table (#620)

* fix: sql server migration to fix identities overview

* fix: postgres migration to fix identities overview

* fix: formatting
  • Loading branch information
daniel-almeida-konkconsulting authored Apr 25, 2024
1 parent e357e67 commit c0e45a6
Show file tree
Hide file tree
Showing 4 changed files with 578 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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"
""");
}
}
}
Loading

0 comments on commit c0e45a6

Please sign in to comment.