Vidyano Documentation
HomepageDemo
  • Vidyano Documentation
  • Vidyano v6 (.NET 8.0 based)
    • Getting started
    • Documentation
      • Courier Feature
      • Managing User Secrets
      • Vidyano.Core
      • Icons
      • Reports
      • Grids
        • Grouping
      • Instant Search
      • Verbose Logs
        • Storage Provider
      • SourceGenerators
    • Migrating from v5.x
      • Migrating an existing Vidyano v5 project
      • Migration scripts for v5 Repository database
  • Release Notes
    • Client
      • 3.0
      • 2.0.0
    • Service
      • 6.0
      • Previous
        • 5.45.0+26864bd
        • 5.44.0+6e65421
        • 5.40.2+2a48896
        • 5.39.1+f04e696
        • 5.38.3+a697611
        • 5.37.1+3fd7ebea
        • 5.36.0+5338103
        • 5.35.5+2316022
        • 5.34.3+d278982
        • 5.33.1+12ad63a
        • 5.32.1+0c41761
        • 5.31.2+c8aabb2
        • 5.30.0+530afaf
        • 5.29.3+30608c3
        • 5.28.2+bc49431
        • 5.27.0+6b9495e
        • 5.26.2+bccf416
        • 5.25.3+8224b3b
        • 5.24.0+a20f7c
        • 5.23.0+9b8b99
        • 5.22.1+557c11
        • 5.21.1+923828
        • 5.20.0+95f4d1
        • 5.19.0+0964f9
        • 5.18.0+de3495
        • 5.17.0+aaa255
        • 5.16.0+aae2a8
        • 5.15.2+5ed89a
        • 5.14.1+ec0dbd
        • 5.13.1+c8fdb1
        • 5.12.0+66cbb5
        • 5.11.1+d7647c
        • 5.10.2+a3acd1
        • 5.9.0+68a51e
        • 5.8.1+67bcab
        • 5.8.0+aab7d8
        • 5.7.1+554316
        • 5.6.4+151e2e
        • 5.1.60401.4035
  • Legacy v5.x
    • Installation (Legacy)
    • Tutorial 1: Your first application (Legacy)
    • Computed attributes
    • Actions
      • Labels
      • Actions classes
    • Security
      • Architecture
      • Allow user registration
      • Forgot password
      • Best Practices
      • Azure AD SAML based Sign-on
      • SCIM 2.0 Service Provider
    • Overriding Vidyano Settings
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Vidyano v6 (.NET 8.0 based)
  2. Migrating from v5.x

Migration scripts for v5 Repository database

Make sure you have a backup before running the scripts

-- Logs
if COL_LENGTH('Vidyano.Logs', 'ExternalId') is null
begin
	exec sp_rename 'Vidyano.Logs.Id', 'ExternalId', 'COLUMN';
	alter table Vidyano.Logs add Id bigint identity
	alter table Vidyano.Logs alter column Type tinyint not null
	alter table Vidyano.Logs alter column CreatedOn datetimeoffset(3) not null

	alter table Vidyano.Logs drop constraint [PK_Vidyano_Logs]
	alter table Vidyano.Logs add constraint PK_Logs primary key(Id)

	CREATE UNIQUE NONCLUSTERED INDEX [AK_Logs] ON [Vidyano].[Logs] ([ExternalId])

	--CREATE NONCLUSTERED INDEX [IX_Logs_PERF1] ON [Vidyano].[Logs] ([CreatedOn] DESC)
end

-- Settings
if COL_LENGTH('Vidyano.Settings', 'Id') is not null
begin
	declare @keyLength int = COL_LENGTH('Vidyano.Settings', 'Key')
	if @keyLength = -1 or @keyLength > 255
	begin
		alter table Vidyano.Settings alter column [Key] nvarchar(255) not null
	end

	alter table Vidyano.Settings drop constraint [PK_Settings]
	alter table Vidyano.Settings drop column [Id]
	alter table Vidyano.Settings add constraint [PK_Settings] primary key ([Key])
end

-- Users/UserGroup/Users_Group
SET ANSI_PADDING ON

IF (OBJECT_ID('[Vidyano].[Groups]', N'U') is null)
BEGIN 

-- Move Groups to separate table
select u.[Id], u.[Name], u.IsSystem, u.CreationDate, g.TwoFactorRequired
	into [Vidyano].[Groups]
	from [Vidyano].Users u
	inner join [Vidyano].[Users_Group] g on g.[Id] = u.[Id]

alter table [Vidyano].[Groups] add constraint [PK_Groups] primary key ([Id])
alter table [Vidyano].[Groups] add constraint [UQ_Groups_Name] UNIQUE NONCLUSTERED ([Name])

-- Switch to Groups table
ALTER TABLE [Vidyano].[UserGroup] DROP CONSTRAINT [FK_UserGroup_Group]
ALTER TABLE [Vidyano].[UserGroup]  WITH CHECK ADD  CONSTRAINT [FK_UserGroup_Group] FOREIGN KEY([Groups_Id]) REFERENCES [Vidyano].[Groups] ([Id])
ALTER TABLE [Vidyano].[UserGroup] CHECK CONSTRAINT [FK_UserGroup_Group]

END
go

if COL_LENGTH('Vidyano.Users', 'IsSystem') is not null
begin

alter table Vidyano.Users drop column IsSystem

end
go

if COL_LENGTH('Vidyano.Users', 'IsEnabled') is null
begin

alter table Vidyano.Users add
	IsEnabled bit constraint DF_Users_IsEnabled default 1 not null
	,TwoFactorToken varchar(100) null
	,ResetPasswordNextLogin bit constraint DF_Users_ResetPasswordNextLogin default 0 not null

