Remove hard-coded dev values from migration utility

This commit is contained in:
Daniel J. Summers 2019-09-02 13:38:50 -05:00
parent 0ea4249b65
commit 7f34b72cc0
2 changed files with 16 additions and 13 deletions

View File

@ -10,8 +10,8 @@ type NpgsqlDataReader with
member this.getTicks = this.GetOrdinal >> this.GetInt64 >> Ticks member this.getTicks = this.GetOrdinal >> this.GetInt64 >> Ticks
member this.isNull = this.GetOrdinal >> this.IsDBNull member this.isNull = this.GetOrdinal >> this.IsDBNull
let pgConn () = let pgConn connStr =
let c = new NpgsqlConnection "Host=severus-server;Database=mpj;Username=mpj;Password=devpassword;Application Name=myPrayerJournal" let c = new NpgsqlConnection (connStr)
c.Open () c.Open ()
c c
@ -21,8 +21,8 @@ let isValidStatus stat =
true true
with _ -> false with _ -> false
let getHistory reqId = let getHistory reqId connStr =
use conn = pgConn () use conn = pgConn connStr
use cmd = conn.CreateCommand () use cmd = conn.CreateCommand ()
cmd.CommandText <- """SELECT "asOf", status, text FROM mpj.history WHERE "requestId" = @reqId ORDER BY "asOf" """ cmd.CommandText <- """SELECT "asOf", status, text FROM mpj.history WHERE "requestId" = @reqId ORDER BY "asOf" """
(cmd.Parameters.Add >> ignore) (NpgsqlParameter ("@reqId", reqId :> obj)) (cmd.Parameters.Add >> ignore) (NpgsqlParameter ("@reqId", reqId :> obj))
@ -42,8 +42,8 @@ let getHistory reqId =
} }
|> List.ofSeq |> List.ofSeq
let getNotes reqId = let getNotes reqId connStr =
use conn = pgConn () use conn = pgConn connStr
use cmd = conn.CreateCommand () use cmd = conn.CreateCommand ()
cmd.CommandText <- """SELECT "asOf", notes FROM mpj.note WHERE "requestId" = @reqId""" cmd.CommandText <- """SELECT "asOf", notes FROM mpj.note WHERE "requestId" = @reqId"""
(cmd.Parameters.Add >> ignore) (NpgsqlParameter ("@reqId", reqId :> obj)) (cmd.Parameters.Add >> ignore) (NpgsqlParameter ("@reqId", reqId :> obj))
@ -57,9 +57,9 @@ let getNotes reqId =
} }
|> List.ofSeq |> List.ofSeq
let migrateRequests (store : IDocumentStore) = let migrateRequests (store : IDocumentStore) connStr =
use sess = store.OpenSession () use sess = store.OpenSession ()
use conn = pgConn () use conn = pgConn connStr
use cmd = conn.CreateCommand () use cmd = conn.CreateCommand ()
cmd.CommandText <- cmd.CommandText <-
"""SELECT "requestId", "enteredOn", "userId", "snoozedUntil", "showAfter", "recurType", "recurCount" FROM mpj.request""" """SELECT "requestId", "enteredOn", "userId", "snoozedUntil", "showAfter", "recurType", "recurCount" FROM mpj.request"""
@ -75,8 +75,8 @@ let migrateRequests (store : IDocumentStore) =
showAfter = match recurrence with Immediate -> Ticks 0L | _ -> rdr.getTicks "showAfter" showAfter = match recurrence with Immediate -> Ticks 0L | _ -> rdr.getTicks "showAfter"
recurType = recurrence recurType = recurrence
recurCount = rdr.getShort "recurCount" recurCount = rdr.getShort "recurCount"
history = getHistory reqId history = getHistory reqId connStr
notes = getNotes reqId notes = getNotes reqId connStr
}) })
sess.SaveChanges () sess.SaveChanges ()
@ -84,7 +84,7 @@ open Converters
[<EntryPoint>] [<EntryPoint>]
let main argv = let main argv =
let raven = new DocumentStore (Urls = [| "http://localhost:8080" |], Database = "myPrayerJournal") let raven = new DocumentStore (Urls = [| argv.[0] |], Database = "myPrayerJournal")
raven.Conventions.CustomizeJsonSerializer <- raven.Conventions.CustomizeJsonSerializer <-
fun x -> fun x ->
x.Converters.Add (RequestIdJsonConverter ()) x.Converters.Add (RequestIdJsonConverter ())
@ -92,6 +92,6 @@ let main argv =
x.Converters.Add (UserIdJsonConverter ()) x.Converters.Add (UserIdJsonConverter ())
x.Converters.Add (CompactUnionJsonConverter ()) x.Converters.Add (CompactUnionJsonConverter ())
let store = raven.Initialize () let store = raven.Initialize ()
migrateRequests store migrateRequests store argv.[1]
printfn "fin" printfn "fin"
0 // return an integer exit code 0 // return an integer exit code

View File

@ -10,11 +10,14 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.7.0" />
<PackageReference Include="Microsoft.FSharpLu.Json" Version="0.11.2" /> <PackageReference Include="Microsoft.FSharpLu.Json" Version="0.11.2" />
<PackageReference Include="Npgsql" Version="4.0.8" /> <PackageReference Include="Npgsql" Version="4.0.8" />
<PackageReference Include="RavenDb.Client" Version="4.2.2" /> <PackageReference Include="RavenDb.Client" Version="4.2.2" />
<ProjectReference Include="../MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj" /> <ProjectReference Include="../MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.7.0" />
</ItemGroup>
</Project> </Project>