From b07532ab508f0c550713129a1c07100b8bd84954 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Thu, 6 Jun 2024 23:07:57 -0400 Subject: [PATCH] Update Dockerfile to .NET 8 (#75) - Update deps - Implement newer doc library --- src/Dockerfile | 8 ++-- src/MyPrayerJournal/Data.fs | 45 ++++++++++------------ src/MyPrayerJournal/MyPrayerJournal.fsproj | 17 ++++---- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/Dockerfile b/src/Dockerfile index 1a5a49a..0dc5c2b 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -1,17 +1,17 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build WORKDIR /mpj COPY ./MyPrayerJournal/MyPrayerJournal.fsproj ./ RUN dotnet restore COPY ./MyPrayerJournal ./ RUN dotnet publish -c Release -r linux-x64 -RUN rm bin/Release/net7.0/linux-x64/publish/appsettings.*.json +RUN rm bin/Release/net8.0/linux-x64/publish/appsettings.*.json -FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine as final +FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine as final WORKDIR /app RUN apk add --no-cache icu-libs ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false -COPY --from=build /mpj/bin/Release/net7.0/linux-x64/publish/ ./ +COPY --from=build /mpj/bin/Release/net8.0/linux-x64/publish/ ./ EXPOSE 80 CMD [ "dotnet", "/app/MyPrayerJournal.dll" ] \ No newline at end of file diff --git a/src/MyPrayerJournal/Data.fs b/src/MyPrayerJournal/Data.fs index 92ccd87..0c072cf 100644 --- a/src/MyPrayerJournal/Data.fs +++ b/src/MyPrayerJournal/Data.fs @@ -28,12 +28,11 @@ module Json = /// JSON serializer options to support the target domain let options = let opts = JsonSerializerOptions() - [ WrappedJsonConverter(Recurrence.ofString, Recurrence.toString) :> JsonConverter - WrappedJsonConverter(RequestAction.ofString, RequestAction.toString) - WrappedJsonConverter(RequestId.ofString, RequestId.toString) - WrappedJsonConverter(UserId, UserId.toString) - JsonFSharpConverter() - ] + [ WrappedJsonConverter(Recurrence.ofString, Recurrence.toString) :> JsonConverter + WrappedJsonConverter(RequestAction.ofString, RequestAction.toString) + WrappedJsonConverter(RequestId.ofString, RequestId.toString) + WrappedJsonConverter(UserId, UserId.toString) + JsonFSharpConverter() ] |> List.iter opts.Converters.Add let _ = opts.ConfigureForNodaTime NodaTime.DateTimeZoneProviders.Tzdb opts.PropertyNamingPolicy <- JsonNamingPolicy.CamelCase @@ -41,13 +40,13 @@ module Json = opts -open BitBadger.Npgsql.FSharp.Documents +open BitBadger.Documents.Postgres /// Connection [] module Connection = - open BitBadger.Npgsql.Documents + open BitBadger.Documents open Microsoft.Extensions.Configuration open Npgsql open System.Text.Json @@ -55,8 +54,8 @@ module Connection = /// Ensure the database is ready to use let private ensureDb () = backgroundTask { do! Custom.nonQuery "CREATE SCHEMA IF NOT EXISTS mpj" [] - do! Definition.ensureTable Table.Request - do! Definition.ensureIndex Table.Request Optimized + do! Definition.ensureTable Table.Request + do! Definition.ensureDocumentIndex Table.Request Optimized } /// Set up the data environment @@ -89,7 +88,7 @@ module Request = /// Retrieve a request by its ID and user ID let tryById reqId userId = backgroundTask { - match! Find.byId Table.Request (RequestId.toString reqId) with + match! Find.byId Table.Request (RequestId.toString reqId) with | Some req when req.UserId = userId -> return Some req | _ -> return None } @@ -98,7 +97,7 @@ module Request = let updateRecurrence reqId userId (recurType : Recurrence) = backgroundTask { let dbId = RequestId.toString reqId match! existsById reqId userId with - | true -> do! Update.partialById Table.Request dbId {| Recurrence = recurType |} + | true -> do! Patch.byId Table.Request dbId {| Recurrence = recurType |} | false -> invalidOp $"Request ID {dbId} not found" } @@ -106,7 +105,7 @@ module Request = let updateShowAfter reqId userId (showAfter : Instant option) = backgroundTask { let dbId = RequestId.toString reqId match! existsById reqId userId with - | true -> do! Update.partialById Table.Request dbId {| ShowAfter = showAfter |} + | true -> do! Patch.byId Table.Request dbId {| ShowAfter = showAfter |} | false -> invalidOp $"Request ID {dbId} not found" } @@ -114,7 +113,7 @@ module Request = let updateSnoozed reqId userId (until : Instant option) = backgroundTask { let dbId = RequestId.toString reqId match! existsById reqId userId with - | true -> do! Update.partialById Table.Request dbId {| SnoozedUntil = until; ShowAfter = until |} + | true -> do! Patch.byId Table.Request dbId {| SnoozedUntil = until; ShowAfter = until |} | false -> invalidOp $"Request ID {dbId} not found" } @@ -128,8 +127,7 @@ module History = let dbId = RequestId.toString reqId match! Request.tryById reqId userId with | Some req -> - do! Update.partialById Table.Request dbId - {| History = (hist :: req.History) |> List.sortByDescending (_.AsOf) |} + do! Patch.byId Table.Request dbId {| History = (hist :: req.History) |> List.sortByDescending (_.AsOf) |} | None -> invalidOp $"Request ID {dbId} not found" } @@ -143,9 +141,9 @@ module Journal = let! reqs = Custom.list $"""{Query.Find.byContains Table.Request} AND {Query.whereJsonPathMatches "@stat"}""" - [ "@criteria", Query.jsonbDocParam {| UserId = userId |} - "@stat", Sql.string """$.history[0].status ? (@ == "Answered")""" - ] fromData + [ jsonParam "@criteria" {| UserId = userId |} + "@stat", Sql.string """$.history[0].status ? (@ == "Answered")""" ] + fromData return reqs |> Seq.ofList @@ -160,9 +158,9 @@ module Journal = let! reqs = Custom.list $"""{Query.Find.byContains Table.Request} AND {Query.whereJsonPathMatches "@stat"}""" - [ "@criteria", Query.jsonbDocParam {| UserId = userId |} - "@stat", Sql.string """$.history[0].status ? (@ <> "Answered")""" - ] fromData + [ jsonParam "@criteria" {| UserId = userId |} + "@stat", Sql.string """$.history[0].status ? (@ <> "Answered")""" ] + fromData return reqs |> Seq.ofList @@ -193,8 +191,7 @@ module Note = let dbId = RequestId.toString reqId match! Request.tryById reqId userId with | Some req -> - do! Update.partialById Table.Request dbId - {| Notes = (note :: req.Notes) |> List.sortByDescending (_.AsOf) |} + do! Patch.byId Table.Request dbId {| Notes = (note :: req.Notes) |> List.sortByDescending (_.AsOf) |} | None -> invalidOp $"Request ID {dbId} not found" } diff --git a/src/MyPrayerJournal/MyPrayerJournal.fsproj b/src/MyPrayerJournal/MyPrayerJournal.fsproj index 6f2dbd1..d8d415c 100644 --- a/src/MyPrayerJournal/MyPrayerJournal.fsproj +++ b/src/MyPrayerJournal/MyPrayerJournal.fsproj @@ -20,15 +20,16 @@ - - + + - - - - - - + + + + + + +