Skip to content

Commit da2a502

Browse files
committed
add inserts better dbinfo class for uniques
1 parent 57393b9 commit da2a502

34 files changed

+5940
-5220
lines changed

cardano-db-sync/src/Cardano/DbSync.hs

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ runDbSync metricsSetters knownMigrations iomgr trce params syncNodeConfigFromFil
118118

119119
let setting = Db.toConnectionSetting pgConfig
120120

121+
121122
-- For testing and debugging.
122123
whenJust (enpMaybeRollback params) $ \slotNo ->
123124
void $ unsafeRollback trce (txOutConfigToTableType txOutConfig) pgConfig slotNo

cardano-db/cardano-db.cabal

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ library
6666
Cardano.Db.Schema.Orphans
6767
Cardano.Db.Schema.Types
6868
Cardano.Db.Statement
69+
Cardano.Db.Statement.Function.Core
70+
Cardano.Db.Statement.Function.Query
71+
Cardano.Db.Statement.Function.Insert
6972
Cardano.Db.Statement.Base
7073
Cardano.Db.Statement.EpochAndProtocol
7174
Cardano.Db.Statement.GovernanceAndVoting
72-
Cardano.Db.Statement.Helpers
7375
Cardano.Db.Statement.MultiAsset
7476
Cardano.Db.Statement.OffChain
7577
Cardano.Db.Statement.Pool
7678
Cardano.Db.Statement.StakeDeligation
79+
Cardano.Db.Statement.Types
7780
Cardano.Db.Types
7881
Cardano.Db.Version.V13_0.Query
7982
Cardano.Db.Version.V13_0.Schema

cardano-db/src/Cardano/Db/Operations/Insert.hs

+212-212
Large diffs are not rendered by default.

cardano-db/src/Cardano/Db/Operations/Other/ConsumedTxOut.hs

+568-568
Large diffs are not rendered by default.

cardano-db/src/Cardano/Db/Operations/Other/JsonbQuery.hs

+3-63
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55

66
module Cardano.Db.Operations.Other.JsonbQuery where
77

8-
import Cardano.Db.Error (DbError (..), AsDbError (..))
9-
import Cardano.Db.Types (mkCallSite, DbAction)
10-
import Cardano.Prelude (ExceptT, MonadError (..), forM, traverse_, MonadIO, forM_)
118
import Control.Monad.IO.Class (liftIO)
12-
139
import Data.ByteString (ByteString)
1410
import Data.Int (Int64)
1511
import qualified Hasql.Connection as HsqlC
@@ -19,35 +15,9 @@ import qualified Hasql.Session as HsqlS
1915
import qualified Hasql.Statement as HsqlS
2016
import qualified Hasql.Transaction as HsqlT
2117

22-
23-
-- enableJsonbInSchema :: AsDbError e => HsqlC.Connection -> ExceptT e IO ()
24-
-- enableJsonbInSchema conn = do
25-
-- results <- forM stmts (\stmt -> liftIO $ HsqlS.run (HasqlS.statement () (enableJsonbInSchemaStmt stmt)) conn)
26-
-- traverse_ handleResult results
27-
-- where
28-
-- enableJsonbInSchemaStmt :: (ByteString, ByteString) -> HsqlS.Statement () ()
29-
-- enableJsonbInSchemaStmt (t, c) =
30-
-- HsqlS.Statement
31-
-- ("ALTER TABLE " <> t <> " ALTER COLUMN " <> c <> " TYPE jsonb USING " <> c <> "::jsonb")
32-
-- HsqlE.noParams
33-
-- HsqlD.noResult
34-
-- True
35-
36-
-- handleResult res =
37-
-- case res of
38-
-- Left err -> throwError $ toDbError $ QueryError "enableJsonbInSchema" mkCallSite err
39-
-- Right _ -> pure ()
40-
41-
-- stmts :: [(ByteString, ByteString)]
42-
-- stmts = [ ("tx_metadata", "json")
43-
-- , ("script", "json")
44-
-- , ("datum", "value")
45-
-- , ("redeemer_data", "value")
46-
-- , ("cost_model", "costs")
47-
-- , ("gov_action_proposal", "description")
48-
-- , ("off_chain_pool_data", "json")
49-
-- , ("off_chain_vote_data", "json")
50-
-- ]
18+
import Cardano.Db.Error (DbError (..), AsDbError (..))
19+
import Cardano.Db.Statement.Function.Core (mkCallSite)
20+
import Cardano.Prelude (ExceptT, MonadError (..), forM_)
5121

5222
enableJsonbInSchema :: HsqlT.Transaction ()
5323
enableJsonbInSchema = do
@@ -72,7 +42,6 @@ enableJsonbInSchema = do
7242
, ("off_chain_vote_data", "json")
7343
]
7444

75-
7645
disableJsonbInSchema :: HsqlT.Transaction ()
7746
disableJsonbInSchema = do
7847
forM_ stmts $ \(t, c) -> HsqlT.statement () (disableJsonbInSchemaStmt t c)
@@ -94,35 +63,6 @@ disableJsonbInSchema = do
9463
, ("off_chain_vote_data", "json")
9564
]
9665

97-
-- disableJsonbInSchema' :: (MonadIO m, AsDbError e) => HsqlC.Connection -> DbAction e m ()
98-
-- disableJsonbInSchema' conn = do
99-
-- results <- forM stmts (\stmt -> liftIO $ HsqlS.run (statement () (disableJsonbInSchemaStmt stmt)) conn)
100-
-- traverse_ handleResult results
101-
-- where
102-
-- disableJsonbInSchemaStmt :: (ByteString, ByteString) -> HsqlS.Statement () ()
103-
-- disableJsonbInSchemaStmt (t, c) =
104-
-- HsqlS.Statement
105-
-- ("ALTER TABLE " <> t <> " ALTER COLUMN " <> c <> " TYPE VARCHAR")
106-
-- HsqlE.noParams
107-
-- HsqlD.noResult
108-
-- True
109-
110-
-- handleResult res =
111-
-- case res of
112-
-- Left err -> throwError $ toDbError $ QueryError "disableJsonbInSchema" mkCallSite err
113-
-- Right _ -> pure ()
114-
115-
-- stmts :: [(ByteString, ByteString)]
116-
-- stmts = [ ("tx_metadata", "json")
117-
-- , ("script", "json")
118-
-- , ("datum", "value")
119-
-- , ("redeemer_data", "value")
120-
-- , ("cost_model", "costs")
121-
-- , ("gov_action_proposal", "description")
122-
-- , ("off_chain_pool_data", "json")
123-
-- , ("off_chain_vote_data", "json")
124-
-- ]
125-
12666
queryJsonbInSchemaExists :: AsDbError e => HsqlC.Connection -> ExceptT e IO Bool
12767
queryJsonbInSchemaExists conn = do
12868
result <- liftIO $ HsqlS.run (HsqlS.statement () jsonbSchemaStatement) conn

0 commit comments

Comments
 (0)