diff --git a/src/Church/Church.SQL/Church.SQL.sqlproj b/src/Church/Church.SQL/Church.SQL.sqlproj index 07e5089..dea1a0c 100644 --- a/src/Church/Church.SQL/Church.SQL.sqlproj +++ b/src/Church/Church.SQL/Church.SQL.sqlproj @@ -86,10 +86,14 @@ + + + + diff --git a/src/Church/Church.SQL/Schemas/Core/Stored Procedures/PersonGet.sql b/src/Church/Church.SQL/Schemas/Core/Stored Procedures/PersonGet.sql new file mode 100644 index 0000000..ebcd9ed --- /dev/null +++ b/src/Church/Church.SQL/Schemas/Core/Stored Procedures/PersonGet.sql @@ -0,0 +1,22 @@ +CREATE PROCEDURE [Core].[PersonGet] + @Ids dbo.big_integer_list_tbltype readonly +AS + + SELECT + p.Id, + p.FirstName, + p.MiddleName, + p.LastName, + p.DateOfBirthDay, + p.DateOfBirthMonth, + p.DateOfBirthYear, + p.ChurchId, + p.IsMale, + p.Occupation, + p.TimeZoneId + + FROM [Core].Person p JOIN @Ids i + On p.Id = i.Id + LEFT JOIN [Core].TimeZone tz + ON tz.Id = p.Id + diff --git a/src/Church/Church.SQL/Schemas/Core/Stored Procedures/PersonGetByChurchId.sql b/src/Church/Church.SQL/Schemas/Core/Stored Procedures/PersonGetByChurchId.sql new file mode 100644 index 0000000..f87ef0e --- /dev/null +++ b/src/Church/Church.SQL/Schemas/Core/Stored Procedures/PersonGetByChurchId.sql @@ -0,0 +1,16 @@ +CREATE PROCEDURE [Core].[PersonGetByChurchId] + @ChurchId INT +AS + + declare @ids dbo.big_integer_list_tbltype + + INSERT INTO @ids (Id) + SELECT + p.Id + FROM [Core].Person p + WHERE + p.ChurchId = @ChurchId + + + EXEC [Core].PersonGet @ids + diff --git a/src/Church/Church.SQL/Schemas/Core/Tables/Person.sql b/src/Church/Church.SQL/Schemas/Core/Tables/Person.sql new file mode 100644 index 0000000..62dbcfe --- /dev/null +++ b/src/Church/Church.SQL/Schemas/Core/Tables/Person.sql @@ -0,0 +1,19 @@ +CREATE TABLE [Core].[Person] +( + [Id] BIGINT IDENTITY(1,1) NOT NULL, + [ChurchId] INT NOT NULL, + [FirstName] NVARCHAR(100) NOT NULL, + [MiddleName] NVARCHAR(100) NULL, + [LastName] NVARCHAR(100) NOT NULL, + [DateOfBirthDay] SMALLINT NULL, + [DateOfBirthMonth] SMALLINT NULL, + [DateOfBirthYear] SMALLINT NULL, + [IsMale] BIT NOT NULL, + [Occupation] NVARCHAR(255) NULL, + [TimeZoneId] INT NULL, + [IsArchived] BIT NOT NULL DEFAULT(0), + + CONSTRAINT PK_Person PRIMARY KEY (Id), + CONSTRAINT FK_Person_TimeZone FOREIGN KEY (TimeZoneId) REFERENCES [Core].[TimeZone](Id), + CONSTRAINT FK_Person_Church FOREIGN KEY (ChurchId) REFERENCES [Core].[Church](Id), +) diff --git a/src/Church/Church.SQL/Script.PostDeployment.sql b/src/Church/Church.SQL/Script.PostDeployment.sql index 4fd0623..831756e 100644 --- a/src/Church/Church.SQL/Script.PostDeployment.sql +++ b/src/Church/Church.SQL/Script.PostDeployment.sql @@ -14,3 +14,5 @@ Post-Deployment Script Template :r .\_PostDeployment\Core.Church.Populate.sql :r .\_PostDeployment\Core.Address.Populate.sql :r .\_PostDeployment\Core.Location.Populate.sql +:r .\_PostDeployment\Core.Person.Populate.sql + diff --git a/src/Church/Church.SQL/Security/Users/ChurchUser.sql b/src/Church/Church.SQL/Security/Users/ChurchUser.sql index 27ec192..22f9447 100644 --- a/src/Church/Church.SQL/Security/Users/ChurchUser.sql +++ b/src/Church/Church.SQL/Security/Users/ChurchUser.sql @@ -29,3 +29,10 @@ GRANT EXECUTE ON [Core].ChurchInsert TO [ChurchUser] As [dbo]; GO GRANT EXECUTE ON [Core].ChurchUpdate TO [ChurchUser] As [dbo]; + +GO +GRANT EXECUTE ON [Core].PersonGet TO [ChurchUser] As [dbo]; +GO +GRANT EXECUTE ON [Core].[PersonGetByChurchId] TO [ChurchUser] As [dbo]; +GO + diff --git a/src/Church/Church.SQL/_PostDeployment/Core.Person.Populate.sql b/src/Church/Church.SQL/_PostDeployment/Core.Person.Populate.sql new file mode 100644 index 0000000..bfe862e --- /dev/null +++ b/src/Church/Church.SQL/_PostDeployment/Core.Person.Populate.sql @@ -0,0 +1,31 @@ +IF NOT EXISTS(SELECT 1 FROM [Core].Person p WHERE p.Id = 1) +BEGIN + INSERT INTO [Core].Person + ( + [ChurchId], + [FirstName], + [MiddleName], + [LastName] , + [DateOfBirthDay], + [DateOfBirthMonth], + [DateOfBirthYear], + [IsMale], + [Occupation], + [TimeZoneId], + [IsArchived] + ) + VALUES + ( + 1, + 'Dav', + 'Owen', + 'Evans', + 12, + 4, + 1981, + 1, + 'Developer', + 85, + 0 + ) +END \ No newline at end of file