Skip to content

Commit

Permalink
Add Person table and stored proc
Browse files Browse the repository at this point in the history
  • Loading branch information
davevans committed Aug 4, 2014
1 parent 2e08678 commit 870eae4
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Church/Church.SQL/Church.SQL.sqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@
<Build Include="Schemas\Core\Stored Procedures\ChurchGetById.sql" />
<Build Include="Schemas\Core\Stored Procedures\ChurchInsert.sql" />
<Build Include="Schemas\Core\Stored Procedures\ChurchUpdate.sql" />
<Build Include="Schemas\Core\Tables\Person.sql" />
<Build Include="Schemas\Core\Stored Procedures\PersonGet.sql" />
<Build Include="Schemas\Core\Stored Procedures\PersonGetByChurchId.sql" />
</ItemGroup>
<ItemGroup>
<None Include="Church.SQL.Local.publish.xml" />
<None Include="_PostDeployment\Core.Church.Populate.sql" />
<None Include="_PostDeployment\Core.Person.Populate.sql" />
</ItemGroup>
<ItemGroup>
<PostDeploy Include="Script.PostDeployment.sql" />
Expand Down
22 changes: 22 additions & 0 deletions src/Church/Church.SQL/Schemas/Core/Stored Procedures/PersonGet.sql
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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

19 changes: 19 additions & 0 deletions src/Church/Church.SQL/Schemas/Core/Tables/Person.sql
Original file line number Diff line number Diff line change
@@ -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),
)
2 changes: 2 additions & 0 deletions src/Church/Church.SQL/Script.PostDeployment.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

7 changes: 7 additions & 0 deletions src/Church/Church.SQL/Security/Users/ChurchUser.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

31 changes: 31 additions & 0 deletions src/Church/Church.SQL/_PostDeployment/Core.Person.Populate.sql
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 870eae4

Please sign in to comment.