declare @constraint nvarchar(256)

select @constraint=d.name from  sys.tables t
inner join sys.schemas s ON s.schema_id = t.schema_id
inner join sys.default_constraints d on d.parent_object_id = t.object_id
inner join sys.columns c on c.object_id = t.object_id
and c.column_id = d.parent_column_id
where 
t.name = N'Users'
and s.name = N'Vidyano' 
and c.name = N'Version'

IF LEN(ISNULL(@constraint, '')) <> 0
BEGIN
    DECLARE @sqlcmd VARCHAR(MAX)
    SET @sqlcmd = 'ALTER TABLE [Vidyano].[Users] DROP CONSTRAINT' +  QUOTENAME(@constraint);
    EXEC (@sqlcmd);
END

alter table Vidyano.Users alter column Version varchar(100) not null

exec ('update [Vidyano].[Users] set
	IsEnabled = case when JSON_VALUE(Profile, ''$.Disabled'') = ''true'' then 0 else 1 end
	, TwoFactorToken = JSON_VALUE(Profile, ''$.TwoFactorToken'')
	, ResetPasswordNextLogin = case when JSON_VALUE(Profile, ''$.ResetPasswordNextLogin'') = ''true'' then 1 else 0 end
	, Profile = JSON_MODIFY(JSON_MODIFY(JSON_MODIFY(Profile, ''$.Disabled'', NULL), ''$.TwoFactorToken'', NULL), ''$.ResetPasswordNextLogin'', NULL)
	from Vidyano.Users 
	where Profile is not null')

end
go

declare @keyLength int = COL_LENGTH('Vidyano.Users', 'Language')
if @keyLength = -1 or @keyLength > 10
begin
	update [Vidyano].[Users] set [Language] = '' where [Language] is null
	alter table [Vidyano].[Users] alter column [Language] varchar(10) not null
end

set @keyLength = COL_LENGTH('Vidyano.Users', 'CultureInfo')
if @keyLength = -1 or @keyLength > 10
begin
	update [Vidyano].[Users] set [CultureInfo] = '' where [CultureInfo] is null
	alter table [Vidyano].[Users] alter column [CultureInfo] varchar(10) not null
end
go

IF (OBJECT_ID('[Vidyano].[UserSettings]', N'U') is null)
BEGIN 

exec('select Id, [Settings]
	into [Vidyano].[UserSettings]
	from [Vidyano].Users
	where len([Settings]) > 2')

alter table [Vidyano].[UserSettings] add constraint PK_UserSettings primary key (Id)
alter table [Vidyano].[UserSettings] alter column [Settings] nvarchar(max) not null
alter table [Vidyano].[UserSettings] add constraint [FK_UserSettings_Users]
    foreign key ([Id])
    references [Vidyano].[Users] ([Id])
    on delete cascade on update no action;

alter table [Vidyano].Users drop column [Settings]

end
go

IF (OBJECT_ID('[Vidyano].[UserProfiles]', N'U') is null)
BEGIN 

exec('select Id, [Profile]
	into [Vidyano].[UserProfiles]
	from [Vidyano].Users
	where len([Profile]) > 2')

alter table [Vidyano].[UserProfiles] add constraint PK_UserProfiles primary key (Id)
alter table [Vidyano].[UserProfiles] alter column [Profile] nvarchar(max) not null
alter table [Vidyano].[UserProfiles] add constraint [FK_UserProfiles_Users]
    foreign key ([Id])
    references [Vidyano].[Users] ([Id])
    on delete cascade on update no action;

alter table [Vidyano].Users drop column [Profile]

end

-- ClientCodeSnippets (was used in v1 web client)
drop table if exists Vidyano.ClientCodeSnippets

-- Group flattening (groups are no longer member of another group)
IF (OBJECT_ID('[Vidyano].[TmpGroupGroups]', N'U') is null)
BEGIN
exec('select Users_Id, Groups_Id
	into Vidyano.TmpGroupGroups
	from Vidyano.UserGroup where Users_Id in (select Id from Vidyano.Groups)');
END

-- Drop old inherited Users_Group table
drop table if exists [Vidyano].[Users_Group]

-- Delete groups from Vidyano.Users
delete from Vidyano.UserGroup where Users_Id in (select Id from Vidyano.Groups)
delete from Vidyano.Users where Id in (select Id from Vidyano.Groups)

-- Flatten groups
;WITH cte AS (
SELECT tmp.[Users_Id]
	,ug.Name GroupName
      ,tmp.[Groups_Id]
	  ,gg.Name MemberOf
  FROM [Vidyano].[TmpGroupGroups] tmp
	inner join Vidyano.Groups ug on ug.Id = tmp.Users_Id
	inner join Vidyano.Groups gg on gg.Id = tmp.Groups_Id

union all

SELECT cte.[Users_Id]
	,cte.GroupName
      ,tmp.Groups_Id
	  ,gg.Name MemberOf
  FROM [Vidyano].[TmpGroupGroups] tmp
  inner join cte on cte.Groups_Id = tmp.[Users_Id]
	inner join Vidyano.Groups gg on gg.Id = tmp.Groups_Id
)
insert into Vidyano.UserGroup (Users_Id, Groups_Id)
select distinct ug.Users_Id, cte.Groups_Id
	from Vidyano.UserGroup ug
	inner join cte on cte.Users_Id = ug.Groups_Id
except
select ug.Users_Id, ug.Groups_Id from Vidyano.UserGroup ug

-- Update repository version
update Vidyano.Settings set Value='61' where [Key]='RepositoryVersion'
PreviousMigrating an existing Vidyano v5 projectNextClient

Last updated 2 months ago

Was this helpful?