Skip to content

Commit

Permalink
Feature/6313 unique profile property per portal (#6314)
Browse files Browse the repository at this point in the history
* 6313 Fix unique contraints for lists per portal

* 6313 Fix AddListEntry

* Update 09.13.07.SqlDataProvider

Few missing oq and dbo s

* Rename 09.13.07.SqlDataProvider to 09.13.08.SqlDataProvider

* Add missing objectQualifier

---------

Co-authored-by: Peter Donker <peter@bring2mind.net>
Co-authored-by: Brian Dukes <bdukes@engagesoftware.com>
  • Loading branch information
3 people authored Jan 28, 2025
1 parent a2a9447 commit c9ed2bd
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/************************************************************/
/***** SqlDataProvider *****/
/***** *****/
/***** *****/
/***** Note: To manually execute this script you must *****/
/***** perform a search and replace operation *****/
/***** for {databaseOwner} and {objectQualifier} *****/
/***** *****/
/************************************************************/

-- Drop the existing constraint
ALTER TABLE {databaseOwner}[{objectQualifier}Lists]
DROP CONSTRAINT [IX_{objectQualifier}Lists_ListName_Value_Text_ParentID];
GO

-- Add the new constraint with PortalId as the first field
ALTER TABLE {databaseOwner}[{objectQualifier}Lists]
ADD CONSTRAINT [IX_{objectQualifier}Lists_ListName_Value_Text_ParentID]
UNIQUE NONCLUSTERED ([PortalId], [ListName], [Value], [Text], [ParentID]);
GO

-- Drop the existing index
DROP INDEX [IX_{objectQualifier}Lists_ParentID] ON {databaseOwner}[{objectQualifier}Lists];
GO

-- Create the new index with PortalId as the first column
CREATE UNIQUE NONCLUSTERED INDEX [IX_{objectQualifier}Lists_ParentID]
ON {databaseOwner}[{objectQualifier}Lists] ([PortalId], [ParentID], [ListName], [Value])
INCLUDE ([DefinitionID], [SortOrder], [Text]);
GO

ALTER PROCEDURE {databaseOwner}[{objectQualifier}AddListEntry]

@ListName nvarchar(50),
@Value nvarchar(100),
@Text nvarchar(150),
@ParentID int,
@Level int,
@EnableSortOrder bit,
@DefinitionID int,
@Description nvarchar(500),
@PortalID int,
@SystemList bit,
@CreatedByUserID int

AS
DECLARE @SortOrder int

IF @EnableSortOrder = 1
SET @SortOrder = IsNull((SELECT MAX ([SortOrder]) From {databaseOwner}[{objectQualifier}Lists] Where [ListName] = @ListName), 0) + 1
ELSE
SET @SortOrder = 0

-- Check if this entry exists
If EXISTS (SELECT [EntryID] From {databaseOwner}[{objectQualifier}Lists] WHERE [PortalID] = @PortalID AND [ListName] = @ListName And [Value] = @Value And [Text] = @Text And [ParentID] = @ParentID)
BEGIN
SELECT -1
RETURN
END

INSERT INTO {databaseOwner}[{objectQualifier}Lists]
(
[ListName],
[Value],
[Text],
[Level],
[SortOrder],
[DefinitionID],
[ParentID],
[Description],
[PortalID],
[SystemList],
[CreatedByUserID],
[CreatedOnDate],
[LastModifiedByUserID],
[LastModifiedOnDate]
)
VALUES (
@ListName,
@Value,
@Text,
@Level,
@SortOrder,
@DefinitionID,
@ParentID,
@Description,
@PortalID,
@SystemList,
@CreatedByUserID,
getdate(),
@CreatedByUserID,
getdate()
)

SELECT SCOPE_IDENTITY()
GO
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ CREATE NONCLUSTERED INDEX [IX_{objectQualifier}Lists_ListName_ParentID] ON {data
GO
PRINT N'Adding constraints to {databaseOwner}[{objectQualifier}Lists]'
GO
ALTER TABLE {databaseOwner}[{objectQualifier}Lists] ADD CONSTRAINT [IX_{objectQualifier}Lists_ListName_Value_Text_ParentID] UNIQUE NONCLUSTERED ([ListName], [Value], [Text], [ParentID])
ALTER TABLE {databaseOwner}[{objectQualifier}Lists] ADD CONSTRAINT [IX_{objectQualifier}Lists_ListName_Value_Text_ParentID] UNIQUE NONCLUSTERED ([PortalId], [ListName], [Value], [Text], [ParentID])
GO
PRINT N'Creating index [IX_{objectQualifier}Lists_ParentID] on {databaseOwner}[{objectQualifier}Lists]'
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_{objectQualifier}Lists_ParentID] ON {databaseOwner}[{objectQualifier}Lists] ([ParentID], [ListName], [Value]) INCLUDE ([DefinitionID], [SortOrder], [Text])
CREATE UNIQUE NONCLUSTERED INDEX [IX_{objectQualifier}Lists_ParentID] ON {databaseOwner}[{objectQualifier}Lists] ([PortalId], [ParentID], [ListName], [Value]) INCLUDE ([DefinitionID], [SortOrder], [Text])
GO
PRINT N'Creating index [IX_{objectQualifier}Lists_SortOrder] on {databaseOwner}[{objectQualifier}Lists]'
GO
Expand Down Expand Up @@ -12069,7 +12069,7 @@ AS
SET @SortOrder = 0

-- Check if this entry exists
If EXISTS (SELECT [EntryID] From {databaseOwner}[{objectQualifier}Lists] WHERE [ListName] = @ListName And [Value] = @Value And [Text] = @Text And [ParentID] = @ParentID)
If EXISTS (SELECT [EntryID] From {databaseOwner}[{objectQualifier}Lists] WHERE [PortalID] = @PortalID AND [ListName] = @ListName And [Value] = @Value And [Text] = @Text And [ParentID] = @ParentID)
BEGIN
SELECT -1
RETURN
Expand Down

0 comments on commit c9ed2bd

Please sign in to comment.