Skip to content

Commit

Permalink
Add a CLI option to ignore detected schema diffs (#111)
Browse files Browse the repository at this point in the history
This PR adds an `--ignore-schema-diff` CLI option to the `chainweb-data` binary that makes it keep going even if it encounters a different schema in the database.

This option is useful for `chainweb-data` operators that would like to make ad-hoc additions to their CW-D database. Though it should probably be mentioned that making such ad-hoc changes, especially directly on the tables populated and queried by `chainweb-data` isn't officially supported since an arbitrarily different schema might cause CW-D to break in unpredictable ways.

* Add a CLI option to ignore detected schema diffs

* fix: invert values for `DontMigrate`. Define long flag without dashes (#113)

Co-authored-by: Albert G <[email protected]>
  • Loading branch information
enobayram and alber70g authored Dec 23, 2022
1 parent b325213 commit 72745ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions lib/ChainwebData/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Text.Printf

---

data MigrateStatus = RunMigration | DontMigrate
data MigrateStatus = RunMigration | DontMigrate Bool
deriving (Eq,Ord,Show,Read)

data Args
Expand Down Expand Up @@ -215,8 +215,13 @@ envP = Args
<*> migrationP

migrationP :: Parser MigrateStatus
migrationP =
flag DontMigrate RunMigration (short 'm' <> long "migrate" <> help "Run DB migration")
migrationP
= flag' RunMigration (short 'm' <> long "migrate" <> help "Run DB migration")
<|> flag' (DontMigrate True)
( long "ignore-schema-diff"
<> help "Ignore any unexpected differences in the database schema"
)
<|> pure (DontMigrate False)

logLevelParser :: Parser LogLevel
logLevelParser =
Expand Down
9 changes: 6 additions & 3 deletions lib/ChainwebDb/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import ChainwebDb.Types.MinerKey
import ChainwebDb.Types.Signer
import ChainwebDb.Types.Transaction
import ChainwebDb.Types.Transfer
import Control.Monad (unless)
import Data.Functor ((<&>))
import qualified Data.Pool as P
import Data.Text (Text)
Expand Down Expand Up @@ -175,10 +176,12 @@ initializeTables logg migrateStatus conn = do
RunMigration -> do
BA.tryRunMigrationsWithEditUpdate annotatedDb conn
logg Info "Done with database migration."
DontMigrate -> do
logg Info "Database needs to be migrated. Re-run with the -m option or you can migrate by hand with the following query:"
DontMigrate ignoreDiffs -> do
logg Info "Database needs to be migrated."
showMigration conn
exitFailure
unless ignoreDiffs $ do
logg Error "Re-run with the -m option or you can run the queries above manually"
exitFailure



Expand Down

0 comments on commit 72745ba

Please sign in to comment.