squash a bunch of commits
This commit is contained in:
13
Shogi.Database/Post Deployment/Script.PostDeployment.sql
Normal file
13
Shogi.Database/Post Deployment/Script.PostDeployment.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
Post-Deployment Script Template
|
||||
--------------------------------------------------------------------------------------
|
||||
This file contains SQL statements that will be appended to the build script.
|
||||
Use SQLCMD syntax to include a file in the post-deployment script.
|
||||
Example: :r .\myfile.sql
|
||||
Use SQLCMD syntax to reference a variable in the post-deployment script.
|
||||
Example: :setvar TableName MyTable
|
||||
SELECT * FROM [$(TableName)]
|
||||
--------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
:r .\Scripts\PopulateLoginPlatforms.sql
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
DECLARE @LoginPlatforms TABLE (
|
||||
[Platform] NVARCHAR(20)
|
||||
)
|
||||
|
||||
INSERT INTO @LoginPlatforms ([Platform])
|
||||
VALUES
|
||||
('Guest'),
|
||||
('Microsoft');
|
||||
|
||||
MERGE [user].[LoginPlatform] as t
|
||||
USING @LoginPlatforms as s
|
||||
ON t.[Platform] = s.[Platform]
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT ([Platform])
|
||||
VALUES (s.[Platform]);
|
||||
1
Shogi.Database/Session/Session.sql
Normal file
1
Shogi.Database/Session/Session.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE SCHEMA [session]
|
||||
@@ -0,0 +1,16 @@
|
||||
CREATE PROCEDURE [dbo].[CreateBoardState]
|
||||
@boardStateDocument NVARCHAR(max),
|
||||
@sessionName NVARCHAR(100)
|
||||
AS
|
||||
BEGIN
|
||||
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [session].[BoardState] (Document, SessionId)
|
||||
SELECT
|
||||
@boardStateDocument,
|
||||
Id
|
||||
FROM [session].[Session]
|
||||
WHERE [Name] = @sessionName;
|
||||
|
||||
END
|
||||
24
Shogi.Database/Session/Stored Procedures/CreateSession.sql
Normal file
24
Shogi.Database/Session/Stored Procedures/CreateSession.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
CREATE PROCEDURE [session].[CreateSession]
|
||||
@SessionName [session].[SessionName],
|
||||
@Player1Name [user].[UserName],
|
||||
@InitialBoardStateDocument [session].[JsonDocument]
|
||||
AS
|
||||
BEGIN
|
||||
|
||||
SET NOCOUNT ON
|
||||
SET XACT_ABORT ON
|
||||
|
||||
BEGIN TRANSACTION
|
||||
INSERT INTO [session].[Session] ([Name], Player1Id)
|
||||
SELECT
|
||||
@SessionName,
|
||||
Id
|
||||
FROM [user].[User]
|
||||
WHERE [Name] = @Player1Name;
|
||||
|
||||
INSERT INTO [session].[BoardState] (Document, SessionId)
|
||||
VALUES
|
||||
(@InitialBoardStateDocument, SCOPE_IDENTITY());
|
||||
COMMIT
|
||||
|
||||
END
|
||||
@@ -0,0 +1,12 @@
|
||||
CREATE PROCEDURE [session].[ReadAllSessionsMetadata]
|
||||
AS
|
||||
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT
|
||||
[Name],
|
||||
CASE Player2Id
|
||||
WHEN NULL THEN 1
|
||||
ELSE 2
|
||||
END AS PlayerCount
|
||||
FROM [session].[Session];
|
||||
14
Shogi.Database/Session/Stored Procedures/UpdateSession.sql
Normal file
14
Shogi.Database/Session/Stored Procedures/UpdateSession.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
CREATE PROCEDURE [dbo].[UpdateSession]
|
||||
@SessionName [session].[SessionName],
|
||||
@BoardStateJson [session].[JsonDocument]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
UPDATE bs
|
||||
SET bs.Document = @BoardStateJson
|
||||
FROM [session].[BoardState] bs
|
||||
INNER JOIN [session].[Session] s on s.Id = bs.SessionId
|
||||
WHERE s.Name = @SessionName;
|
||||
|
||||
END
|
||||
10
Shogi.Database/Session/Tables/BoardState.sql
Normal file
10
Shogi.Database/Session/Tables/BoardState.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE [session].[BoardState]
|
||||
(
|
||||
[Id] BIGINT NOT NULL PRIMARY KEY IDENTITY,
|
||||
[Document] NVARCHAR(max) NOT NULL,
|
||||
[SessionId] BIGINT NOT NULL,
|
||||
|
||||
CONSTRAINT [Document must be json] CHECK (isjson(Document)=1),
|
||||
CONSTRAINT FK_BoardState_Session FOREIGN KEY (SessionId)
|
||||
REFERENCES [session].[Session] (Id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
)
|
||||
16
Shogi.Database/Session/Tables/Session.sql
Normal file
16
Shogi.Database/Session/Tables/Session.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE [session].[Session]
|
||||
(
|
||||
Id BIGINT NOT NULL PRIMARY KEY IDENTITY,
|
||||
[Name] [session].[SessionName] NOT NULL UNIQUE,
|
||||
Created DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET(),
|
||||
GameOver BIT NOT NULL DEFAULT 0,
|
||||
Player1Id BIGINT NOT NULL,
|
||||
Player2Id BIGINT NULL,
|
||||
|
||||
CONSTRAINT FK_Player1_User FOREIGN KEY (Player1Id) REFERENCES [user].[User] (Id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
CONSTRAINT FK_Player2_User FOREIGN KEY (Player2Id) REFERENCES [user].[User] (Id)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION
|
||||
)
|
||||
2
Shogi.Database/Session/Types/JsonDocument.sql
Normal file
2
Shogi.Database/Session/Types/JsonDocument.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
CREATE TYPE [session].[JsonDocument]
|
||||
FROM NVARCHAR(max) NOT NULL
|
||||
2
Shogi.Database/Session/Types/SessionName.sql
Normal file
2
Shogi.Database/Session/Types/SessionName.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
CREATE TYPE [session].[SessionName]
|
||||
FROM nvarchar(50) NOT NULL
|
||||
91
Shogi.Database/Shogi.Database.sqlproj
Normal file
91
Shogi.Database/Shogi.Database.sqlproj
Normal file
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<Name>Shogi.Database</Name>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>4.1</ProjectVersion>
|
||||
<ProjectGuid>{9b115b71-088f-41ef-858f-c7b155271a9f}</ProjectGuid>
|
||||
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider</DSP>
|
||||
<OutputType>Database</OutputType>
|
||||
<RootPath>
|
||||
</RootPath>
|
||||
<RootNamespace>Shogi.Database</RootNamespace>
|
||||
<AssemblyName>Shogi.Database</AssemblyName>
|
||||
<ModelCollation>1033, CI</ModelCollation>
|
||||
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
|
||||
<DeployToDatabase>True</DeployToDatabase>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<TargetLanguage>CS</TargetLanguage>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<SqlServerVerification>False</SqlServerVerification>
|
||||
<IncludeCompositeObjects>True</IncludeCompositeObjects>
|
||||
<TargetDatabaseSet>True</TargetDatabaseSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||
<!-- Default to the v11.0 targets path if the targets file for the current VS version is not found -->
|
||||
<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>
|
||||
<VisualStudioVersion Condition="'$(SSDTExists)' == ''">11.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Condition="'$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
|
||||
<Import Condition="'$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties" />
|
||||
<Folder Include="Session" />
|
||||
<Folder Include="User" />
|
||||
<Folder Include="Session\Tables" />
|
||||
<Folder Include="Session\Stored Procedures" />
|
||||
<Folder Include="User\Tables" />
|
||||
<Folder Include="Session\Types" />
|
||||
<Folder Include="User\Types" />
|
||||
<Folder Include="User\StoredProcedures" />
|
||||
<Folder Include="Post Deployment" />
|
||||
<Folder Include="Post Deployment\Scripts" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Build Include="Session\session.sql" />
|
||||
<Build Include="User\user.sql" />
|
||||
<Build Include="Session\Tables\Session.sql" />
|
||||
<Build Include="Session\Tables\BoardState.sql" />
|
||||
<Build Include="Session\Stored Procedures\CreateSession.sql" />
|
||||
<Build Include="Session\Stored Procedures\CreateBoardState.sql" />
|
||||
<Build Include="User\Tables\User.sql" />
|
||||
<Build Include="Session\Types\SessionName.sql" />
|
||||
<Build Include="User\Types\UserName.sql" />
|
||||
<Build Include="Session\Types\JsonDocument.sql" />
|
||||
<Build Include="User\StoredProcedures\CreateUser.sql" />
|
||||
<Build Include="Session\Stored Procedures\ReadAllSessionsMetadata.sql" />
|
||||
<Build Include="User\StoredProcedures\ReadUser.sql" />
|
||||
<Build Include="User\Tables\LoginPlatform.sql" />
|
||||
<None Include="Post Deployment\Scripts\PopulateLoginPlatforms.sql" />
|
||||
<Build Include="Session\Stored Procedures\UpdateSession.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PostDeploy Include="Post Deployment\Script.PostDeployment.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
14
Shogi.Database/User/StoredProcedures/CreateUser.sql
Normal file
14
Shogi.Database/User/StoredProcedures/CreateUser.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
CREATE PROCEDURE [user].[CreateUser]
|
||||
@Name [user].[UserName],
|
||||
@DisplayName NVARCHAR(100),
|
||||
@Platform NVARCHAR(20)
|
||||
AS
|
||||
BEGIN
|
||||
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [user].[User] ([Name], DisplayName, [Platform])
|
||||
VALUES
|
||||
(@Name, @DisplayName, @Platform);
|
||||
|
||||
END
|
||||
11
Shogi.Database/User/StoredProcedures/ReadUser.sql
Normal file
11
Shogi.Database/User/StoredProcedures/ReadUser.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE PROCEDURE [user].[ReadUser]
|
||||
@Name [user].[UserName]
|
||||
AS
|
||||
BEGIN
|
||||
SELECT
|
||||
[Name] as Id,
|
||||
DisplayName,
|
||||
[Platform]
|
||||
FROM [user].[User]
|
||||
WHERE [Name] = @Name;
|
||||
END
|
||||
4
Shogi.Database/User/Tables/LoginPlatform.sql
Normal file
4
Shogi.Database/User/Tables/LoginPlatform.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
CREATE TABLE [user].[LoginPlatform]
|
||||
(
|
||||
[Platform] NVARCHAR(20) NOT NULL PRIMARY KEY
|
||||
)
|
||||
11
Shogi.Database/User/Tables/User.sql
Normal file
11
Shogi.Database/User/Tables/User.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE [user].[User]
|
||||
(
|
||||
[Id] BIGINT NOT NULL PRIMARY KEY IDENTITY,
|
||||
[Name] [user].[UserName] NOT NULL UNIQUE,
|
||||
[DisplayName] NVARCHAR(100) NOT NULL,
|
||||
[Platform] NVARCHAR(20) NOT NULL,
|
||||
|
||||
CONSTRAINT User_Platform FOREIGN KEY ([Platform]) References [user].[LoginPlatform] ([Platform])
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
)
|
||||
2
Shogi.Database/User/Types/UserName.sql
Normal file
2
Shogi.Database/User/Types/UserName.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
CREATE TYPE [user].[UserName]
|
||||
FROM nvarchar(100) NOT NULL
|
||||
1
Shogi.Database/User/User.sql
Normal file
1
Shogi.Database/User/User.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE SCHEMA [user]
|
||||
Reference in New Issue
Block a user