Skip to content

Commit

Permalink
Place TH gitRev into cardano-db-sync project.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgilchrist committed Oct 14, 2021
1 parent cb11874 commit f05b6a5
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 195 deletions.
94 changes: 1 addition & 93 deletions cardano-db-sync-extended/app/cardano-db-sync-extended.hs
Expand Up @@ -3,23 +3,18 @@

import Cardano.Prelude

import Cardano.Config.Git.Rev (gitRev)

import Cardano.DbSync (runDbSyncNode)
import Cardano.DbSync.Cli
import Cardano.DbSync.Metrics (withMetricSetters)
import Cardano.DbSync.Plugin.Extended (extendedDbSyncNodePlugin)

import Cardano.Slotting.Slot (SlotNo (..))
import Cardano.Sync.Config
import Cardano.Sync.Config.Types

import Data.String (String)
import qualified Data.Text as Text
import Data.Version (showVersion)

import MigrationValidations (KnownMigration (..), knownMigrations)

import Options.Applicative (Parser, ParserInfo)
import qualified Options.Applicative as Opt

import Paths_cardano_db_sync_extended (version)
Expand All @@ -43,93 +38,6 @@ main = do

-- -------------------------------------------------------------------------------------------------

opts :: ParserInfo SyncCommand
opts =
Opt.info (pCommandLine <**> Opt.helper)
( Opt.fullDesc
<> Opt.progDesc "Extended Cardano POstgreSQL sync node."
)

pCommandLine :: Parser SyncCommand
pCommandLine =
asum
[ pVersionCommand
, CmdRun <$> pRunDbSyncNode
]

pRunDbSyncNode :: Parser SyncNodeParams
pRunDbSyncNode =
SyncNodeParams
<$> pConfigFile
<*> pSocketPath
<*> pLedgerStateDir
<*> pMigrationDir
<*> optional pSlotNo

pConfigFile :: Parser ConfigFile
pConfigFile =
ConfigFile <$> Opt.strOption
( Opt.long "config"
<> Opt.help "Path to the db-sync node config file"
<> Opt.completer (Opt.bashCompleter "file")
<> Opt.metavar "FILEPATH"
)

pLedgerStateDir :: Parser LedgerStateDir
pLedgerStateDir =
LedgerStateDir <$> Opt.strOption
( Opt.long "state-dir"
<> Opt.help "The directory for persistung ledger state."
<> Opt.completer (Opt.bashCompleter "directory")
<> Opt.metavar "FILEPATH"
)

pMigrationDir :: Parser MigrationDir
pMigrationDir =
MigrationDir <$> Opt.strOption
( Opt.long "schema-dir"
<> Opt.help "The directory containing the migrations."
<> Opt.completer (Opt.bashCompleter "directory")
<> Opt.metavar "FILEPATH"
)

pSocketPath :: Parser SocketPath
pSocketPath =
SocketPath <$> Opt.strOption
( Opt.long "socket-path"
<> Opt.help "Path to a cardano-node socket"
<> Opt.completer (Opt.bashCompleter "file")
<> Opt.metavar "FILEPATH"
)

pSlotNo :: Parser SlotNo
pSlotNo =
SlotNo <$> Opt.option Opt.auto
( Opt.long "rollback-to-slot"
<> Opt.help "Force a rollback to the specified slot (mainly for testing and debugging)."
<> Opt.metavar "WORD"
)

