简体   繁体   中英

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. But when I have the following code:

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

The application fails before DropDb drops the database.

How can I make the application only fail once DropDb is complete?

I seem to have found the issue:

In my script, I have already ran DropDb before, then created a DB again. The code for DropDb in FAKE is:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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