This commit is contained in:
2022-10-31 08:08:58 -05:00
parent 689de35c3b
commit 2241ab23fe
6 changed files with 14 additions and 30 deletions

View File

@@ -1,14 +1,14 @@
CREATE PROCEDURE [session].[CreateSession]
@InitialBoardStateDocument [session].[JsonDocument]
@InitialBoardStateDocument [session].[JsonDocument],
@Player1Name [user].[UserName]
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [session].[Session] ([Name], BoardState, Player1Id)
INSERT INTO [session].[Session] (BoardState, Player1Id)
SELECT
JSON_VALUE(@InitialBoardStateDocument, '$.Name'),
@InitialBoardStateDocument,
Id
FROM [user].[User]
WHERE [Name] = JSON_VALUE(@InitialBoardStateDocument, '$.Player1');
WHERE [Name] = @Player1Name
END

View File

@@ -6,7 +6,6 @@ BEGIN
SELECT
sess.[Name],
GameOver,
BoardState,
p1.[Name] as Player1,
p2.[Name] as Player2

View File

@@ -2,12 +2,12 @@
(
Id BIGINT NOT NULL PRIMARY KEY IDENTITY,
Created DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET(),
DomainDocument [session].[JsonDocument] NOT NULL,
[Name] AS JSON_VALUE(DomainDocument, '$.Name') UNIQUE,
Player1Id BIGINT NOT NULL,
Player2Id BIGINT NULL,
BoardState [session].[JsonDocument] NOT NULL,
[Name] AS JSON_VALUE(BoardState, '$.Name') UNIQUE,
CONSTRAINT [BoardState must be json] CHECK (isjson(DomainDocument)=1),
CONSTRAINT [BoardState must be json] CHECK (isjson(BoardState)=1),
CONSTRAINT FK_Player1_User FOREIGN KEY (Player1Id) REFERENCES [user].[User] (Id)
ON DELETE CASCADE
ON UPDATE CASCADE,