Skip to content

Commit 17b98b4

Browse files
committed
Moved legacy Hierarchy to Utilities schema, renamed AdjacencyList
While `Hierarchy` is a preexisting table, and thus this is a breaking change, it's not a table that is publicly documented, and it's exclusively used by the `GenerateNestedSet` stored procedure—which is _also_ a preexisting object which was moved to the `Utilities` schema as part of a minor release under the same justification. As with other similar updates (e.g., e565f0e), this helps keep the `dbo` schema focused on items which are publicly documented and expected to be used directly as part of the library.
1 parent f0e781b commit 17b98b4

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

OnTopic.Data.Sql.Database/OnTopic.Data.Sql.Database.sqlproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Folder Include="Utilities\" />
7272
<Folder Include="Utilities\Stored Procedures" />
7373
<Folder Include="Utilities\Views" />
74+
<Folder Include="Utilities\Tables" />
7475
</ItemGroup>
7576
<ItemGroup>
7677
<Build Include="Utilities\Schema.sql" />
@@ -87,10 +88,10 @@
8788
<Build Include="Functions\GetUniqueKey.sql" />
8889
<Build Include="Utilities\Views\UniqueKeyIndex.sql" />
8990
<Build Include="Utilities\Views\LeftRightRange.sql" />
91+
<Build Include="Utilities\Tables\AdjacencyList.sql" />
9092
</ItemGroup>
9193
<ItemGroup>
9294
<Build Include="Tables\ExtendedAttributes.sql" />
93-
<Build Include="Tables\Hierarchy.sql" />
9495
<Build Include="Tables\Relationships.sql" />
9596
<Build Include="Tables\Topics.sql" />
9697
<Build Include="Tables\Attributes.sql" />

OnTopic.Data.Sql.Database/Utilities/Stored Procedures/GenerateNestedSet.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ SET IDENTITY_INSERT Topics ON
1515
--------------------------------------------------------------------------------------------------------------------------------
1616
-- Delete original content
1717
DELETE
18-
FROM Hierarchy
18+
FROM AdjacencyList
1919

2020
-- Insert data from Attributes
2121
INSERT
22-
INTO Hierarchy
22+
INTO AdjacencyList
2323
SELECT TopicID AS TopicID,
2424
CONVERT(Int, AttributeValue) AS ParentID,
2525
GETDATE() AS DateAdded
2626
FROM Attributes
2727
WHERE AttributeKey = 'ParentID'
2828

2929
-- Address root node
30-
UPDATE Hierarchy
30+
UPDATE AdjacencyList
3131
SET Parent_TopicID = null
3232
WHERE ISNULL(Parent_TopicID, -1) = -1
3333

@@ -41,7 +41,7 @@ BEGIN
4141

4242
SET @max_RangeLeft_RangeRight = 2 * (
4343
SELECT COUNT(*)
44-
FROM Hierarchy
44+
FROM AdjacencyList
4545
);
4646

4747
INSERT
@@ -55,14 +55,14 @@ SELECT 1,
5555
TopicID,
5656
1,
5757
@max_RangeLeft_RangeRight
58-
FROM Hierarchy
58+
FROM AdjacencyList
5959
WHERE Parent_TopicID IS NULL;
6060

6161
SET @RangeLeft_RangeRight = 2;
6262
SET @pointer = 1;
6363

6464
DELETE
65-
FROM Hierarchy
65+
FROM AdjacencyList
6666
WHERE Parent_TopicID IS NULL;
6767

6868
-- The topics is now loaded and ready to use
@@ -72,7 +72,7 @@ BEGIN
7272
IF EXISTS (
7373
SELECT *
7474
FROM Topics AS S1
75-
JOIN Hierarchy AS T1
75+
JOIN AdjacencyList AS T1
7676
ON S1.TopicID = T1.Parent_TopicID
7777
AND S1.Stack_Top = @pointer
7878
)
@@ -91,13 +91,13 @@ BEGIN
9191
@RangeLeft_RangeRight,
9292
NULL
9393
FROM Topics AS S1
94-
JOIN Hierarchy AS T1
94+
JOIN AdjacencyList AS T1
9595
ON S1.TopicID = T1.Parent_TopicID
9696
AND S1.Stack_Top = @pointer;
9797

9898
-- remove this row from hierarchy
9999
DELETE
100-
FROM Hierarchy
100+
FROM AdjacencyList
101101
WHERE TopicID = (
102102
SELECT TopicID
103103
FROM Topics

OnTopic.Data.Sql.Database/Tables/Hierarchy.sql renamed to OnTopic.Data.Sql.Database/Utilities/Tables/AdjacencyList.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
--------------------------------------------------------------------------------------------------------------------------------
2-
-- HIERARCHY (TABLE)
2+
-- ADJACENCY LIST (TABLE)
33
--------------------------------------------------------------------------------------------------------------------------------
44
-- Provides temporary storage for representing the topic hierarchy as an adjacency list. This isn't the preferred format for
55
-- representing the topic hierarchy, and is not used in production code. Nevertheless, having this available is useful for
66
-- processing migrations from other data formats, or rebuilding the nested set hierarchy should it become corrupted.
77
--------------------------------------------------------------------------------------------------------------------------------
88
CREATE
9-
TABLE [dbo].[Hierarchy] (
9+
TABLE [Utilities].[AdjacencyList] (
1010
[TopicID] INT NOT NULL,
1111
[Parent_TopicID] INT NULL,
1212
[DateAdded] DATETIME NOT NULL,

0 commit comments

Comments
 (0)