简体   繁体   English

我该如何使用F#FAKE的DropDb,然后使用failwith?

[英]How do I use F# FAKE's DropDb followed by a failwith?

When an error is thrown in one of my Target functions, I would like my application to first DropDb, then fail. 当我的Target函数之一引发错误时,我希望我的应用程序先运行DropDb,然后失败。 But when I have the following code: 但是当我有以下代码时:

DropDb *databaseInfo* |> ignore
failwith "Migration failed"

The application fails before DropDb drops the database. 在DropDb删除数据库之前,应用程序将失败。

How can I make the application only fail once DropDb is complete? 如何使应用程序仅在DropDb完成后失败?

I seem to have found the issue: 我似乎发现了问题:

In my script, I have already ran DropDb before, then created a DB again. 在我的脚本中,我之前已经运行过DropDb,然后再次创建了一个数据库。 The code for DropDb in FAKE is: FAKE中DropDb的代码是:

let DropDb serverInfo = 
    if intitialCatalogExistsOnServer serverInfo then
         logfn "Dropping database %s on server %s" (getDBName serverInfo) (getServerName serverInfo)
        (getDatabase serverInfo).DropBackupHistory |> ignore
        getDBName serverInfo |> serverInfo.Server.KillDatabase
    serverInfo

serverInfo has been stored in a cache that was not updated by the script creating the databases again in my previous and therefore, initialCatalogExistsOnServer returns false and none of the code runs. serverInfo已存储在一个缓存中,该缓存在我之前的脚本中并未通过再次创建数据库的脚本进行更新,因此, initialCatalogExistsOnServer返回false,并且没有代码运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM