Version 8 (#43)
* Use htmx for front end (#36) * Use short GUIDs in URLs and forms (#1) * Refresh theme (#38) * Use ASP.NET Core for log on/off (#39) * Fix date/time / time zone issues (#41) * Update help for v8 (#42) * Add FAKE build script (#37)
This commit was merged in pull request #43.
This commit is contained in:
724
src/PrayerTracker.Data/Access.fs
Normal file
724
src/PrayerTracker.Data/Access.fs
Normal file
@@ -0,0 +1,724 @@
|
||||
namespace PrayerTracker.Data
|
||||
|
||||
open NodaTime
|
||||
open Npgsql
|
||||
open Npgsql.FSharp
|
||||
open PrayerTracker.Entities
|
||||
|
||||
/// Helper functions for the PostgreSQL data implementation
|
||||
[<AutoOpen>]
|
||||
module private Helpers =
|
||||
|
||||
/// Map a row to a Church instance
|
||||
let mapToChurch (row : RowReader) =
|
||||
{ Id = ChurchId (row.uuid "id")
|
||||
Name = row.string "church_name"
|
||||
City = row.string "city"
|
||||
State = row.string "state"
|
||||
HasVpsInterface = row.bool "has_vps_interface"
|
||||
InterfaceAddress = row.stringOrNone "interface_address"
|
||||
}
|
||||
|
||||
/// Map a row to a ListPreferences instance
|
||||
let mapToListPreferences (row : RowReader) =
|
||||
{ SmallGroupId = SmallGroupId (row.uuid "small_group_id")
|
||||
DaysToKeepNew = row.int "days_to_keep_new"
|
||||
DaysToExpire = row.int "days_to_expire"
|
||||
LongTermUpdateWeeks = row.int "long_term_update_weeks"
|
||||
EmailFromName = row.string "email_from_name"
|
||||
EmailFromAddress = row.string "email_from_address"
|
||||
Fonts = row.string "fonts"
|
||||
HeadingColor = row.string "heading_color"
|
||||
LineColor = row.string "line_color"
|
||||
HeadingFontSize = row.int "heading_font_size"
|
||||
TextFontSize = row.int "text_font_size"
|
||||
GroupPassword = row.string "group_password"
|
||||
IsPublic = row.bool "is_public"
|
||||
PageSize = row.int "page_size"
|
||||
TimeZoneId = TimeZoneId (row.string "time_zone_id")
|
||||
RequestSort = RequestSort.fromCode (row.string "request_sort")
|
||||
DefaultEmailType = EmailFormat.fromCode (row.string "default_email_type")
|
||||
AsOfDateDisplay = AsOfDateDisplay.fromCode (row.string "as_of_date_display")
|
||||
}
|
||||
|
||||
/// Map a row to a Member instance
|
||||
let mapToMember (row : RowReader) =
|
||||
{ Id = MemberId (row.uuid "id")
|
||||
SmallGroupId = SmallGroupId (row.uuid "small_group_id")
|
||||
Name = row.string "member_name"
|
||||
Email = row.string "email"
|
||||
Format = row.stringOrNone "email_format" |> Option.map EmailFormat.fromCode
|
||||
}
|
||||
|
||||
/// Map a row to a Prayer Request instance
|
||||
let mapToPrayerRequest (row : RowReader) =
|
||||
{ Id = PrayerRequestId (row.uuid "id")
|
||||
UserId = UserId (row.uuid "user_id")
|
||||
SmallGroupId = SmallGroupId (row.uuid "small_group_id")
|
||||
EnteredDate = row.fieldValue<Instant> "entered_date"
|
||||
UpdatedDate = row.fieldValue<Instant> "updated_date"
|
||||
Requestor = row.stringOrNone "requestor"
|
||||
Text = row.string "request_text"
|
||||
NotifyChaplain = row.bool "notify_chaplain"
|
||||
RequestType = PrayerRequestType.fromCode (row.string "request_type")
|
||||
Expiration = Expiration.fromCode (row.string "expiration")
|
||||
}
|
||||
|
||||
/// Map a row to a Small Group instance
|
||||
let mapToSmallGroup (row : RowReader) =
|
||||
{ Id = SmallGroupId (row.uuid "id")
|
||||
ChurchId = ChurchId (row.uuid "church_id")
|
||||
Name = row.string "group_name"
|
||||
Preferences = ListPreferences.empty
|
||||
}
|
||||
|
||||
/// Map a row to a Small Group information set
|
||||
let mapToSmallGroupInfo (row : RowReader) =
|
||||
{ Id = Giraffe.ShortGuid.fromGuid (row.uuid "id")
|
||||
Name = row.string "group_name"
|
||||
ChurchName = row.string "church_name"
|
||||
TimeZoneId = TimeZoneId (row.string "time_zone_id")
|
||||
IsPublic = row.bool "is_public"
|
||||
}
|
||||
|
||||
/// Map a row to a Small Group list item
|
||||
let mapToSmallGroupItem (row : RowReader) =
|
||||
Giraffe.ShortGuid.fromGuid (row.uuid "id"), $"""{row.string "church_name"} | {row.string "group_name"}"""
|
||||
|
||||
/// Map a row to a Small Group instance with populated list preferences
|
||||
let mapToSmallGroupWithPreferences (row : RowReader) =
|
||||
{ mapToSmallGroup row with
|
||||
Preferences = mapToListPreferences row
|
||||
}
|
||||
|
||||
/// Map a row to a User instance
|
||||
let mapToUser (row : RowReader) =
|
||||
{ Id = UserId (row.uuid "id")
|
||||
FirstName = row.string "first_name"
|
||||
LastName = row.string "last_name"
|
||||
Email = row.string "email"
|
||||
IsAdmin = row.bool "is_admin"
|
||||
PasswordHash = row.string "password_hash"
|
||||
LastSeen = row.fieldValueOrNone<Instant> "last_seen"
|
||||
}
|
||||
|
||||
|
||||
/// Functions to manipulate churches
|
||||
module Churches =
|
||||
|
||||
/// Get a list of all churches
|
||||
let all conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT * FROM pt.church ORDER BY church_name"
|
||||
|> Sql.executeAsync mapToChurch
|
||||
|
||||
/// Delete a church by its ID
|
||||
let deleteById (churchId : ChurchId) conn = backgroundTask {
|
||||
let idParam = [ [ "@churchId", Sql.uuid churchId.Value ] ]
|
||||
let where = "WHERE small_group_id IN (SELECT id FROM pt.small_group WHERE church_id = @churchId)"
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.executeTransactionAsync
|
||||
[ $"DELETE FROM pt.prayer_request {where}", idParam
|
||||
$"DELETE FROM pt.user_small_group {where}", idParam
|
||||
$"DELETE FROM pt.list_preference {where}", idParam
|
||||
"DELETE FROM pt.small_group WHERE church_id = @churchId", idParam
|
||||
"DELETE FROM pt.church WHERE id = @churchId", idParam ]
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Save a church's information
|
||||
let save (church : Church) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
INSERT INTO pt.church (
|
||||
id, church_name, city, state, has_vps_interface, interface_address
|
||||
) VALUES (
|
||||
@id, @name, @city, @state, @hasVpsInterface, @interfaceAddress
|
||||
) ON CONFLICT (id) DO UPDATE
|
||||
SET church_name = EXCLUDED.church_name,
|
||||
city = EXCLUDED.city,
|
||||
state = EXCLUDED.state,
|
||||
has_vps_interface = EXCLUDED.has_vps_interface,
|
||||
interface_address = EXCLUDED.interface_address"""
|
||||
|> Sql.parameters
|
||||
[ "@id", Sql.uuid church.Id.Value
|
||||
"@name", Sql.string church.Name
|
||||
"@city", Sql.string church.City
|
||||
"@state", Sql.string church.State
|
||||
"@hasVpsInterface", Sql.bool church.HasVpsInterface
|
||||
"@interfaceAddress", Sql.stringOrNone church.InterfaceAddress ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Find a church by its ID
|
||||
let tryById (churchId : ChurchId) conn = backgroundTask {
|
||||
let! church =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT * FROM pt.church WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid churchId.Value ]
|
||||
|> Sql.executeAsync mapToChurch
|
||||
return List.tryHead church
|
||||
}
|
||||
|
||||
|
||||
/// Functions to manipulate small group members
|
||||
module Members =
|
||||
|
||||
/// Count members for the given small group
|
||||
let countByGroup (groupId : SmallGroupId) conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT COUNT(id) AS mbr_count FROM pt.member WHERE small_group_id = @groupId"
|
||||
|> Sql.parameters [ "@groupId", Sql.uuid groupId.Value ]
|
||||
|> Sql.executeRowAsync (fun row -> row.int "mbr_count")
|
||||
|
||||
/// Delete a small group member by its ID
|
||||
let deleteById (memberId : MemberId) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "DELETE FROM pt.member WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid memberId.Value ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Retrieve all members for a given small group
|
||||
let forGroup (groupId : SmallGroupId) conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT * FROM pt.member WHERE small_group_id = @groupId ORDER BY member_name"
|
||||
|> Sql.parameters [ "@groupId", Sql.uuid groupId.Value ]
|
||||
|> Sql.executeAsync mapToMember
|
||||
|
||||
/// Save a small group member
|
||||
let save (mbr : Member) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
INSERT INTO pt.member (
|
||||
id, small_group_id, member_name, email, email_format
|
||||
) VALUES (
|
||||
@id, @groupId, @name, @email, @format
|
||||
) ON CONFLICT (id) DO UPDATE
|
||||
SET member_name = EXCLUDED.member_name,
|
||||
email = EXCLUDED.email,
|
||||
email_format = EXCLUDED.email_format"""
|
||||
|> Sql.parameters
|
||||
[ "@id", Sql.uuid mbr.Id.Value
|
||||
"@groupId", Sql.uuid mbr.SmallGroupId.Value
|
||||
"@name", Sql.string mbr.Name
|
||||
"@email", Sql.string mbr.Email
|
||||
"@format", Sql.stringOrNone (mbr.Format |> Option.map EmailFormat.toCode) ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Retrieve a small group member by its ID
|
||||
let tryById (memberId : MemberId) conn = backgroundTask {
|
||||
let! mbr =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT * FROM pt.member WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid memberId.Value ]
|
||||
|> Sql.executeAsync mapToMember
|
||||
return List.tryHead mbr
|
||||
}
|
||||
|
||||
|
||||
/// Options to retrieve a list of requests
|
||||
type PrayerRequestOptions =
|
||||
{ /// The small group for which requests should be retrieved
|
||||
SmallGroup : SmallGroup
|
||||
|
||||
/// The clock instance to use for date/time manipulation
|
||||
Clock : IClock
|
||||
|
||||
/// The date for which the list is being retrieved
|
||||
ListDate : LocalDate option
|
||||
|
||||
/// Whether only active requests should be retrieved
|
||||
ActiveOnly : bool
|
||||
|
||||
/// The page number, for paged lists
|
||||
PageNumber : int
|
||||
}
|
||||
|
||||
|
||||
/// Functions to manipulate prayer requests
|
||||
module PrayerRequests =
|
||||
|
||||
/// Central place to append sort criteria for prayer request queries
|
||||
let private orderBy sort =
|
||||
match sort with
|
||||
| SortByDate -> "updated_date DESC, entered_date DESC, requestor"
|
||||
| SortByRequestor -> "requestor, updated_date DESC, entered_date DESC"
|
||||
|
||||
/// Paginate a prayer request query
|
||||
let private paginate (pageNbr : int) pageSize =
|
||||
if pageNbr > 0 then $"LIMIT {pageSize} OFFSET {(pageNbr - 1) * pageSize}" else ""
|
||||
|
||||
/// Count the number of prayer requests for a church
|
||||
let countByChurch (churchId : ChurchId) conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT COUNT(id) AS req_count
|
||||
FROM pt.prayer_request
|
||||
WHERE small_group_id IN (SELECT id FROM pt.small_group WHERE church_id = @churchId)"""
|
||||
|> Sql.parameters [ "@churchId", Sql.uuid churchId.Value ]
|
||||
|> Sql.executeRowAsync (fun row -> row.int "req_count")
|
||||
|
||||
/// Count the number of prayer requests for a small group
|
||||
let countByGroup (groupId : SmallGroupId) conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT COUNT(id) AS req_count FROM pt.prayer_request WHERE small_group_id = @groupId"
|
||||
|> Sql.parameters [ "@groupId", Sql.uuid groupId.Value ]
|
||||
|> Sql.executeRowAsync (fun row -> row.int "req_count")
|
||||
|
||||
/// Delete a prayer request by its ID
|
||||
let deleteById (reqId : PrayerRequestId) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "DELETE FROM pt.prayer_request WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid reqId.Value ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Get all (or active) requests for a small group as of now or the specified date
|
||||
let forGroup (opts : PrayerRequestOptions) conn =
|
||||
let theDate = defaultArg opts.ListDate (SmallGroup.localDateNow opts.Clock opts.SmallGroup)
|
||||
let where, parameters =
|
||||
if opts.ActiveOnly then
|
||||
let asOf = NpgsqlParameter (
|
||||
"@asOf",
|
||||
(theDate.AtStartOfDayInZone(SmallGroup.timeZone opts.SmallGroup)
|
||||
- Duration.FromDays opts.SmallGroup.Preferences.DaysToExpire)
|
||||
.ToInstant ())
|
||||
""" AND ( updated_date > @asOf
|
||||
OR expiration = @manual
|
||||
OR request_type = @longTerm
|
||||
OR request_type = @expecting)
|
||||
AND expiration <> @forced""",
|
||||
[ "@asOf", Sql.parameter asOf
|
||||
"@manual", Sql.string (Expiration.toCode Manual)
|
||||
"@longTerm", Sql.string (PrayerRequestType.toCode LongTermRequest)
|
||||
"@expecting", Sql.string (PrayerRequestType.toCode Expecting)
|
||||
"@forced", Sql.string (Expiration.toCode Forced) ]
|
||||
else "", []
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query $"""
|
||||
SELECT *
|
||||
FROM pt.prayer_request
|
||||
WHERE small_group_id = @groupId {where}
|
||||
ORDER BY {orderBy opts.SmallGroup.Preferences.RequestSort}
|
||||
{paginate opts.PageNumber opts.SmallGroup.Preferences.PageSize}"""
|
||||
|> Sql.parameters (("@groupId", Sql.uuid opts.SmallGroup.Id.Value) :: parameters)
|
||||
|> Sql.executeAsync mapToPrayerRequest
|
||||
|
||||
/// Save a prayer request
|
||||
let save (req : PrayerRequest) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
INSERT into pt.prayer_request (
|
||||
id, request_type, user_id, small_group_id, entered_date, updated_date, requestor, request_text,
|
||||
notify_chaplain, expiration
|
||||
) VALUES (
|
||||
@id, @type, @userId, @groupId, @entered, @updated, @requestor, @text,
|
||||
@notifyChaplain, @expiration
|
||||
) ON CONFLICT (id) DO UPDATE
|
||||
SET request_type = EXCLUDED.request_type,
|
||||
updated_date = EXCLUDED.updated_date,
|
||||
requestor = EXCLUDED.requestor,
|
||||
request_text = EXCLUDED.request_text,
|
||||
notify_chaplain = EXCLUDED.notify_chaplain,
|
||||
expiration = EXCLUDED.expiration"""
|
||||
|> Sql.parameters
|
||||
[ "@id", Sql.uuid req.Id.Value
|
||||
"@type", Sql.string (PrayerRequestType.toCode req.RequestType)
|
||||
"@userId", Sql.uuid req.UserId.Value
|
||||
"@groupId", Sql.uuid req.SmallGroupId.Value
|
||||
"@entered", Sql.parameter (NpgsqlParameter ("@entered", req.EnteredDate))
|
||||
"@updated", Sql.parameter (NpgsqlParameter ("@updated", req.UpdatedDate))
|
||||
"@requestor", Sql.stringOrNone req.Requestor
|
||||
"@text", Sql.string req.Text
|
||||
"@notifyChaplain", Sql.bool req.NotifyChaplain
|
||||
"@expiration", Sql.string (Expiration.toCode req.Expiration)
|
||||
]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Search prayer requests for the given term
|
||||
let searchForGroup group searchTerm pageNbr conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query $"""
|
||||
SELECT * FROM pt.prayer_request WHERE small_group_id = @groupId AND request_text ILIKE @search
|
||||
UNION
|
||||
SELECT * FROM pt.prayer_request WHERE small_group_id = @groupId AND COALESCE(requestor, '') ILIKE @search
|
||||
ORDER BY {orderBy group.Preferences.RequestSort}
|
||||
{paginate pageNbr group.Preferences.PageSize}"""
|
||||
|> Sql.parameters [ "@groupId", Sql.uuid group.Id.Value; "@search", Sql.string $"%%%s{searchTerm}%%" ]
|
||||
|> Sql.executeAsync mapToPrayerRequest
|
||||
|
||||
/// Retrieve a prayer request by its ID
|
||||
let tryById (reqId : PrayerRequestId) conn = backgroundTask {
|
||||
let! req =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT * FROM pt.prayer_request WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid reqId.Value ]
|
||||
|> Sql.executeAsync mapToPrayerRequest
|
||||
return List.tryHead req
|
||||
}
|
||||
|
||||
/// Update the expiration for the given prayer request
|
||||
let updateExpiration (req : PrayerRequest) withTime conn = backgroundTask {
|
||||
let sql, parameters =
|
||||
if withTime then
|
||||
", updated_date = @updated",
|
||||
[ "@updated", Sql.parameter (NpgsqlParameter ("@updated", req.UpdatedDate)) ]
|
||||
else "", []
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query $"UPDATE pt.prayer_request SET expiration = @expiration{sql} WHERE id = @id"
|
||||
|> Sql.parameters
|
||||
([ "@expiration", Sql.string (Expiration.toCode req.Expiration)
|
||||
"@id", Sql.uuid req.Id.Value ]
|
||||
|> List.append parameters)
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
|
||||
/// Functions to retrieve small group information
|
||||
module SmallGroups =
|
||||
|
||||
/// Count the number of small groups for a church
|
||||
let countByChurch (churchId : ChurchId) conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT COUNT(id) AS group_count FROM pt.small_group WHERE church_id = @churchId"
|
||||
|> Sql.parameters [ "@churchId", Sql.uuid churchId.Value ]
|
||||
|> Sql.executeRowAsync (fun row -> row.int "group_count")
|
||||
|
||||
/// Delete a small group by its ID
|
||||
let deleteById (groupId : SmallGroupId) conn = backgroundTask {
|
||||
let idParam = [ [ "@groupId", Sql.uuid groupId.Value ] ]
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.executeTransactionAsync
|
||||
[ "DELETE FROM pt.prayer_request WHERE small_group_id = @groupId", idParam
|
||||
"DELETE FROM pt.user_small_group WHERE small_group_id = @groupId", idParam
|
||||
"DELETE FROM pt.list_preference WHERE small_group_id = @groupId", idParam
|
||||
"DELETE FROM pt.small_group WHERE id = @groupId", idParam ]
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Get information for all small groups
|
||||
let infoForAll conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT sg.id, sg.group_name, c.church_name, lp.time_zone_id, lp.is_public
|
||||
FROM pt.small_group sg
|
||||
INNER JOIN pt.church c ON c.id = sg.church_id
|
||||
INNER JOIN pt.list_preference lp ON lp.small_group_id = sg.id
|
||||
ORDER BY sg.group_name"""
|
||||
|> Sql.executeAsync mapToSmallGroupInfo
|
||||
|
||||
/// Get a list of small group IDs along with a description that includes the church name
|
||||
let listAll conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT g.group_name, g.id, c.church_name
|
||||
FROM pt.small_group g
|
||||
INNER JOIN pt.church c ON c.id = g.church_id
|
||||
ORDER BY c.church_name, g.group_name"""
|
||||
|> Sql.executeAsync mapToSmallGroupItem
|
||||
|
||||
/// Get a list of small group IDs and descriptions for groups with a group password
|
||||
let listProtected conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT g.group_name, g.id, c.church_name, lp.is_public
|
||||
FROM pt.small_group g
|
||||
INNER JOIN pt.church c ON c.id = g.church_id
|
||||
INNER JOIN pt.list_preference lp ON lp.small_group_id = g.id
|
||||
WHERE COALESCE(lp.group_password, '') <> ''
|
||||
ORDER BY c.church_name, g.group_name"""
|
||||
|> Sql.executeAsync mapToSmallGroupItem
|
||||
|
||||
/// Get a list of small group IDs and descriptions for groups that are public or have a group password
|
||||
let listPublicAndProtected conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT g.group_name, g.id, c.church_name, lp.time_zone_id, lp.is_public
|
||||
FROM pt.small_group g
|
||||
INNER JOIN pt.church c ON c.id = g.church_id
|
||||
INNER JOIN pt.list_preference lp ON lp.small_group_id = g.id
|
||||
WHERE lp.is_public = TRUE
|
||||
OR COALESCE(lp.group_password, '') <> ''
|
||||
ORDER BY c.church_name, g.group_name"""
|
||||
|> Sql.executeAsync mapToSmallGroupInfo
|
||||
|
||||
/// Log on for a small group (includes list preferences)
|
||||
let logOn (groupId : SmallGroupId) password conn = backgroundTask {
|
||||
let! group =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT sg.*, lp.*
|
||||
FROM pt.small_group sg
|
||||
INNER JOIN pt.list_preference lp ON lp.small_group_id = sg.id
|
||||
WHERE sg.id = @id
|
||||
AND lp.group_password = @password"""
|
||||
|> Sql.parameters [ "@id", Sql.uuid groupId.Value; "@password", Sql.string password ]
|
||||
|> Sql.executeAsync mapToSmallGroupWithPreferences
|
||||
return List.tryHead group
|
||||
}
|
||||
|
||||
/// Save a small group
|
||||
let save (group : SmallGroup) isNew conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.executeTransactionAsync [
|
||||
""" INSERT INTO pt.small_group (
|
||||
id, church_id, group_name
|
||||
) VALUES (
|
||||
@id, @churchId, @name
|
||||
) ON CONFLICT (id) DO UPDATE
|
||||
SET church_id = EXCLUDED.church_id,
|
||||
group_name = EXCLUDED.group_name""",
|
||||
[ [ "@id", Sql.uuid group.Id.Value
|
||||
"@churchId", Sql.uuid group.ChurchId.Value
|
||||
"@name", Sql.string group.Name ] ]
|
||||
if isNew then
|
||||
"INSERT INTO pt.list_preference (small_group_id) VALUES (@id)",
|
||||
[ [ "@id", Sql.uuid group.Id.Value ] ]
|
||||
]
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Save a small group's list preferences
|
||||
let savePreferences (pref : ListPreferences) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
UPDATE pt.list_preference
|
||||
SET days_to_keep_new = @daysToKeepNew,
|
||||
days_to_expire = @daysToExpire,
|
||||
long_term_update_weeks = @longTermUpdateWeeks,
|
||||
email_from_name = @emailFromName,
|
||||
email_from_address = @emailFromAddress,
|
||||
fonts = @fonts,
|
||||
heading_color = @headingColor,
|
||||
line_color = @lineColor,
|
||||
heading_font_size = @headingFontSize,
|
||||
text_font_size = @textFontSize,
|
||||
request_sort = @requestSort,
|
||||
group_password = @groupPassword,
|
||||
default_email_type = @defaultEmailType,
|
||||
is_public = @isPublic,
|
||||
time_zone_id = @timeZoneId,
|
||||
page_size = @pageSize,
|
||||
as_of_date_display = @asOfDateDisplay
|
||||
WHERE small_group_id = @groupId"""
|
||||
|> Sql.parameters
|
||||
[ "@groupId", Sql.uuid pref.SmallGroupId.Value
|
||||
"@daysToKeepNew", Sql.int pref.DaysToKeepNew
|
||||
"@daysToExpire", Sql.int pref.DaysToExpire
|
||||
"@longTermUpdateWeeks", Sql.int pref.LongTermUpdateWeeks
|
||||
"@emailFromName", Sql.string pref.EmailFromName
|
||||
"@emailFromAddress", Sql.string pref.EmailFromAddress
|
||||
"@fonts", Sql.string pref.Fonts
|
||||
"@headingColor", Sql.string pref.HeadingColor
|
||||
"@lineColor", Sql.string pref.LineColor
|
||||
"@headingFontSize", Sql.int pref.HeadingFontSize
|
||||
"@textFontSize", Sql.int pref.TextFontSize
|
||||
"@requestSort", Sql.string (RequestSort.toCode pref.RequestSort)
|
||||
"@groupPassword", Sql.string pref.GroupPassword
|
||||
"@defaultEmailType", Sql.string (EmailFormat.toCode pref.DefaultEmailType)
|
||||
"@isPublic", Sql.bool pref.IsPublic
|
||||
"@timeZoneId", Sql.string (TimeZoneId.toString pref.TimeZoneId)
|
||||
"@pageSize", Sql.int pref.PageSize
|
||||
"@asOfDateDisplay", Sql.string (AsOfDateDisplay.toCode pref.AsOfDateDisplay)
|
||||
]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Get a small group by its ID
|
||||
let tryById (groupId : SmallGroupId) conn = backgroundTask {
|
||||
let! group =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT * FROM pt.small_group WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid groupId.Value ]
|
||||
|> Sql.executeAsync mapToSmallGroup
|
||||
return List.tryHead group
|
||||
}
|
||||
|
||||
/// Get a small group by its ID with its list preferences populated
|
||||
let tryByIdWithPreferences (groupId : SmallGroupId) conn = backgroundTask {
|
||||
let! group =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT sg.*, lp.*
|
||||
FROM pt.small_group sg
|
||||
INNER JOIN pt.list_preference lp ON lp.small_group_id = sg.id
|
||||
WHERE sg.id = @id"""
|
||||
|> Sql.parameters [ "@id", Sql.uuid groupId.Value ]
|
||||
|> Sql.executeAsync mapToSmallGroupWithPreferences
|
||||
return List.tryHead group
|
||||
}
|
||||
|
||||
|
||||
/// Functions to manipulate users
|
||||
module Users =
|
||||
|
||||
/// Retrieve all PrayerTracker users
|
||||
let all conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT * FROM pt.pt_user ORDER BY last_name, first_name"
|
||||
|> Sql.executeAsync mapToUser
|
||||
|
||||
/// Count the number of users for a church
|
||||
let countByChurch (churchId : ChurchId) conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT COUNT(u.id) AS user_count
|
||||
FROM pt.pt_user u
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM pt.user_small_group usg
|
||||
INNER JOIN pt.small_group sg ON sg.id = usg.small_group_id
|
||||
WHERE usg.user_id = u.id
|
||||
AND sg.church_id = @churchId)"""
|
||||
|> Sql.parameters [ "@churchId", Sql.uuid churchId.Value ]
|
||||
|> Sql.executeRowAsync (fun row -> row.int "user_count")
|
||||
|
||||
/// Count the number of users for a small group
|
||||
let countByGroup (groupId : SmallGroupId) conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT COUNT(user_id) AS user_count FROM pt.user_small_group WHERE small_group_id = @groupId"
|
||||
|> Sql.parameters [ "@groupId", Sql.uuid groupId.Value ]
|
||||
|> Sql.executeRowAsync (fun row -> row.int "user_count")
|
||||
|
||||
/// Delete a user by its database ID
|
||||
let deleteById (userId : UserId) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "DELETE FROM pt.pt_user WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid userId.Value ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Get the IDs of the small groups for which the given user is authorized
|
||||
let groupIdsByUserId (userId : UserId) conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT small_group_id FROM pt.user_small_group WHERE user_id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid userId.Value ]
|
||||
|> Sql.executeAsync (fun row -> SmallGroupId (row.uuid "small_group_id"))
|
||||
|
||||
/// Get a list of users authorized to administer the given small group
|
||||
let listByGroupId (groupId : SmallGroupId) conn =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT u.*
|
||||
FROM pt.pt_user u
|
||||
INNER JOIN pt.user_small_group usg ON usg.user_id = u.id
|
||||
WHERE usg.small_group_id = @groupId
|
||||
ORDER BY u.last_name, u.first_name"""
|
||||
|> Sql.parameters [ "@groupId", Sql.uuid groupId.Value ]
|
||||
|> Sql.executeAsync mapToUser
|
||||
|
||||
/// Save a user's information
|
||||
let save (user : User) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
INSERT INTO pt.pt_user (
|
||||
id, first_name, last_name, email, is_admin, password_hash
|
||||
) VALUES (
|
||||
@id, @firstName, @lastName, @email, @isAdmin, @passwordHash
|
||||
) ON CONFLICT (id) DO UPDATE
|
||||
SET first_name = EXCLUDED.first_name,
|
||||
last_name = EXCLUDED.last_name,
|
||||
email = EXCLUDED.email,
|
||||
is_admin = EXCLUDED.is_admin,
|
||||
password_hash = EXCLUDED.password_hash"""
|
||||
|> Sql.parameters
|
||||
[ "@id", Sql.uuid user.Id.Value
|
||||
"@firstName", Sql.string user.FirstName
|
||||
"@lastName", Sql.string user.LastName
|
||||
"@email", Sql.string user.Email
|
||||
"@isAdmin", Sql.bool user.IsAdmin
|
||||
"@passwordHash", Sql.string user.PasswordHash
|
||||
]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Find a user by its e-mail address and authorized small group
|
||||
let tryByEmailAndGroup email (groupId : SmallGroupId) conn = backgroundTask {
|
||||
let! user =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query """
|
||||
SELECT u.*
|
||||
FROM pt.pt_user u
|
||||
INNER JOIN pt.user_small_group usg ON usg.user_id = u.id AND usg.small_group_id = @groupId
|
||||
WHERE u.email = @email"""
|
||||
|> Sql.parameters [ "@email", Sql.string email; "@groupId", Sql.uuid groupId.Value ]
|
||||
|> Sql.executeAsync mapToUser
|
||||
return List.tryHead user
|
||||
}
|
||||
|
||||
/// Find a user by their database ID
|
||||
let tryById (userId : UserId) conn = backgroundTask {
|
||||
let! user =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "SELECT * FROM pt.pt_user WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid userId.Value ]
|
||||
|> Sql.executeAsync mapToUser
|
||||
return List.tryHead user
|
||||
}
|
||||
|
||||
/// Update a user's last seen date/time
|
||||
let updateLastSeen (userId : UserId) (now : Instant) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "UPDATE pt.pt_user SET last_seen = @now WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid userId.Value; "@now", Sql.parameter (NpgsqlParameter ("@now", now)) ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Update a user's password hash
|
||||
let updatePassword (user : User) conn = backgroundTask {
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.query "UPDATE pt.pt_user SET password_hash = @passwordHash WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.uuid user.Id.Value; "@passwordHash", Sql.string user.PasswordHash ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
return ()
|
||||
}
|
||||
|
||||
/// Update a user's authorized small groups
|
||||
let updateSmallGroups (userId : UserId) groupIds conn = backgroundTask {
|
||||
let! existingGroupIds = groupIdsByUserId userId conn
|
||||
let toAdd =
|
||||
groupIds |> List.filter (fun it -> existingGroupIds |> List.exists (fun grpId -> grpId = it) |> not)
|
||||
let toDelete =
|
||||
existingGroupIds |> List.filter (fun it -> groupIds |> List.exists (fun grpId -> grpId = it) |> not)
|
||||
let queries = seq {
|
||||
if not (List.isEmpty toAdd) then
|
||||
"INSERT INTO pt.user_small_group VALUES (@userId, @smallGroupId)",
|
||||
toAdd |> List.map (fun it -> [ "@userId", Sql.uuid userId.Value; "@smallGroupId", Sql.uuid it.Value ])
|
||||
if not (List.isEmpty toDelete) then
|
||||
"DELETE FROM pt.user_small_group WHERE user_id = @userId AND small_group_id = @smallGroupId",
|
||||
toDelete
|
||||
|> List.map (fun it -> [ "@userId", Sql.uuid userId.Value; "@smallGroupId", Sql.uuid it.Value ])
|
||||
}
|
||||
if not (Seq.isEmpty queries) then
|
||||
let! _ =
|
||||
Sql.existingConnection conn
|
||||
|> Sql.executeTransactionAsync (List.ofSeq queries)
|
||||
()
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
namespace PrayerTracker
|
||||
|
||||
open Microsoft.EntityFrameworkCore
|
||||
open PrayerTracker.Entities
|
||||
|
||||
/// EF Core data context for PrayerTracker
|
||||
[<AllowNullLiteral>]
|
||||
type AppDbContext (options : DbContextOptions<AppDbContext>) =
|
||||
inherit DbContext (options)
|
||||
|
||||
[<DefaultValue>]
|
||||
val mutable private churches : DbSet<Church>
|
||||
[<DefaultValue>]
|
||||
val mutable private members : DbSet<Member>
|
||||
[<DefaultValue>]
|
||||
val mutable private prayerRequests : DbSet<PrayerRequest>
|
||||
[<DefaultValue>]
|
||||
val mutable private preferences : DbSet<ListPreferences>
|
||||
[<DefaultValue>]
|
||||
val mutable private smallGroups : DbSet<SmallGroup>
|
||||
[<DefaultValue>]
|
||||
val mutable private timeZones : DbSet<TimeZone>
|
||||
[<DefaultValue>]
|
||||
val mutable private users : DbSet<User>
|
||||
[<DefaultValue>]
|
||||
val mutable private userGroupXref : DbSet<UserSmallGroup>
|
||||
|
||||
/// Churches
|
||||
member this.Churches
|
||||
with get() = this.churches
|
||||
and set v = this.churches <- v
|
||||
|
||||
/// Small group members
|
||||
member this.Members
|
||||
with get() = this.members
|
||||
and set v = this.members <- v
|
||||
|
||||
/// Prayer requests
|
||||
member this.PrayerRequests
|
||||
with get() = this.prayerRequests
|
||||
and set v = this.prayerRequests <- v
|
||||
|
||||
/// Request list preferences (by class)
|
||||
member this.Preferences
|
||||
with get() = this.preferences
|
||||
and set v = this.preferences <- v
|
||||
|
||||
/// Small groups
|
||||
member this.SmallGroups
|
||||
with get() = this.smallGroups
|
||||
and set v = this.smallGroups <- v
|
||||
|
||||
/// Time zones
|
||||
member this.TimeZones
|
||||
with get() = this.timeZones
|
||||
and set v = this.timeZones <- v
|
||||
|
||||
/// Users
|
||||
member this.Users
|
||||
with get() = this.users
|
||||
and set v = this.users <- v
|
||||
|
||||
/// User / small group cross-reference
|
||||
member this.UserGroupXref
|
||||
with get() = this.userGroupXref
|
||||
and set v = this.userGroupXref <- v
|
||||
|
||||
/// F#-style async for saving changes
|
||||
member this.AsyncSaveChanges () =
|
||||
this.SaveChangesAsync () |> Async.AwaitTask
|
||||
|
||||
override __.OnModelCreating (modelBuilder : ModelBuilder) =
|
||||
base.OnModelCreating modelBuilder
|
||||
|
||||
modelBuilder.HasDefaultSchema "pt" |> ignore
|
||||
|
||||
[ Church.configureEF
|
||||
ListPreferences.configureEF
|
||||
Member.configureEF
|
||||
PrayerRequest.configureEF
|
||||
SmallGroup.configureEF
|
||||
TimeZone.configureEF
|
||||
User.configureEF
|
||||
UserSmallGroup.configureEF
|
||||
]
|
||||
|> List.iter (fun x -> x modelBuilder)
|
||||
@@ -1,373 +0,0 @@
|
||||
[<AutoOpen>]
|
||||
module PrayerTracker.DataAccess
|
||||
|
||||
open Microsoft.EntityFrameworkCore
|
||||
open PrayerTracker.Entities
|
||||
open System.Collections.Generic
|
||||
open System.Linq
|
||||
|
||||
[<AutoOpen>]
|
||||
module private Helpers =
|
||||
|
||||
open Microsoft.FSharpLu
|
||||
open System.Threading.Tasks
|
||||
|
||||
/// Central place to append sort criteria for prayer request queries
|
||||
let reqSort sort (q : IQueryable<PrayerRequest>) =
|
||||
match sort with
|
||||
| SortByDate ->
|
||||
query {
|
||||
for req in q do
|
||||
sortByDescending req.updatedDate
|
||||
thenByDescending req.enteredDate
|
||||
thenBy req.requestor
|
||||
}
|
||||
| SortByRequestor ->
|
||||
query {
|
||||
for req in q do
|
||||
sortBy req.requestor
|
||||
thenByDescending req.updatedDate
|
||||
thenByDescending req.enteredDate
|
||||
}
|
||||
|
||||
/// Convert a possibly-null object to an option, wrapped as a task
|
||||
let toOptionTask<'T> (item : 'T) = (Option.fromObject >> Task.FromResult) item
|
||||
|
||||
|
||||
type AppDbContext with
|
||||
|
||||
(*-- DISCONNECTED DATA EXTENSIONS --*)
|
||||
|
||||
/// Add an entity entry to the tracked data context with the status of Added
|
||||
member this.AddEntry<'TEntity when 'TEntity : not struct> (e : 'TEntity) =
|
||||
this.Entry<'TEntity>(e).State <- EntityState.Added
|
||||
|
||||
/// Add an entity entry to the tracked data context with the status of Updated
|
||||
member this.UpdateEntry<'TEntity when 'TEntity : not struct> (e : 'TEntity) =
|
||||
this.Entry<'TEntity>(e).State <- EntityState.Modified
|
||||
|
||||
/// Add an entity entry to the tracked data context with the status of Deleted
|
||||
member this.RemoveEntry<'TEntity when 'TEntity : not struct> (e : 'TEntity) =
|
||||
this.Entry<'TEntity>(e).State <- EntityState.Deleted
|
||||
|
||||
(*-- CHURCH EXTENSIONS --*)
|
||||
|
||||
/// Find a church by its Id
|
||||
member this.TryChurchById cId =
|
||||
query {
|
||||
for ch in this.Churches.AsNoTracking () do
|
||||
where (ch.churchId = cId)
|
||||
exactlyOneOrDefault
|
||||
}
|
||||
|> toOptionTask
|
||||
|
||||
/// Find all churches
|
||||
member this.AllChurches () =
|
||||
task {
|
||||
let q =
|
||||
query {
|
||||
for ch in this.Churches.AsNoTracking () do
|
||||
sortBy ch.name
|
||||
}
|
||||
let! churches = q.ToListAsync ()
|
||||
return List.ofSeq churches
|
||||
}
|
||||
|
||||
(*-- MEMBER EXTENSIONS --*)
|
||||
|
||||
/// Get a small group member by its Id
|
||||
member this.TryMemberById mId =
|
||||
query {
|
||||
for mbr in this.Members.AsNoTracking () do
|
||||
where (mbr.memberId = mId)
|
||||
select mbr
|
||||
exactlyOneOrDefault
|
||||
}
|
||||
|> toOptionTask
|
||||
|
||||
/// Find all members for a small group
|
||||
member this.AllMembersForSmallGroup gId =
|
||||
task {
|
||||
let q =
|
||||
query {
|
||||
for mbr in this.Members.AsNoTracking () do
|
||||
where (mbr.smallGroupId = gId)
|
||||
sortBy mbr.memberName
|
||||
}
|
||||
let! mbrs = q.ToListAsync ()
|
||||
return List.ofSeq mbrs
|
||||
}
|
||||
|
||||
/// Count members for a small group
|
||||
member this.CountMembersForSmallGroup gId =
|
||||
this.Members.CountAsync (fun m -> m.smallGroupId = gId)
|
||||
|
||||
(*-- PRAYER REQUEST EXTENSIONS --*)
|
||||
|
||||
/// Get a prayer request by its Id
|
||||
member this.TryRequestById reqId =
|
||||
query {
|
||||
for req in this.PrayerRequests.AsNoTracking () do
|
||||
where (req.prayerRequestId = reqId)
|
||||
exactlyOneOrDefault
|
||||
}
|
||||
|> toOptionTask
|
||||
|
||||
/// Get all (or active) requests for a small group as of now or the specified date
|
||||
// TODO: why not make this an async list like the rest of these methods?
|
||||
member this.AllRequestsForSmallGroup (grp : SmallGroup) clock listDate activeOnly pageNbr : PrayerRequest seq =
|
||||
let theDate = match listDate with Some dt -> dt | _ -> grp.localDateNow clock
|
||||
query {
|
||||
for req in this.PrayerRequests.AsNoTracking () do
|
||||
where (req.smallGroupId = grp.smallGroupId)
|
||||
}
|
||||
|> function
|
||||
| q when activeOnly ->
|
||||
let asOf = theDate.AddDays(-(float grp.preferences.daysToExpire)).Date
|
||||
query {
|
||||
for req in q do
|
||||
where ( ( req.updatedDate > asOf
|
||||
|| req.expiration = Manual
|
||||
|| req.requestType = LongTermRequest
|
||||
|| req.requestType = Expecting)
|
||||
&& req.expiration <> Forced)
|
||||
}
|
||||
| q -> q
|
||||
|> reqSort grp.preferences.requestSort
|
||||
|> function
|
||||
| q ->
|
||||
match activeOnly with
|
||||
| true -> upcast q
|
||||
| false ->
|
||||
upcast query {
|
||||
for req in q do
|
||||
skip ((pageNbr - 1) * grp.preferences.pageSize)
|
||||
take grp.preferences.pageSize
|
||||
}
|
||||
|
||||
/// Count prayer requests for the given small group Id
|
||||
member this.CountRequestsBySmallGroup gId =
|
||||
this.PrayerRequests.CountAsync (fun pr -> pr.smallGroupId = gId)
|
||||
|
||||
/// Count prayer requests for the given church Id
|
||||
member this.CountRequestsByChurch cId =
|
||||
this.PrayerRequests.CountAsync (fun pr -> pr.smallGroup.churchId = cId)
|
||||
|
||||
/// Get all (or active) requests for a small group as of now or the specified date
|
||||
// TODO: same as above...
|
||||
member this.SearchRequestsForSmallGroup (grp : SmallGroup) (searchTerm : string) pageNbr : PrayerRequest seq =
|
||||
let pgSz = grp.preferences.pageSize
|
||||
let toSkip = (pageNbr - 1) * pgSz
|
||||
let sql =
|
||||
""" SELECT * FROM pt."PrayerRequest" WHERE "SmallGroupId" = {0} AND "Text" ILIKE {1}
|
||||
UNION
|
||||
SELECT * FROM pt."PrayerRequest" WHERE "SmallGroupId" = {0} AND COALESCE("Requestor", '') ILIKE {1}"""
|
||||
let like = sprintf "%%%s%%"
|
||||
this.PrayerRequests.FromSqlRaw(sql, grp.smallGroupId, like searchTerm).AsNoTracking ()
|
||||
|> reqSort grp.preferences.requestSort
|
||||
|> function
|
||||
| q ->
|
||||
upcast query {
|
||||
for req in q do
|
||||
skip toSkip
|
||||
take pgSz
|
||||
}
|
||||
|
||||
(*-- SMALL GROUP EXTENSIONS --*)
|
||||
|
||||
/// Find a small group by its Id
|
||||
member this.TryGroupById gId =
|
||||
query {
|
||||
for grp in this.SmallGroups.AsNoTracking().Include (fun sg -> sg.preferences) do
|
||||
where (grp.smallGroupId = gId)
|
||||
exactlyOneOrDefault
|
||||
}
|
||||
|> toOptionTask
|
||||
|
||||
/// Get small groups that are public or password protected
|
||||
member this.PublicAndProtectedGroups () =
|
||||
task {
|
||||
let smallGroups = this.SmallGroups.AsNoTracking().Include(fun sg -> sg.preferences).Include (fun sg -> sg.church)
|
||||
let q =
|
||||
query {
|
||||
for grp in smallGroups do
|
||||
where ( grp.preferences.isPublic
|
||||
|| (grp.preferences.groupPassword <> null && grp.preferences.groupPassword <> ""))
|
||||
sortBy grp.church.name
|
||||
thenBy grp.name
|
||||
}
|
||||
let! grps = q.ToListAsync ()
|
||||
return List.ofSeq grps
|
||||
}
|
||||
|
||||
/// Get small groups that are password protected
|
||||
member this.ProtectedGroups () =
|
||||
task {
|
||||
let q =
|
||||
query {
|
||||
for grp in this.SmallGroups.AsNoTracking().Include (fun sg -> sg.church) do
|
||||
where (grp.preferences.groupPassword <> null && grp.preferences.groupPassword <> "")
|
||||
sortBy grp.church.name
|
||||
thenBy grp.name
|
||||
}
|
||||
let! grps = q.ToListAsync ()
|
||||
return List.ofSeq grps
|
||||
}
|
||||
|
||||
/// Get all small groups
|
||||
member this.AllGroups () =
|
||||
task {
|
||||
let! grps =
|
||||
this.SmallGroups.AsNoTracking()
|
||||
.Include(fun sg -> sg.church)
|
||||
.Include(fun sg -> sg.preferences)
|
||||
.Include(fun sg -> sg.preferences.timeZone)
|
||||
.OrderBy(fun sg -> sg.name)
|
||||
.ToListAsync ()
|
||||
return List.ofSeq grps
|
||||
}
|
||||
|
||||
/// Get a small group list by their Id, with their church prepended to their name
|
||||
member this.GroupList () =
|
||||
task {
|
||||
let q =
|
||||
query {
|
||||
for grp in this.SmallGroups.AsNoTracking().Include (fun sg -> sg.church) do
|
||||
sortBy grp.church.name
|
||||
thenBy grp.name
|
||||
}
|
||||
let! grps = q.ToListAsync ()
|
||||
return grps
|
||||
|> Seq.map (fun grp -> grp.smallGroupId.ToString "N", $"{grp.church.name} | {grp.name}")
|
||||
|> List.ofSeq
|
||||
}
|
||||
|
||||
/// Log on a small group
|
||||
member this.TryGroupLogOnByPassword gId pw =
|
||||
task {
|
||||
match! this.TryGroupById gId with
|
||||
| None -> return None
|
||||
| Some grp ->
|
||||
match pw = grp.preferences.groupPassword with
|
||||
| true -> return Some grp
|
||||
| _ -> return None
|
||||
}
|
||||
|
||||
/// Check a cookie log on for a small group
|
||||
member this.TryGroupLogOnByCookie gId pwHash (hasher : string -> string) =
|
||||
task {
|
||||
match! this.TryGroupById gId with
|
||||
| None -> return None
|
||||
| Some grp ->
|
||||
match pwHash = hasher grp.preferences.groupPassword with
|
||||
| true -> return Some grp
|
||||
| _ -> return None
|
||||
}
|
||||
|
||||
/// Count small groups for the given church Id
|
||||
member this.CountGroupsByChurch cId =
|
||||
this.SmallGroups.CountAsync (fun sg -> sg.churchId = cId)
|
||||
|
||||
(*-- TIME ZONE EXTENSIONS --*)
|
||||
|
||||
/// Get a time zone by its Id
|
||||
member this.TryTimeZoneById tzId =
|
||||
query {
|
||||
for tz in this.TimeZones do
|
||||
where (tz.timeZoneId = tzId)
|
||||
exactlyOneOrDefault
|
||||
}
|
||||
|> toOptionTask
|
||||
|
||||
/// Get all time zones
|
||||
member this.AllTimeZones () =
|
||||
task {
|
||||
let q =
|
||||
query {
|
||||
for tz in this.TimeZones do
|
||||
sortBy tz.sortOrder
|
||||
}
|
||||
let! tzs = q.ToListAsync ()
|
||||
return List.ofSeq tzs
|
||||
}
|
||||
|
||||
(*-- USER EXTENSIONS --*)
|
||||
|
||||
/// Find a user by its Id
|
||||
member this.TryUserById uId =
|
||||
query {
|
||||
for usr in this.Users.AsNoTracking () do
|
||||
where (usr.userId = uId)
|
||||
exactlyOneOrDefault
|
||||
}
|
||||
|> toOptionTask
|
||||
|
||||
/// Find a user by its e-mail address and authorized small group
|
||||
member this.TryUserByEmailAndGroup email gId =
|
||||
query {
|
||||
for usr in this.Users.AsNoTracking () do
|
||||
where (usr.emailAddress = email && usr.smallGroups.Any (fun xref -> xref.smallGroupId = gId))
|
||||
exactlyOneOrDefault
|
||||
}
|
||||
|> toOptionTask
|
||||
|
||||
/// Find a user by its Id (tracked entity), eagerly loading the user's groups
|
||||
member this.TryUserByIdWithGroups uId =
|
||||
query {
|
||||
for usr in this.Users.AsNoTracking().Include (fun u -> u.smallGroups) do
|
||||
where (usr.userId = uId)
|
||||
exactlyOneOrDefault
|
||||
}
|
||||
|> toOptionTask
|
||||
|
||||
/// Get a list of all users
|
||||
member this.AllUsers () =
|
||||
task {
|
||||
let q =
|
||||
query {
|
||||
for usr in this.Users.AsNoTracking () do
|
||||
sortBy usr.lastName
|
||||
thenBy usr.firstName
|
||||
}
|
||||
let! usrs = q.ToListAsync ()
|
||||
return List.ofSeq usrs
|
||||
}
|
||||
|
||||
/// Get all PrayerTracker users as members (used to send e-mails)
|
||||
member this.AllUsersAsMembers () =
|
||||
task {
|
||||
let! users = this.AllUsers ()
|
||||
return users |> List.map (fun u -> { Member.empty with email = u.emailAddress; memberName = u.fullName })
|
||||
}
|
||||
|
||||
/// Find a user based on their credentials
|
||||
member this.TryUserLogOnByPassword email pwHash gId =
|
||||
query {
|
||||
for usr in this.Users.AsNoTracking () do
|
||||
where ( usr.emailAddress = email
|
||||
&& usr.passwordHash = pwHash
|
||||
&& usr.smallGroups.Any (fun xref -> xref.smallGroupId = gId))
|
||||
exactlyOneOrDefault
|
||||
}
|
||||
|> toOptionTask
|
||||
|
||||
/// Find a user based on credentials stored in a cookie
|
||||
member this.TryUserLogOnByCookie uId gId pwHash =
|
||||
task {
|
||||
match! this.TryUserByIdWithGroups uId with
|
||||
| None -> return None
|
||||
| Some usr ->
|
||||
match pwHash = usr.passwordHash && usr.smallGroups |> Seq.exists (fun xref -> xref.smallGroupId = gId) with
|
||||
| true ->
|
||||
this.Entry<User>(usr).State <- EntityState.Detached
|
||||
return Some { usr with passwordHash = ""; salt = None; smallGroups = List<UserSmallGroup>() }
|
||||
| _ -> return None
|
||||
}
|
||||
|
||||
/// Count the number of users for a small group
|
||||
member this.CountUsersBySmallGroup gId =
|
||||
this.Users.CountAsync (fun u -> u.smallGroups.Any (fun xref -> xref.smallGroupId = gId))
|
||||
|
||||
/// Count the number of users for a church
|
||||
member this.CountUsersByChurch cId =
|
||||
this.Users.CountAsync (fun u -> u.smallGroups.Any (fun xref -> xref.smallGroup.churchId = cId))
|
||||
218
src/PrayerTracker.Data/DistributedCache.fs
Normal file
218
src/PrayerTracker.Data/DistributedCache.fs
Normal file
@@ -0,0 +1,218 @@
|
||||
namespace PrayerTracker.Data
|
||||
|
||||
open System.Threading
|
||||
open System.Threading.Tasks
|
||||
open Microsoft.Extensions.Caching.Distributed
|
||||
open NodaTime
|
||||
open Npgsql
|
||||
open Npgsql.FSharp
|
||||
|
||||
/// Helper types and functions for the cache
|
||||
[<AutoOpen>]
|
||||
module private CacheHelpers =
|
||||
|
||||
open System
|
||||
|
||||
/// The cache entry
|
||||
type Entry =
|
||||
{ /// The ID of the cache entry
|
||||
Id : string
|
||||
|
||||
/// The value to be cached
|
||||
Payload : byte[]
|
||||
|
||||
/// When this entry will expire
|
||||
ExpireAt : Instant
|
||||
|
||||
/// The duration by which the expiration should be pushed out when being refreshed
|
||||
SlidingExpiration : Duration option
|
||||
|
||||
/// The must-expire-by date/time for the cache entry
|
||||
AbsoluteExpiration : Instant option
|
||||
}
|
||||
|
||||
/// Run a task synchronously
|
||||
let sync<'T> (it : Task<'T>) = it |> (Async.AwaitTask >> Async.RunSynchronously)
|
||||
|
||||
/// Get the current instant
|
||||
let getNow () = SystemClock.Instance.GetCurrentInstant ()
|
||||
|
||||
/// Create a parameter for the expire-at time
|
||||
let expireParam (it : Instant) =
|
||||
"@expireAt", Sql.parameter (NpgsqlParameter ("@expireAt", it))
|
||||
|
||||
/// Create a parameter for a possibly-missing NodaTime type
|
||||
let optParam<'T> name (it : 'T option) =
|
||||
let p = NpgsqlParameter ($"@%s{name}", if Option.isSome it then box it.Value else DBNull.Value)
|
||||
p.ParameterName, Sql.parameter p
|
||||
|
||||
|
||||
/// A distributed cache implementation in PostgreSQL used to handle sessions for myWebLog
|
||||
type DistributedCache (connStr : string) =
|
||||
|
||||
// ~~~ INITIALIZATION ~~~
|
||||
|
||||
do
|
||||
task {
|
||||
let! exists =
|
||||
Sql.connect connStr
|
||||
|> Sql.query $"
|
||||
SELECT EXISTS
|
||||
(SELECT 1 FROM pg_tables WHERE schemaname = 'public' AND tablename = 'session')
|
||||
AS does_exist"
|
||||
|> Sql.executeRowAsync (fun row -> row.bool "does_exist")
|
||||
if not exists then
|
||||
let! _ =
|
||||
Sql.connect connStr
|
||||
|> Sql.query
|
||||
"CREATE TABLE session (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
payload BYTEA NOT NULL,
|
||||
expire_at TIMESTAMPTZ NOT NULL,
|
||||
sliding_expiration INTERVAL,
|
||||
absolute_expiration TIMESTAMPTZ);
|
||||
CREATE INDEX idx_session_expiration ON session (expire_at)"
|
||||
|> Sql.executeNonQueryAsync
|
||||
()
|
||||
} |> sync
|
||||
|
||||
// ~~~ SUPPORT FUNCTIONS ~~~
|
||||
|
||||
/// Get an entry, updating it for sliding expiration
|
||||
let getEntry key = backgroundTask {
|
||||
let idParam = "@id", Sql.string key
|
||||
let! tryEntry =
|
||||
Sql.connect connStr
|
||||
|> Sql.query "SELECT * FROM session WHERE id = @id"
|
||||
|> Sql.parameters [ idParam ]
|
||||
|> Sql.executeAsync (fun row ->
|
||||
{ Id = row.string "id"
|
||||
Payload = row.bytea "payload"
|
||||
ExpireAt = row.fieldValue<Instant> "expire_at"
|
||||
SlidingExpiration = row.fieldValueOrNone<Duration> "sliding_expiration"
|
||||
AbsoluteExpiration = row.fieldValueOrNone<Instant> "absolute_expiration" })
|
||||
match List.tryHead tryEntry with
|
||||
| Some entry ->
|
||||
let now = getNow ()
|
||||
let slideExp = defaultArg entry.SlidingExpiration Duration.MinValue
|
||||
let absExp = defaultArg entry.AbsoluteExpiration Instant.MinValue
|
||||
let needsRefresh, item =
|
||||
if entry.ExpireAt = absExp then false, entry
|
||||
elif slideExp = Duration.MinValue && absExp = Instant.MinValue then false, entry
|
||||
elif absExp > Instant.MinValue && entry.ExpireAt.Plus slideExp > absExp then
|
||||
true, { entry with ExpireAt = absExp }
|
||||
else true, { entry with ExpireAt = now.Plus slideExp }
|
||||
if needsRefresh then
|
||||
let! _ =
|
||||
Sql.connect connStr
|
||||
|> Sql.query "UPDATE session SET expire_at = @expireAt WHERE id = @id"
|
||||
|> Sql.parameters [ expireParam item.ExpireAt; idParam ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
()
|
||||
return if item.ExpireAt > now then Some entry else None
|
||||
| None -> return None
|
||||
}
|
||||
|
||||
/// The last time expired entries were purged (runs every 30 minutes)
|
||||
let mutable lastPurge = Instant.MinValue
|
||||
|
||||
/// Purge expired entries every 30 minutes
|
||||
let purge () = backgroundTask {
|
||||
let now = getNow ()
|
||||
if lastPurge.Plus (Duration.FromMinutes 30L) < now then
|
||||
let! _ =
|
||||
Sql.connect connStr
|
||||
|> Sql.query "DELETE FROM session WHERE expire_at < @expireAt"
|
||||
|> Sql.parameters [ expireParam now ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
lastPurge <- now
|
||||
}
|
||||
|
||||
/// Remove a cache entry
|
||||
let removeEntry key = backgroundTask {
|
||||
let! _ =
|
||||
Sql.connect connStr
|
||||
|> Sql.query "DELETE FROM session WHERE id = @id"
|
||||
|> Sql.parameters [ "@id", Sql.string key ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
()
|
||||
}
|
||||
|
||||
/// Save an entry
|
||||
let saveEntry (opts : DistributedCacheEntryOptions) key payload = backgroundTask {
|
||||
let now = getNow ()
|
||||
let expireAt, slideExp, absExp =
|
||||
if opts.SlidingExpiration.HasValue then
|
||||
let slide = Duration.FromTimeSpan opts.SlidingExpiration.Value
|
||||
now.Plus slide, Some slide, None
|
||||
elif opts.AbsoluteExpiration.HasValue then
|
||||
let exp = Instant.FromDateTimeOffset opts.AbsoluteExpiration.Value
|
||||
exp, None, Some exp
|
||||
elif opts.AbsoluteExpirationRelativeToNow.HasValue then
|
||||
let exp = now.Plus (Duration.FromTimeSpan opts.AbsoluteExpirationRelativeToNow.Value)
|
||||
exp, None, Some exp
|
||||
else
|
||||
// Default to 2 hour sliding expiration
|
||||
let slide = Duration.FromHours 2
|
||||
now.Plus slide, Some slide, None
|
||||
let! _ =
|
||||
Sql.connect connStr
|
||||
|> Sql.query
|
||||
"INSERT INTO session (
|
||||
id, payload, expire_at, sliding_expiration, absolute_expiration
|
||||
) VALUES (
|
||||
@id, @payload, @expireAt, @slideExp, @absExp
|
||||
) ON CONFLICT (id) DO UPDATE
|
||||
SET payload = EXCLUDED.payload,
|
||||
expire_at = EXCLUDED.expire_at,
|
||||
sliding_expiration = EXCLUDED.sliding_expiration,
|
||||
absolute_expiration = EXCLUDED.absolute_expiration"
|
||||
|> Sql.parameters
|
||||
[ "@id", Sql.string key
|
||||
"@payload", Sql.bytea payload
|
||||
expireParam expireAt
|
||||
optParam "slideExp" slideExp
|
||||
optParam "absExp" absExp ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
()
|
||||
}
|
||||
|
||||
// ~~~ IMPLEMENTATION FUNCTIONS ~~~
|
||||
|
||||
/// Retrieve the data for a cache entry
|
||||
let get key (_ : CancellationToken) = backgroundTask {
|
||||
match! getEntry key with
|
||||
| Some entry ->
|
||||
do! purge ()
|
||||
return entry.Payload
|
||||
| None -> return null
|
||||
}
|
||||
|
||||
/// Refresh an entry
|
||||
let refresh key (cancelToken : CancellationToken) = backgroundTask {
|
||||
let! _ = get key cancelToken
|
||||
()
|
||||
}
|
||||
|
||||
/// Remove an entry
|
||||
let remove key (_ : CancellationToken) = backgroundTask {
|
||||
do! removeEntry key
|
||||
do! purge ()
|
||||
}
|
||||
|
||||
/// Set an entry
|
||||
let set key value options (_ : CancellationToken) = backgroundTask {
|
||||
do! saveEntry options key value
|
||||
do! purge ()
|
||||
}
|
||||
|
||||
interface IDistributedCache with
|
||||
member this.Get key = get key CancellationToken.None |> sync
|
||||
member this.GetAsync (key, token) = get key token
|
||||
member this.Refresh key = refresh key CancellationToken.None |> sync
|
||||
member this.RefreshAsync (key, token) = refresh key token
|
||||
member this.Remove key = remove key CancellationToken.None |> sync
|
||||
member this.RemoveAsync (key, token) = remove key token
|
||||
member this.Set (key, value, options) = set key value options CancellationToken.None |> sync
|
||||
member this.SetAsync (key, value, options, token) = set key value options token
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,514 +0,0 @@
|
||||
namespace PrayerTracker.Migrations
|
||||
|
||||
open Microsoft.EntityFrameworkCore
|
||||
open Microsoft.EntityFrameworkCore.Infrastructure
|
||||
open Microsoft.EntityFrameworkCore.Migrations
|
||||
open Microsoft.EntityFrameworkCore.Migrations.Operations
|
||||
open Microsoft.EntityFrameworkCore.Migrations.Operations.Builders
|
||||
open Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
|
||||
open PrayerTracker
|
||||
open PrayerTracker.Entities
|
||||
open System
|
||||
|
||||
// fsharplint:disable RecordFieldNames
|
||||
|
||||
type ChurchTable =
|
||||
{ churchId : OperationBuilder<AddColumnOperation>
|
||||
city : OperationBuilder<AddColumnOperation>
|
||||
hasInterface : OperationBuilder<AddColumnOperation>
|
||||
interfaceAddress : OperationBuilder<AddColumnOperation>
|
||||
name : OperationBuilder<AddColumnOperation>
|
||||
st : OperationBuilder<AddColumnOperation>
|
||||
}
|
||||
|
||||
type ListPreferencesTable =
|
||||
{ smallGroupId : OperationBuilder<AddColumnOperation>
|
||||
daysToExpire : OperationBuilder<AddColumnOperation>
|
||||
daysToKeepNew : OperationBuilder<AddColumnOperation>
|
||||
defaultEmailType : OperationBuilder<AddColumnOperation>
|
||||
emailFromAddress : OperationBuilder<AddColumnOperation>
|
||||
emailFromName : OperationBuilder<AddColumnOperation>
|
||||
groupPassword : OperationBuilder<AddColumnOperation>
|
||||
headingColor : OperationBuilder<AddColumnOperation>
|
||||
headingFontSize : OperationBuilder<AddColumnOperation>
|
||||
isPublic : OperationBuilder<AddColumnOperation>
|
||||
lineColor : OperationBuilder<AddColumnOperation>
|
||||
listFonts : OperationBuilder<AddColumnOperation>
|
||||
longTermUpdateWeeks : OperationBuilder<AddColumnOperation>
|
||||
requestSort : OperationBuilder<AddColumnOperation>
|
||||
textFontSize : OperationBuilder<AddColumnOperation>
|
||||
timeZoneId : OperationBuilder<AddColumnOperation>
|
||||
pageSize : OperationBuilder<AddColumnOperation>
|
||||
asOfDateDisplay : OperationBuilder<AddColumnOperation>
|
||||
}
|
||||
|
||||
type MemberTable =
|
||||
{ memberId : OperationBuilder<AddColumnOperation>
|
||||
email : OperationBuilder<AddColumnOperation>
|
||||
format : OperationBuilder<AddColumnOperation>
|
||||
memberName : OperationBuilder<AddColumnOperation>
|
||||
smallGroupId : OperationBuilder<AddColumnOperation>
|
||||
}
|
||||
|
||||
type PrayerRequestTable =
|
||||
{ prayerRequestId : OperationBuilder<AddColumnOperation>
|
||||
enteredDate : OperationBuilder<AddColumnOperation>
|
||||
expiration : OperationBuilder<AddColumnOperation>
|
||||
notifyChaplain : OperationBuilder<AddColumnOperation>
|
||||
requestType : OperationBuilder<AddColumnOperation>
|
||||
requestor : OperationBuilder<AddColumnOperation>
|
||||
smallGroupId : OperationBuilder<AddColumnOperation>
|
||||
text : OperationBuilder<AddColumnOperation>
|
||||
updatedDate : OperationBuilder<AddColumnOperation>
|
||||
userId : OperationBuilder<AddColumnOperation>
|
||||
}
|
||||
|
||||
type SmallGroupTable =
|
||||
{ smallGroupId : OperationBuilder<AddColumnOperation>
|
||||
churchId : OperationBuilder<AddColumnOperation>
|
||||
name : OperationBuilder<AddColumnOperation>
|
||||
}
|
||||
|
||||
type TimeZoneTable =
|
||||
{ timeZoneId : OperationBuilder<AddColumnOperation>
|
||||
description : OperationBuilder<AddColumnOperation>
|
||||
isActive : OperationBuilder<AddColumnOperation>
|
||||
sortOrder : OperationBuilder<AddColumnOperation>
|
||||
}
|
||||
|
||||
type UserSmallGroupTable =
|
||||
{ userId : OperationBuilder<AddColumnOperation>
|
||||
smallGroupId : OperationBuilder<AddColumnOperation>
|
||||
}
|
||||
|
||||
type UserTable =
|
||||
{ userId : OperationBuilder<AddColumnOperation>
|
||||
emailAddress : OperationBuilder<AddColumnOperation>
|
||||
firstName : OperationBuilder<AddColumnOperation>
|
||||
isAdmin : OperationBuilder<AddColumnOperation>
|
||||
lastName : OperationBuilder<AddColumnOperation>
|
||||
passwordHash : OperationBuilder<AddColumnOperation>
|
||||
salt : OperationBuilder<AddColumnOperation>
|
||||
}
|
||||
|
||||
[<DbContext (typeof<AppDbContext>)>]
|
||||
[<Migration "20161217153124_InitialDatabase">]
|
||||
type InitialDatabase () =
|
||||
inherit Migration ()
|
||||
override __.Up (migrationBuilder : MigrationBuilder) =
|
||||
migrationBuilder.EnsureSchema (name = "pt")
|
||||
|> ignore
|
||||
|
||||
migrationBuilder.CreateTable (
|
||||
name = "Church",
|
||||
schema = "pt",
|
||||
columns =
|
||||
(fun table ->
|
||||
{ churchId = table.Column<Guid> (name = "ChurchId", nullable = false)
|
||||
city = table.Column<string> (name = "City", nullable = false)
|
||||
hasInterface = table.Column<bool> (name = "HasVirtualPrayerRoomInterface", nullable = false)
|
||||
interfaceAddress = table.Column<string> (name = "InterfaceAddress", nullable = true)
|
||||
name = table.Column<string> (name = "Name", nullable = false)
|
||||
st = table.Column<string> (name = "ST", nullable = false, maxLength = Nullable<int> 2)
|
||||
}),
|
||||
constraints =
|
||||
fun table ->
|
||||
table.PrimaryKey ("PK_Church", fun x -> upcast x.churchId) |> ignore)
|
||||
|> ignore
|
||||
|
||||
migrationBuilder.CreateTable (
|
||||
name = "TimeZone",
|
||||
schema = "pt",
|
||||
columns =
|
||||
(fun table ->
|
||||
{ timeZoneId = table.Column<string> (name = "TimeZoneId", nullable = false)
|
||||
description = table.Column<string> (name = "Description", nullable = false)
|
||||
isActive = table.Column<bool> (name = "IsActive", nullable = false)
|
||||
sortOrder = table.Column<int> (name = "SortOrder", nullable = false)
|
||||
}),
|
||||
constraints =
|
||||
fun table ->
|
||||
table.PrimaryKey ("PK_TimeZone", fun x -> upcast x.timeZoneId) |> ignore)
|
||||
|> ignore
|
||||
|
||||
migrationBuilder.CreateTable (
|
||||
name = "User",
|
||||
schema = "pt",
|
||||
columns =
|
||||
(fun table ->
|
||||
{ userId = table.Column<Guid> (name = "UserId", nullable = false)
|
||||
emailAddress = table.Column<string> (name = "EmailAddress", nullable = false)
|
||||
firstName = table.Column<string> (name = "FirstName", nullable = false)
|
||||
isAdmin = table.Column<bool> (name = "IsSystemAdmin", nullable = false)
|
||||
lastName = table.Column<string> (name = "LastName", nullable = false)
|
||||
passwordHash = table.Column<string> (name = "PasswordHash", nullable = false)
|
||||
salt = table.Column<Guid> (name = "Salt", nullable = true)
|
||||
}),
|
||||
constraints =
|
||||
fun table ->
|
||||
table.PrimaryKey("PK_User", fun x -> upcast x.userId) |> ignore)
|
||||
|> ignore
|
||||
|
||||
migrationBuilder.CreateTable (
|
||||
name = "SmallGroup",
|
||||
schema = "pt",
|
||||
columns =
|
||||
(fun table ->
|
||||
{ smallGroupId = table.Column<Guid> (name = "SmallGroupId", nullable = false)
|
||||
churchId = table.Column<Guid> (name = "ChurchId", nullable = false)
|
||||
name = table.Column<string> (name = "Name", nullable = false)
|
||||
}),
|
||||
constraints =
|
||||
fun table ->
|
||||
table.PrimaryKey ("PK_SmallGroup", fun x -> upcast x.smallGroupId) |> ignore
|
||||
table.ForeignKey (
|
||||
name = "FK_SmallGroup_Church_ChurchId",
|
||||
column = (fun x -> upcast x.churchId),
|
||||
principalSchema = "pt",
|
||||
principalTable = "Church",
|
||||
principalColumn = "ChurchId",
|
||||
onDelete = ReferentialAction.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
migrationBuilder.CreateTable (
|
||||
name = "ListPreference",
|
||||
schema = "pt",
|
||||
columns =
|
||||
(fun table ->
|
||||
{ smallGroupId = table.Column<Guid> (name = "SmallGroupId", nullable = false)
|
||||
daysToExpire = table.Column<int> (name = "DaysToExpire", nullable = false, defaultValue = 14)
|
||||
daysToKeepNew = table.Column<int> (name = "DaysToKeepNew", nullable = false, defaultValue = 7)
|
||||
defaultEmailType = table.Column<string> (name = "DefaultEmailType", nullable = false, defaultValue = "Html")
|
||||
emailFromAddress = table.Column<string> (name = "EmailFromAddress", nullable = false, defaultValue = "prayer@djs-consulting.com")
|
||||
emailFromName = table.Column<string> (name = "EmailFromName", nullable = false, defaultValue = "PrayerTracker")
|
||||
groupPassword = table.Column<string> (name = "GroupPassword", nullable = false, defaultValue = "")
|
||||
headingColor = table.Column<string> (name = "HeadingColor", nullable = false, defaultValue = "maroon")
|
||||
headingFontSize = table.Column<int> (name = "HeadingFontSize", nullable = false, defaultValue = 16)
|
||||
isPublic = table.Column<bool> (name = "IsPublic", nullable = false, defaultValue = false)
|
||||
lineColor = table.Column<string> (name = "LineColor", nullable = false, defaultValue = "navy")
|
||||
listFonts = table.Column<string> (name = "ListFonts", nullable = false, defaultValue = "Century Gothic,Tahoma,Luxi Sans,sans-serif")
|
||||
longTermUpdateWeeks = table.Column<int> (name = "LongTermUpdateWeeks", nullable = false, defaultValue = 4)
|
||||
requestSort = table.Column<string> (name = "RequestSort", nullable = false, defaultValue = "D", maxLength = Nullable<int> 1)
|
||||
textFontSize = table.Column<int> (name = "TextFontSize", nullable = false, defaultValue = 12)
|
||||
timeZoneId = table.Column<string> (name = "TimeZoneId", nullable = false, defaultValue = "America/Denver")
|
||||
pageSize = table.Column<int> (name = "PageSize", nullable = false, defaultValue = 100)
|
||||
asOfDateDisplay = table.Column<string> (name = "AsOfDateDisplay", nullable = false, defaultValue = "N", maxLength = Nullable<int> 1)
|
||||
}),
|
||||
constraints =
|
||||
fun table ->
|
||||
table.PrimaryKey ("PK_ListPreference", fun x -> upcast x.smallGroupId) |> ignore
|
||||
table.ForeignKey (
|
||||
name = "FK_ListPreference_SmallGroup_SmallGroupId",
|
||||
column = (fun x -> upcast x.smallGroupId),
|
||||
principalSchema = "pt",
|
||||
principalTable = "SmallGroup",
|
||||
principalColumn = "SmallGroupId",
|
||||
onDelete = ReferentialAction.Cascade)
|
||||
|> ignore
|
||||
table.ForeignKey (
|
||||
name = "FK_ListPreference_TimeZone_TimeZoneId",
|
||||
column = (fun x -> upcast x.timeZoneId),
|
||||
principalSchema = "pt",
|
||||
principalTable = "TimeZone",
|
||||
principalColumn = "TimeZoneId",
|
||||
onDelete = ReferentialAction.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
migrationBuilder.CreateTable (
|
||||
name = "Member",
|
||||
schema = "pt",
|
||||
columns =
|
||||
(fun table ->
|
||||
{ memberId = table.Column<Guid> (name = "MemberId", nullable = false)
|
||||
email = table.Column<string> (name = "Email", nullable = false)
|
||||
format = table.Column<string> (name = "Format", nullable = true)
|
||||
memberName = table.Column<string> (name = "MemberName", nullable = false)
|
||||
smallGroupId = table.Column<Guid> (name = "SmallGroupId", nullable = false)
|
||||
}),
|
||||
constraints =
|
||||
fun table ->
|
||||
table.PrimaryKey ("PK_Member", fun x -> upcast x.memberId) |> ignore
|
||||
table.ForeignKey (
|
||||
name = "FK_Member_SmallGroup_SmallGroupId",
|
||||
column = (fun x -> upcast x.smallGroupId),
|
||||
principalSchema = "pt",
|
||||
principalTable = "SmallGroup",
|
||||
principalColumn = "SmallGroupId",
|
||||
onDelete = ReferentialAction.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
migrationBuilder.CreateTable (
|
||||
name = "PrayerRequest",
|
||||
schema = "pt",
|
||||
columns =
|
||||
(fun table ->
|
||||
{ prayerRequestId = table.Column<Guid> (name = "PrayerRequestId", nullable = false)
|
||||
expiration = table.Column<bool> (name = "Expiration", nullable = false)
|
||||
enteredDate = table.Column<DateTime> (name = "EnteredDate", nullable = false)
|
||||
notifyChaplain = table.Column<bool> (name = "NotifyChaplain", nullable = false)
|
||||
requestType = table.Column<string> (name = "RequestType", nullable = false)
|
||||
requestor = table.Column<string> (name = "Requestor", nullable = true)
|
||||
smallGroupId = table.Column<Guid> (name = "SmallGroupId", nullable = false)
|
||||
text = table.Column<string> (name = "Text", nullable = false)
|
||||
updatedDate = table.Column<DateTime> (name = "UpdatedDate", nullable = false)
|
||||
userId = table.Column<Guid> (name = "UserId", nullable = false)
|
||||
}),
|
||||
constraints =
|
||||
fun table ->
|
||||
table.PrimaryKey ("PK_PrayerRequest", fun x -> upcast x.prayerRequestId) |> ignore
|
||||
table.ForeignKey (
|
||||
name = "FK_PrayerRequest_SmallGroup_SmallGroupId",
|
||||
column = (fun x -> upcast x.smallGroupId),
|
||||
principalSchema = "pt",
|
||||
principalTable = "SmallGroup",
|
||||
principalColumn = "SmallGroupId",
|
||||
onDelete = ReferentialAction.Cascade)
|
||||
|> ignore
|
||||
table.ForeignKey (
|
||||
name = "FK_PrayerRequest_User_UserId",
|
||||
column = (fun x -> upcast x.userId),
|
||||
principalSchema = "pt",
|
||||
principalTable = "User",
|
||||
principalColumn = "UserId",
|
||||
onDelete = ReferentialAction.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name = "User_SmallGroup",
|
||||
schema = "pt",
|
||||
columns =
|
||||
(fun table ->
|
||||
{ userId = table.Column<Guid> (name = "UserId", nullable = false)
|
||||
smallGroupId = table.Column<Guid> (name = "SmallGroupId", nullable = false)
|
||||
}),
|
||||
constraints =
|
||||
fun table ->
|
||||
table.PrimaryKey ("PK_User_SmallGroup", fun x -> upcast x) |> ignore
|
||||
table.ForeignKey (
|
||||
name = "FK_User_SmallGroup_SmallGroup_SmallGroupId",
|
||||
column = (fun x -> upcast x.smallGroupId),
|
||||
principalSchema = "pt",
|
||||
principalTable = "SmallGroup",
|
||||
principalColumn = "SmallGroupId",
|
||||
onDelete = ReferentialAction.Cascade)
|
||||
|> ignore
|
||||
table.ForeignKey (
|
||||
name = "FK_User_SmallGroup_User_UserId",
|
||||
column = (fun x -> upcast x.userId),
|
||||
principalSchema = "pt",
|
||||
principalTable = "User",
|
||||
principalColumn = "UserId",
|
||||
onDelete = ReferentialAction.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
migrationBuilder.CreateIndex (name = "IX_ListPreference_TimeZoneId", schema = "pt", table = "ListPreference", column = "TimeZoneId") |> ignore
|
||||
migrationBuilder.CreateIndex (name = "IX_Member_SmallGroupId", schema = "pt", table = "Member", column = "SmallGroupId") |> ignore
|
||||
migrationBuilder.CreateIndex (name = "IX_PrayerRequest_SmallGroupId", schema = "pt", table = "PrayerRequest", column = "SmallGroupId") |> ignore
|
||||
migrationBuilder.CreateIndex (name = "IX_PrayerRequest_UserId", schema = "pt", table = "PrayerRequest", column = "UserId") |> ignore
|
||||
migrationBuilder.CreateIndex (name = "IX_SmallGroup_ChurchId", schema = "pt", table = "SmallGroup", column = "ChurchId") |> ignore
|
||||
migrationBuilder.CreateIndex (name = "IX_User_SmallGroup_SmallGroupId", schema = "pt", table = "User_SmallGroup", column = "SmallGroupId") |> ignore
|
||||
|
||||
override __.Down (migrationBuilder : MigrationBuilder) =
|
||||
migrationBuilder.DropTable (name = "ListPreference", schema = "pt") |> ignore
|
||||
migrationBuilder.DropTable (name = "Member", schema = "pt") |> ignore
|
||||
migrationBuilder.DropTable (name = "PrayerRequest", schema = "pt") |> ignore
|
||||
migrationBuilder.DropTable (name = "User_SmallGroup", schema = "pt") |> ignore
|
||||
migrationBuilder.DropTable (name = "TimeZone", schema = "pt") |> ignore
|
||||
migrationBuilder.DropTable (name = "SmallGroup", schema = "pt") |> ignore
|
||||
migrationBuilder.DropTable (name = "User", schema = "pt") |> ignore
|
||||
migrationBuilder.DropTable (name = "Church", schema = "pt") |> ignore
|
||||
|
||||
|
||||
override __.BuildTargetModel (modelBuilder : ModelBuilder) =
|
||||
modelBuilder
|
||||
.HasDefaultSchema("pt")
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
|
||||
.HasAnnotation("ProductVersion", "1.1.0-rtm-22752")
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<Church>,
|
||||
fun b ->
|
||||
b.Property<Guid>("churchId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<string>("city").IsRequired() |> ignore
|
||||
b.Property<bool>("hasInterface") |> ignore
|
||||
b.Property<string>("interfaceAddress") |> ignore
|
||||
b.Property<string>("name").IsRequired() |> ignore
|
||||
b.Property<string>("st").IsRequired().HasMaxLength(2) |> ignore
|
||||
b.HasKey("churchId") |> ignore
|
||||
b.ToTable("Church") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<ListPreferences>,
|
||||
fun b ->
|
||||
b.Property<Guid>("smallGroupId") |> ignore
|
||||
b.Property<int>("daysToExpire").ValueGeneratedOnAdd().HasDefaultValue(14) |> ignore
|
||||
b.Property<int>("daysToKeepNew").ValueGeneratedOnAdd().HasDefaultValue(7) |> ignore
|
||||
b.Property<string>("defaultEmailType").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("H") |> ignore
|
||||
b.Property<string>("emailFromAddress").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("prayer@djs-consulting.com") |> ignore
|
||||
b.Property<string>("emailFromName").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("PrayerTracker") |> ignore
|
||||
b.Property<string>("groupPassword").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("") |> ignore
|
||||
b.Property<string>("headingColor").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("maroon") |> ignore
|
||||
b.Property<int>("headingFontSize").ValueGeneratedOnAdd().HasDefaultValue(16) |> ignore
|
||||
b.Property<bool>("isPublic").ValueGeneratedOnAdd().HasDefaultValue(false) |> ignore
|
||||
b.Property<string>("lineColor").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("navy") |> ignore
|
||||
b.Property<string>("listFonts").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("Century Gothic,Tahoma,Luxi Sans,sans-serif") |> ignore
|
||||
b.Property<int>("longTermUpdateWeeks").ValueGeneratedOnAdd().HasDefaultValue(4) |> ignore
|
||||
b.Property<string>("requestSort").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("D").HasMaxLength(1) |> ignore
|
||||
b.Property<int>("textFontSize").ValueGeneratedOnAdd().HasDefaultValue(12) |> ignore
|
||||
b.Property<string>("timeZoneId").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("America/Denver") |> ignore
|
||||
b.Property<int>("pageSize").IsRequired().ValueGeneratedOnAdd().HasDefaultValue(100) |> ignore
|
||||
b.Property<string>("asOfDateDisplay").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("N").HasMaxLength(1) |> ignore
|
||||
b.HasKey("smallGroupId") |> ignore
|
||||
b.HasIndex("timeZoneId") |> ignore
|
||||
b.ToTable("ListPreference") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<Member>,
|
||||
fun b ->
|
||||
b.Property<Guid>("memberId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<string>("email").IsRequired() |> ignore
|
||||
b.Property<string>("format") |> ignore
|
||||
b.Property<string>("memberName").IsRequired() |> ignore
|
||||
b.Property<Guid>("smallGroupId") |> ignore
|
||||
b.HasKey("memberId") |> ignore
|
||||
b.HasIndex("smallGroupId") |> ignore
|
||||
b.ToTable("Member") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<PrayerRequest>,
|
||||
fun b ->
|
||||
b.Property<Guid>("prayerRequestId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<DateTime>("enteredDate").IsRequired() |> ignore
|
||||
b.Property<string>("expiration").IsRequired().HasMaxLength 1 |> ignore
|
||||
b.Property<bool>("notifyChaplain") |> ignore
|
||||
b.Property<string>("requestType").IsRequired().HasMaxLength 1 |> ignore
|
||||
b.Property<string>("requestor") |> ignore
|
||||
b.Property<Guid>("smallGroupId") |> ignore
|
||||
b.Property<string>("text").IsRequired() |> ignore
|
||||
b.Property<DateTime>("updatedDate") |> ignore
|
||||
b.Property<Guid>("userId") |> ignore
|
||||
b.HasKey("prayerRequestId") |> ignore
|
||||
b.HasIndex("smallGroupId") |> ignore
|
||||
b.HasIndex("userId") |> ignore
|
||||
b.ToTable("PrayerRequest") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<SmallGroup>,
|
||||
fun b ->
|
||||
b.Property<Guid>("smallGroupId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<Guid>("churchId") |> ignore
|
||||
b.Property<string>("name").IsRequired() |> ignore
|
||||
b.HasKey("smallGroupId") |> ignore
|
||||
b.HasIndex("churchId") |> ignore
|
||||
b.ToTable("SmallGroup") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<PrayerTracker.Entities.TimeZone>,
|
||||
fun b ->
|
||||
b.Property<string>("timeZoneId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<string>("description").IsRequired() |> ignore
|
||||
b.Property<bool>("isActive") |> ignore
|
||||
b.Property<int>("sortOrder") |> ignore
|
||||
b.HasKey("timeZoneId") |> ignore
|
||||
b.ToTable("TimeZone") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<User>,
|
||||
fun b ->
|
||||
b.Property<Guid>("userId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<string>("emailAddress").IsRequired() |> ignore
|
||||
b.Property<string>("firstName").IsRequired() |> ignore
|
||||
b.Property<bool>("isAdmin") |> ignore
|
||||
b.Property<string>("lastName").IsRequired() |> ignore
|
||||
b.Property<string>("passwordHash").IsRequired() |> ignore
|
||||
b.Property<Guid>("salt") |> ignore
|
||||
b.HasKey("userId") |> ignore
|
||||
b.ToTable("User") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<UserSmallGroup>,
|
||||
fun b ->
|
||||
b.Property<Guid>("userId") |> ignore
|
||||
b.Property<Guid>("smallGroupId") |> ignore
|
||||
b.HasKey("userId", "smallGroupId") |> ignore
|
||||
b.HasIndex("smallGroupId") |> ignore
|
||||
b.ToTable("User_SmallGroup") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<ListPreferences>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.SmallGroup")
|
||||
.WithOne("preferences")
|
||||
.HasForeignKey("PrayerTracker.Entities.ListPreferences", "smallGroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore
|
||||
b.HasOne("PrayerTracker.Entities.TimeZone", "timeZone")
|
||||
.WithMany()
|
||||
.HasForeignKey("timeZoneId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<Member>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.SmallGroup", "smallGroup")
|
||||
.WithMany("members")
|
||||
.HasForeignKey("smallGroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<PrayerRequest>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.SmallGroup", "smallGroup")
|
||||
.WithMany("prayerRequests")
|
||||
.HasForeignKey("smallGroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore
|
||||
b.HasOne("PrayerTracker.Entities.User", "user")
|
||||
.WithMany()
|
||||
.HasForeignKey("userId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<SmallGroup>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.Church", "Church")
|
||||
.WithMany("SmallGroups")
|
||||
.HasForeignKey("ChurchId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<UserSmallGroup>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.SmallGroup", "smallGroup")
|
||||
.WithMany("users")
|
||||
.HasForeignKey("smallGroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore
|
||||
b.HasOne("PrayerTracker.Entities.User", "user")
|
||||
.WithMany("smallGroups")
|
||||
.HasForeignKey("userId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
@@ -1,200 +0,0 @@
|
||||
namespace PrayerTracker.Migrations
|
||||
|
||||
open Microsoft.EntityFrameworkCore
|
||||
open Microsoft.EntityFrameworkCore.Infrastructure
|
||||
open Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
|
||||
open PrayerTracker
|
||||
open PrayerTracker.Entities
|
||||
open System
|
||||
|
||||
[<DbContext (typeof<AppDbContext>)>]
|
||||
type AppDbContextModelSnapshot () =
|
||||
inherit ModelSnapshot ()
|
||||
|
||||
override __.BuildModel (modelBuilder : ModelBuilder) =
|
||||
modelBuilder
|
||||
.HasDefaultSchema("pt")
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
|
||||
.HasAnnotation("ProductVersion", "1.1.0-rtm-22752")
|
||||
|> ignore
|
||||
modelBuilder.Entity (
|
||||
typeof<Church>,
|
||||
fun b ->
|
||||
b.Property<Guid>("churchId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<string>("city").IsRequired() |> ignore
|
||||
b.Property<bool>("hasInterface") |> ignore
|
||||
b.Property<string>("interfaceAddress") |> ignore
|
||||
b.Property<string>("name").IsRequired() |> ignore
|
||||
b.Property<string>("st").IsRequired().HasMaxLength(2) |> ignore
|
||||
b.HasKey("churchId") |> ignore
|
||||
b.ToTable("Church") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<ListPreferences>,
|
||||
fun b ->
|
||||
b.Property<Guid>("smallGroupId") |> ignore
|
||||
b.Property<int>("daysToExpire").ValueGeneratedOnAdd().HasDefaultValue(14) |> ignore
|
||||
b.Property<int>("daysToKeepNew").ValueGeneratedOnAdd().HasDefaultValue(7) |> ignore
|
||||
b.Property<string>("defaultEmailType").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("H").HasMaxLength(1) |> ignore
|
||||
b.Property<string>("emailFromAddress").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("prayer@djs-consulting.com") |> ignore
|
||||
b.Property<string>("emailFromName").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("PrayerTracker") |> ignore
|
||||
b.Property<string>("groupPassword").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("") |> ignore
|
||||
b.Property<string>("headingColor").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("maroon") |> ignore
|
||||
b.Property<int>("headingFontSize").ValueGeneratedOnAdd().HasDefaultValue(16) |> ignore
|
||||
b.Property<bool>("isPublic").ValueGeneratedOnAdd().HasDefaultValue(false) |> ignore
|
||||
b.Property<string>("lineColor").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("navy") |> ignore
|
||||
b.Property<string>("listFonts").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("Century Gothic,Tahoma,Luxi Sans,sans-serif") |> ignore
|
||||
b.Property<int>("longTermUpdateWeeks").ValueGeneratedOnAdd().HasDefaultValue(4) |> ignore
|
||||
b.Property<string>("requestSort").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("D").HasMaxLength(1) |> ignore
|
||||
b.Property<int>("textFontSize").ValueGeneratedOnAdd().HasDefaultValue(12) |> ignore
|
||||
b.Property<string>("timeZoneId").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("America/Denver") |> ignore
|
||||
b.Property<int>("pageSize").IsRequired().ValueGeneratedOnAdd().HasDefaultValue(100) |> ignore
|
||||
b.Property<string>("asOfDateDisplay").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("N").HasMaxLength(1) |> ignore
|
||||
b.HasKey("smallGroupId") |> ignore
|
||||
b.HasIndex("timeZoneId") |> ignore
|
||||
b.ToTable("ListPreference") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<Member>,
|
||||
fun b ->
|
||||
b.Property<Guid>("memberId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<string>("email").IsRequired() |> ignore
|
||||
b.Property<string>("format") |> ignore
|
||||
b.Property<string>("memberName").IsRequired() |> ignore
|
||||
b.Property<Guid>("smallGroupId") |> ignore
|
||||
b.HasKey("memberId") |> ignore
|
||||
b.HasIndex("smallGroupId") |> ignore
|
||||
b.ToTable("Member") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<PrayerRequest>,
|
||||
fun b ->
|
||||
b.Property<Guid>("prayerRequestId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<DateTime>("enteredDate") |> ignore
|
||||
b.Property<string>("expiration").IsRequired().HasMaxLength(1) |> ignore
|
||||
b.Property<bool>("notifyChaplain") |> ignore
|
||||
b.Property<string>("requestType").IsRequired().HasMaxLength(1) |> ignore
|
||||
b.Property<string>("requestor") |> ignore
|
||||
b.Property<Guid>("smallGroupId") |> ignore
|
||||
b.Property<string>("text").IsRequired() |> ignore
|
||||
b.Property<DateTime>("updatedDate") |> ignore
|
||||
b.Property<Guid>("userId") |> ignore
|
||||
b.HasKey("prayerRequestId") |> ignore
|
||||
b.HasIndex("smallGroupId") |> ignore
|
||||
b.HasIndex("userId") |> ignore
|
||||
b.ToTable("PrayerRequest") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<SmallGroup>,
|
||||
fun b ->
|
||||
b.Property<Guid>("smallGroupId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<Guid>("churchId") |> ignore
|
||||
b.Property<string>("name").IsRequired() |> ignore
|
||||
b.HasKey("smallGroupId") |> ignore
|
||||
b.HasIndex("churchId") |> ignore
|
||||
b.ToTable("SmallGroup") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<PrayerTracker.Entities.TimeZone>,
|
||||
fun b ->
|
||||
b.Property<string>("timeZoneId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<string>("description").IsRequired() |> ignore
|
||||
b.Property<bool>("isActive") |> ignore
|
||||
b.Property<int>("sortOrder") |> ignore
|
||||
b.HasKey("timeZoneId") |> ignore
|
||||
b.ToTable("TimeZone") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<User>,
|
||||
fun b ->
|
||||
b.Property<Guid>("userId").ValueGeneratedOnAdd() |> ignore
|
||||
b.Property<string>("emailAddress").IsRequired() |> ignore
|
||||
b.Property<string>("firstName").IsRequired() |> ignore
|
||||
b.Property<bool>("isAdmin") |> ignore
|
||||
b.Property<string>("lastName").IsRequired() |> ignore
|
||||
b.Property<string>("passwordHash").IsRequired() |> ignore
|
||||
b.Property<Guid>("salt") |> ignore
|
||||
b.HasKey("userId") |> ignore
|
||||
b.ToTable("User") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<UserSmallGroup>,
|
||||
fun b ->
|
||||
b.Property<Guid>("userId") |> ignore
|
||||
b.Property<Guid>("smallGroupId") |> ignore
|
||||
b.HasKey("userId", "smallGroupId") |> ignore
|
||||
b.HasIndex("smallGroupId") |> ignore
|
||||
b.ToTable("User_SmallGroup") |> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<ListPreferences>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.SmallGroup")
|
||||
.WithOne("preferences")
|
||||
.HasForeignKey("PrayerTracker.Entities.ListPreferences", "smallGroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore
|
||||
b.HasOne("PrayerTracker.Entities.TimeZone", "timeZone")
|
||||
.WithMany()
|
||||
.HasForeignKey("timeZoneId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<Member>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.SmallGroup", "smallGroup")
|
||||
.WithMany("members")
|
||||
.HasForeignKey("smallGroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<PrayerRequest>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.SmallGroup", "smallGroup")
|
||||
.WithMany("prayerRequests")
|
||||
.HasForeignKey("smallGroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore
|
||||
b.HasOne("PrayerTracker.Entities.User", "user")
|
||||
.WithMany()
|
||||
.HasForeignKey("userId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<SmallGroup>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.Church", "Church")
|
||||
.WithMany("SmallGroups")
|
||||
.HasForeignKey("ChurchId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
modelBuilder.Entity (
|
||||
typeof<UserSmallGroup>,
|
||||
fun b ->
|
||||
b.HasOne("PrayerTracker.Entities.SmallGroup", "smallGroup")
|
||||
.WithMany("users")
|
||||
.HasForeignKey("smallGroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore
|
||||
b.HasOne("PrayerTracker.Entities.User", "user")
|
||||
.WithMany("smallGroups")
|
||||
.HasForeignKey("userId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
@@ -6,17 +6,16 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Entities.fs" />
|
||||
<Compile Include="AppDbContext.fs" />
|
||||
<Compile Include="DataAccess.fs" />
|
||||
<Compile Include="Migrations\20161217153124_InitialDatabase.fs" />
|
||||
<Compile Include="Migrations\AppDbContextModelSnapshot.fs" />
|
||||
<Compile Include="Access.fs" />
|
||||
<Compile Include="DistributedCache.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FSharp.EFCore.OptionConverter" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.FSharpLu" Version="0.11.7" />
|
||||
<PackageReference Include="NodaTime" Version="3.0.5" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
|
||||
<PackageReference Include="Giraffe" Version="6.0.0" />
|
||||
<PackageReference Include="NodaTime" Version="3.1.2" />
|
||||
<PackageReference Update="FSharp.Core" Version="6.0.5" />
|
||||
<PackageReference Include="Npgsql.FSharp" Version="5.3.0" />
|
||||
<PackageReference Include="Npgsql.NodaTime" Version="6.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user