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

3
.gitignore vendored
View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ let isVoiceRemoveAction(update: Update) =
let resolveUpdate (ctx: UpdateContext) =
match ctx.Update with
| x when isVoiceRemoveAction x ->
VoiceRemove { fileId = x.Message.Value.Audio.Value.FileId; chatId = x.Message.Value.Chat.Id }
VoiceRemove { fileId = x.Message.Value.Audio.Value.FileId; chatId = x.Message.Value.Chat.Id }
| _ -> Unknown
let createBotInbox (cfg: BotConfig, db: unit -> DbContext) = MailboxProcessor.Start(fun (inbox) ->

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"
}