Skip to content

Commit a74389d

Browse files
committed
Add @TopicKey and @ContentType to CreateTopic, UpdateTopic
In a previous commit, the key attributes of `Key`, `ContentType`, and `ParentID` were migrated from `Attributes` to `Topics`. This updates the `CreateTopic` and `UpdateTopic` stored procedure—as well as its call from `SqlTopicRepository`—to include `@TopicKey` and `@ContentType`. (`@ParentID` was already required for `CreateTopic`, and continues to be handled via `MoveTopic` for updates.) Technically, the `UpdateTopic` stored procedure only requires the `@TopicKey` or `@ContentType` parameters if they have changed; it's smart enough to fall back to the existing value if they aren't passed. That said, it doesn't hurt anything to hard code them in absence of library support for tracking their state change. These three attributes continue to be saved in the `Attributes` table for now, and are thus maintained in two locations. That will be removed in subsequent commits.
1 parent 1124443 commit a74389d

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

OnTopic.Data.Sql.Database/Stored Procedures/CreateTopic.sql

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
--------------------------------------------------------------------------------------------------------------------------------
66

77
CREATE PROCEDURE [dbo].[CreateTopic]
8-
@ParentID int = -1,
8+
@Key VARCHAR(128) ,
9+
@ContentType VARCHAR(128) ,
10+
@ParentID INT = -1,
911
@Attributes AttributeValues READONLY,
1012
@ExtendedAttributes Xml = null,
1113
@Version datetime = null
@@ -53,11 +55,17 @@ IF (@ParentID > -1)
5355
--------------------------------------------------------------------------------------------------------------------------------
5456
INSERT INTO Topics (
5557
RangeLeft,
56-
RangeRight
58+
RangeRight,
59+
TopicKey,
60+
ContentType,
61+
ParentID
5762
)
5863
Values (
5964
@RangeRight,
60-
@RangeRight + 1
65+
@RangeRight + 1,
66+
@Key,
67+
@ContentType,
68+
@ParentID
6169
)
6270

6371
DECLARE @TopicID INT

OnTopic.Data.Sql.Database/Stored Procedures/UpdateTopic.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
CREATE PROCEDURE [dbo].[UpdateTopic]
88
@TopicID INT = -1 ,
9+
@Key VARCHAR(128) = NULL ,
10+
@ContentType VARCHAR(128) = NULL ,
911
@Attributes AttributeValues READONLY ,
1012
@ExtendedAttributes XML = null ,
1113
@Version DATETIME = null ,
@@ -18,6 +20,28 @@ AS
1820
IF @Version IS NULL
1921
SET @Version = GetDate()
2022

23+
--------------------------------------------------------------------------------------------------------------------------------
24+
-- UPDATE KEY ATTRIBUTES
25+
--------------------------------------------------------------------------------------------------------------------------------
26+
27+
IF @Key IS NOT NULL OR @ContentType IS NOT NULL
28+
BEGIN
29+
UPDATE Topics
30+
SET TopicKey =
31+
CASE
32+
WHEN @Key IS NULL
33+
THEN TopicKey
34+
ELSE @Key
35+
END,
36+
ContentType =
37+
CASE
38+
WHEN @ContentType IS NULL
39+
THEN TopicKey
40+
ELSE @ContentType
41+
END
42+
WHERE TopicID = @TopicID
43+
END
44+
2145
--------------------------------------------------------------------------------------------------------------------------------
2246
-- INSERT NEW ATTRIBUTES
2347
--------------------------------------------------------------------------------------------------------------------------------

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ SqlDateTime version
423423
else if (topic.Parent is not null) {
424424
command.AddParameter("ParentID", topic.Parent.Id);
425425
}
426+
command.AddParameter("Key", topic.Key);
427+
command.AddParameter("ContentType", topic.ContentType);
426428
command.AddParameter("Version", version.Value);
427429
command.AddParameter("ExtendedAttributes", extendedAttributes);
428430
command.AddParameter("Attributes", attributeValues);

0 commit comments

Comments
 (0)