Skip to content

Commit

Permalink
Use major.minor (schema version) to identify snapshot compatibility
Browse files Browse the repository at this point in the history
 just major is not enough anymore since 13.1.
  • Loading branch information
jbgi committed Feb 8, 2023
1 parent 07d3587 commit aa85f24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions cardano-db-tool/src/Cardano/DbTool/PrepareSnapshot.hs
Expand Up @@ -9,7 +9,7 @@ import Cardano.DbSync.LedgerState
import Cardano.Prelude (Word64, fromMaybe)
import Control.Monad
import qualified Data.ByteString.Base16 as Base16
import Data.Version (versionBranch)
import Data.Version (makeVersion, showVersion, versionBranch)
import Ouroboros.Network.Block hiding (blockHash)
import Paths_cardano_db_tool (version)
import System.Info (arch, os)
Expand Down Expand Up @@ -69,20 +69,18 @@ runPrepareSnapshot args = do

printCreateSnapshot :: Word64 -> FilePath -> IO ()
printCreateSnapshot bblockNo fp = do
let mMajor = listToMaybe $ versionBranch version
majorStr = case mMajor of
Nothing -> ""
Just majorV -> "schema-" ++ show majorV
let schemaVersion = makeVersion $ take 2 $ versionBranch version
cmdStr =
"Create a snapshot with:\n"
++ case os of
"freebsd" -> " cardano-db-sync-pgsql-setup"
_otherwise -> " scripts/postgresql-setup.sh"
++ " --create-snapshot db-sync-snapshot-"
++ " --create-snapshot db-sync-snapshot"
putStrLn $
concat
[ cmdStr
, majorStr
, "-schema-"
, showVersion schemaVersion
, "-block-"
, show bblockNo
, "-" ++ arch ++ " "
Expand Down
4 changes: 2 additions & 2 deletions nix/nixos/cardano-db-sync-service.nix
Expand Up @@ -7,7 +7,7 @@ let
configFile = __toFile "db-sync-config.json"
(__toJSON (cfg.explorerConfig // cfg.logConfig));
stateDirBase = "/var/lib/";
majorVersion = lib.versions.major cfg.package.version;
schemaVersion = lib.versions.majorMinor cfg.package.version;
in {
options = {
services.cardano-db-sync = {
Expand Down Expand Up @@ -233,7 +233,7 @@ in {
# Only take snapshot after service exited cleanly.
if [ "$SERVICE_RESULT" = "success" ]; then
EXISTING_SNAPSHOTS=()
for f in db-sync-snapshot-schema-${majorVersion}*.tgz; do
for f in db-sync-snapshot-schema-${schemaVersion}*.tgz; do
if [ -f $f ]; then
echo "A snapshot already exist for this version: $f"
EXISTING_SNAPSHOTS+=( $f )
Expand Down

0 comments on commit aa85f24

Please sign in to comment.