indice-co / Indice.Platform

Indice Platform addons and featues
MIT License
44 stars 7 forks source link

Add UsernameHistory feature in Identity #377

Closed eskour closed 6 months ago

eskour commented 6 months ago

What is this feature about?

This feature introduces an optional table for tracking username changes across users, based on the UserId. It functions as a username changelog history, for auditing purposes.

How to enable it?

You need to configure it like this:

"IdentityServer": {
  "Features": {
    "UsernameHistory": true
  }
}

SQL script for manual migration (if needed)

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [auth].[UserUsername](
    [Id] [uniqueidentifier] NOT NULL,
    [UserId] [nvarchar](450) NULL,
    [PreviousUsername] [nvarchar](max) NULL,
    [DateCreated] [datetimeoffset](7) NOT NULL,
 CONSTRAINT [PK_UserUsername] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [auth].[UserUsername]  WITH CHECK ADD  CONSTRAINT [FK_UserUsername_User_UserId] FOREIGN KEY([UserId])
REFERENCES [auth].[User] ([Id])
ON DELETE CASCADE
GO

ALTER TABLE [auth].[UserUsername] CHECK CONSTRAINT [FK_UserUsername_User_UserId]
GO