pVersionCommand :: Parser SyncCommand
pVersionCommand =
asum
[ Opt.subparser
( mconcat
[ command' "version" "Show the program version" (pure CmdVersion) ]
)
, Opt.flag' CmdVersion
( Opt.long "version"
<> Opt.help "Show the program version"
<> Opt.hidden
)
]

command' :: String -> String -> Parser a -> Opt.Mod Opt.CommandFields a
command' c descr p =
Opt.command c
$ Opt.info (p <**> Opt.helper)
$ mconcat [ Opt.progDesc descr ]

runVersionCommand :: IO ()
runVersionCommand = do
liftIO . putTextLn $ mconcat
Expand Down
2 changes: 0 additions & 2 deletions cardano-db-sync-extended/cardano-db-sync-extended.cabal
Expand Up @@ -73,11 +73,9 @@ executable cardano-db-sync-extended
MigrationValidations

build-depends: base >= 4.14 && < 4.16
, cardano-config
, cardano-db-sync
, cardano-db-sync-extended
, cardano-sync
, cardano-prelude
, cardano-slotting
, optparse-applicative
, text
101 changes: 3 additions & 98 deletions cardano-db-sync/app/cardano-db-sync.hs
Expand Up @@ -3,29 +3,21 @@

import Cardano.Prelude

import Cardano.Config.Git.Rev (gitRev)

import Cardano.DbSync (defDbSyncNodePlugin, runDbSyncNode)
import Cardano.DbSync.Cli
import Cardano.DbSync.Metrics (withMetricSetters)

import Cardano.Sync.Config
import Cardano.Sync.Config (readSyncNodeConfig)
import Cardano.Sync.Config.Types

import Cardano.Slotting.Slot (SlotNo (..))

import Data.String (String)
import qualified Data.Text as Text
import Data.Version (showVersion)

import Options.Applicative (Parser, ParserInfo)
import qualified Options.Applicative as Opt

import MigrationValidations (KnownMigration (..), knownMigrations)
import qualified Options.Applicative as Opt
import Paths_cardano_db_sync (version)

import System.Info (arch, compilerName, compilerVersion, os)


main :: IO ()
main = do
cmd <- Opt.execParser opts
Expand All @@ -42,93 +34,6 @@ main = do

-- -------------------------------------------------------------------------------------------------

opts :: ParserInfo SyncCommand
opts =
Opt.info (pCommandLine <**> Opt.helper)
( Opt.fullDesc
<> Opt.progDesc "Cardano PostgreSQL sync node."
)

pCommandLine :: Parser SyncCommand
pCommandLine =
asum
[ pVersionCommand
, CmdRun <$> pRunDbSyncNode
]

pRunDbSyncNode :: Parser SyncNodeParams
pRunDbSyncNode =
SyncNodeParams
<$> pConfigFile
<*> pSocketPath
<*> pLedgerStateDir
<*> pMigrationDir
<*> optional pSlotNo

pConfigFile :: Parser ConfigFile
pConfigFile =
ConfigFile <$> Opt.strOption
( Opt.long "config"
<> Opt.help "Path to the db-sync node config file"
<> Opt.completer (Opt.bashCompleter "file")
<> Opt.metavar "FILEPATH"
)

pLedgerStateDir :: Parser LedgerStateDir
pLedgerStateDir =
LedgerStateDir <$> Opt.strOption
( Opt.long "state-dir"
<> Opt.help "The directory for persistung ledger state."
<> Opt.completer (Opt.bashCompleter "directory")
<> Opt.metavar "FILEPATH"
)

pMigrationDir :: Parser MigrationDir
pMigrationDir =
MigrationDir <$> Opt.strOption
( Opt.long "schema-dir"
<> Opt.help "The directory containing the migrations."
<> Opt.completer (Opt.bashCompleter "directory")
<> Opt.metavar "FILEPATH"
)

pSocketPath :: Parser SocketPath
pSocketPath =
SocketPath <$> Opt.strOption
( Opt.long "socket-path"
<> Opt.help "Path to a cardano-node socket"
<> Opt.completer (Opt.bashCompleter "file")
<> Opt.metavar "FILEPATH"
)

pSlotNo :: Parser SlotNo
pSlotNo =
SlotNo <$> Opt.option Opt.auto
( Opt.long "rollback-to-slot"
<> Opt.help "Force a rollback to the specified slot (mainly for testing and debugging)."
<> Opt.metavar "WORD"
)

pVersionCommand :: Parser SyncCommand
pVersionCommand =
asum
[ Opt.subparser
( mconcat
[ command' "version" "Show the program version" (pure CmdVersion) ]
)
, Opt.flag' CmdVersion
( Opt.long "version"
<> Opt.help "Show the program version"
<> Opt.hidden
)
]

command' :: String -> String -> Parser a -> Opt.Mod Opt.CommandFields a
command' c descr p =
Opt.command c
$ Opt.info (p <**> Opt.helper)
$ mconcat [ Opt.progDesc descr ]

runVersionCommand :: IO ()
runVersionCommand = do
liftIO . putTextLn $ mconcat
Expand Down
9 changes: 7 additions & 2 deletions cardano-db-sync/cardano-db-sync.cabal
Expand Up @@ -44,6 +44,9 @@ library

exposed-modules: Cardano.DbSync

Cardano.DbSync.Cli
Cardano.DbSync.TH

Cardano.DbSync.Era

Cardano.DbSync.Era.Byron.Genesis
Expand Down Expand Up @@ -110,6 +113,7 @@ library
, containers
, esqueleto
, extra
, file-embed
, groups
, http-client
, http-client-tls
Expand All @@ -123,15 +127,18 @@ library
, ouroboros-consensus-cardano
, ouroboros-consensus-shelley
, ouroboros-network
, optparse-applicative
, persistent
, persistent-postgresql
, process
, prometheus
, random-shuffle
, small-steps
, split
, strict-containers
, swagger2
, text
, template-haskell
, time
, transformers
, transformers-except
Expand Down Expand Up @@ -162,10 +169,8 @@ executable cardano-db-sync
MigrationValidations

build-depends: base >= 4.14 && < 4.16
, cardano-config
, cardano-sync
, cardano-db-sync
, cardano-prelude
, cardano-slotting
, optparse-applicative
, text

0 comments on commit f05b6a5

Please sign in to comment.