tuitio/IdentityServer.Domain.Data/Scripts/1.0.1/02.New structure for AppUse...

48 lines
1.6 KiB
MySQL
Raw Normal View History

2021-11-11 01:20:02 +02:00
if exists (select top 1 1 from sys.objects where name = 'AppUser' and type = 'U')
and not exists(select top 1 1 from sys.columns where name = 'SecurityStamp' and object_id = object_id('AppUser'))
begin
select * into #TmpAppUser from AppUser
drop table AppUser
end
2020-12-20 00:18:53 +02:00
if not exists (select top 1 1 from sys.objects where name = 'AppUser' and type = 'U')
begin
create table AppUser
(
UserId int identity(0, 1) constraint PK_AppUser primary key,
UserName varchar(100) not null constraint UQ_AppUser_UserName unique,
2020-12-20 00:18:53 +02:00
[Password] varchar(100) not null,
2021-11-10 15:14:58 +02:00
FirstName varchar(100),
LastName varchar(100),
2021-11-13 15:08:33 +02:00
Email varchar(100),
2021-11-10 15:14:58 +02:00
ProfilePictureUrl varchar(200),
2021-11-13 16:04:04 +02:00
SecurityStamp varchar(200) not null constraint UQ_AppUser_SecurityStamp unique,
2021-11-12 02:22:51 +02:00
StatusId int not null constraint FK_AppUser_UserStatus references UserStatus(StatusId),
2021-11-13 16:04:04 +02:00
CreationDate datetime not null constraint DF_AppUser_CreationDate default getdate(),
2021-11-10 15:14:58 +02:00
FailedLoginAttempts int,
LastLoginDate datetime,
PasswordChangeDate datetime
2020-12-20 00:18:53 +02:00
)
end
go
2021-11-13 15:08:33 +02:00
if not exists (select top 1 1 from sys.indexes where name = 'IDX_AppUser_Email_NOTNULL' AND object_id = OBJECT_ID('AppUser'))
begin
CREATE UNIQUE NONCLUSTERED INDEX IDX_AppUser_Email_NOTNULL
ON AppUser(Email)
WHERE Email IS NOT NULL
end
go
2020-12-20 00:18:53 +02:00
if not exists (select top 1 1 from AppUser)
begin
2021-11-11 01:20:02 +02:00
declare @activeStatusId int
select @activeStatusId = StatusId from UserStatus where StatusCode = 'ACTIVE'
insert into AppUser(UserName, [Password], CreationDate, SecurityStamp, StatusId)
select UserName, [Password], CreationDate, cast(newid() as varchar(100)), @activeStatusId as StatusId
from #TmpAppUser
drop table #TmpAppUser
2020-12-20 00:18:53 +02:00
end
go