Fix migrations

This commit is contained in:
Kirill Poletaev 2023-04-06 23:13:22 +03:00
parent f61fea6244
commit b4658c4559
6 changed files with 11 additions and 7 deletions

1
.gitignore vendored
View File

@ -562,3 +562,4 @@ dist
.ionide .ionide
# End of https://www.toptal.com/developers/gitignore/api/csharp,fsharp,node,visualstudiocode # End of https://www.toptal.com/developers/gitignore/api/csharp,fsharp,node,visualstudiocode
Keroosha.SilencerBot/token

View File

@ -44,6 +44,7 @@ let migrateApp (connectionString: string) =
use serviceProvider = use serviceProvider =
ServiceCollection() ServiceCollection()
.AddFluentMigratorCore() .AddFluentMigratorCore()
.AddLogging(fun x -> x.AddFluentMigratorConsole() |> ignore)
.ConfigureRunner(fun x -> .ConfigureRunner(fun x ->
x.AddPostgres() x.AddPostgres()
.WithMigrationsIn(typeof<DbContext>.Assembly) .WithMigrationsIn(typeof<DbContext>.Assembly)
@ -51,12 +52,12 @@ let migrateApp (connectionString: string) =
) )
.BuildServiceProvider(false) .BuildServiceProvider(false)
use scope = serviceProvider.CreateScope() use scope = serviceProvider.CreateScope()
serviceProvider.GetRequiredService<IMigrationRunner>().MigrateUp() scope.ServiceProvider.GetRequiredService<IMigrationRunner>().MigrateUp()
let createContext (connectionString: string) = let createContext (connectionString: string) =
new DbContext(connectionString, PostgreSQLTools.GetDataProvider()) new DbContext(connectionString, PostgreSQLTools.GetDataProvider())
[<TimestampedMigration(2023us, 4us, 6us, 20us, 8us)>] [<Migration(1L, "")>]
type InitialMigration() = type InitialMigration() =
inherit AutoReversingMigration() inherit AutoReversingMigration()
override this.Up() = override this.Up() =

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>

View File

@ -11,13 +11,14 @@ let config = Env.createConfig "SILENCER_BOT_CONFIG_PATH"
let botConfig = Config.defaultConfig |> Config.withReadTokenFromFile let botConfig = Config.defaultConfig |> Config.withReadTokenFromFile
let ctxFactory = fun () -> Database.createContext <| config.connectionString let ctxFactory = fun () -> Database.createContext <| config.connectionString
Console.CancelKeyPress |> Event.add (fun _ -> Environment.Exit <| 0)
Database.migrateApp config.connectionString Database.migrateApp config.connectionString
let botInbox = createBotInbox <| (botConfig, ctxFactory) let botInbox = createBotInbox <| (botConfig, ctxFactory)
let handleUpdate (ctx: UpdateContext) = resolveUpdate ctx |> botInbox.Post let handleUpdate (ctx: UpdateContext) = resolveUpdate ctx |> botInbox.Post
Console.CancelKeyPress |> Event.add (fun _ -> Environment.Exit <| 0)
async { async {
let! _ = Api.makeRequestAsync botConfig <| Api.deleteWebhookBase() let! _ = Api.makeRequestAsync botConfig <| Api.deleteWebhookBase()
return! startBot botConfig handleUpdate None return! startBot botConfig handleUpdate None

View File

@ -1,3 +1,4 @@
{ {
"ConnectionString": "Server=127.0.0.1;User id=postgres;password=postgres;database=silencer-bot" "connectionString": "Server=127.0.0.1;User id=postgres;password=postgres;database=silencer-bot",
"tempSavePath": "/tmp"
} }