Skip to content

Commit 0747cb7

Browse files
committed
Alter new [dbo].[Topics] columns to be NOT NULL
These columns are initially added as nullable since they don't have a default value. But the script will immediately populate those values, and the result should remove any remaining null values. Once that's done, we can change them to not be nullable, as the final schema expects. This will not only validate that the previous query functioned properly, but also avoid issues with the auto-generated schema comparison script, since it isn't able to update individual columns if there are existing records. While I was at it, I cleaned up the formatting of the original script for adding these columns.
1 parent dc8d988 commit 0747cb7

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

OnTopic.Data.Sql.Database/Scripts/Upgrade from OnTopic 4 to OnTopic 5.sql

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ COLUMN DateModified;
4646
-- in a way that's inconsistent with other attributes. By moving them to Topic, we better acknowledge their unique status.
4747
--------------------------------------------------------------------------------------------------------------------------------
4848

49-
ALTER TABLE [dbo].[Topics]
50-
ADD [TopicKey] VARCHAR (128) NULL,
51-
[ContentType] VARCHAR (128) NULL,
52-
[ParentID] INT NULL;
49+
ALTER TABLE [dbo].[Topics]
50+
ADD [TopicKey] VARCHAR(128) NULL,
51+
[ContentType] VARCHAR(128) NULL,
52+
[ParentID] INT NULL;
5353

5454
WITH KeyAttributes AS (
5555
SELECT TopicID,
@@ -82,6 +82,12 @@ PIVOT ( MIN(AttributeValue)
8282
WHERE RowNumber = 1
8383
AND Topics.TopicID = Pvt.TopicID
8484

85+
ALTER TABLE [dbo].[Topics]
86+
ALTER COLUMN TopicKey VARCHAR(128) NOT NULL;
87+
88+
ALTER TABLE [dbo].[Topics]
89+
ALTER COLUMN ContentType VARCHAR(128) NOT NULL;
90+
8591
DELETE
8692
FROM Attributes
8793
WHERE AttributeKey

0 commit comments

Comments
 (0)