Skip to content

Commit 4f1ed7d

Browse files
Cmdvkderme
authored andcommitted
convert jsonb removal to be an opt in feature
1 parent 117d2c3 commit 4f1ed7d

File tree

16 files changed

+82
-103
lines changed

16 files changed

+82
-103
lines changed

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Config.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ insertConfig = do
3131
, sioGovernance = GovernanceConfig False
3232
, sioOffchainPoolData = OffchainPoolDataConfig False
3333
, sioJsonType = JsonTypeDisable
34-
, sioAddJsonbToSchema = AddJsonbToSchemaConfig False
34+
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
3535
}
3636

3737
dncInsertOptions cfg @?= expected

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/Config/Parse.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ insertConfig = do
3131
, sioGovernance = GovernanceConfig False
3232
, sioOffchainPoolData = OffchainPoolDataConfig False
3333
, sioJsonType = JsonTypeDisable
34-
, sioAddJsonbToSchema = AddJsonbToSchemaConfig False
34+
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
3535
}
3636

3737
dncInsertOptions cfg @?= expected

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ unitTests iom knownMigrations =
3737
, testCase "insert config" Config.insertConfig
3838
, testGroup
3939
"jsonb-in-schema"
40-
[ test "jsonb in schema true" Config.configJsonbInSchemaTrue
41-
, test "jsonb in schema false" Config.configJsonbInSchemaFalse
40+
[ test "jsonb in schema true" Config.configRemoveJsonbFromSchemaEnabled
41+
, test "jsonb in schema false" Config.configRemoveJsonbFromSchemaDisabled
4242
, test
43-
"jsonb true then false should remove datatype from db"
44-
Config.configJsonbInSchemaShouldAddThenRemove
43+
"remove jsonb from schema and add back"
44+
Config.configJsonbInSchemaShouldRemoveThenAdd
4545
]
4646
, testGroup
4747
"tx-out"

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/JsonbInSchema.hs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
{-# LANGUAGE OverloadedStrings #-}
33

44
module Test.Cardano.Db.Mock.Unit.Conway.Config.JsonbInSchema (
5-
configJsonbInSchemaTrue,
6-
configJsonbInSchemaFalse,
7-
configJsonbInSchemaShouldAddThenRemove,
5+
configRemoveJsonbFromSchemaEnabled,
6+
configRemoveJsonbFromSchemaDisabled,
7+
configJsonbInSchemaShouldRemoveThenAdd,
88
) where
99

1010
import qualified Cardano.Db as DB
1111
import Cardano.DbSync.Config (SyncNodeConfig (..))
12-
import Cardano.DbSync.Config.Types (AddJsonbToSchemaConfig (..), SyncInsertOptions (..))
12+
import Cardano.DbSync.Config.Types (RemoveJsonbFromSchemaConfig (..), SyncInsertOptions (..))
1313
import Cardano.Mock.ChainSync.Server (IOManager ())
1414
import Cardano.Prelude hiding (head)
1515
import Test.Cardano.Db.Mock.Config
1616
import Test.Cardano.Db.Mock.Validate
1717
import Test.Tasty.HUnit (Assertion ())
1818

19-
configJsonbInSchemaTrue :: IOManager -> [(Text, Text)] -> Assertion
20-
configJsonbInSchemaTrue ioManager metadata = do
19+
configRemoveJsonbFromSchemaEnabled :: IOManager -> [(Text, Text)] -> Assertion
20+
configRemoveJsonbFromSchemaEnabled ioManager metadata = do
2121
syncNodeConfig <- mksNodeConfig
2222
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
2323
where
@@ -27,12 +27,12 @@ configJsonbInSchemaTrue ioManager metadata = do
2727
assertEqQuery
2828
dbSync
2929
DB.queryJsonbInSchemaExists
30-
True
31-
"There should be jsonb data types in database if option is active"
30+
False
31+
"There should be no jsonb data types in database if option is enabled"
3232
checkStillRuns dbSync
3333

3434
args = initCommandLineArgs {claFullMode = False}
35-
testLabel = "conwayConfigJsonbInSchemaTrue"
35+
testLabel = "conwayConfigRemoveJsonbFromSchemaEnabled"
3636

3737
cfgDir = conwayConfigDir
3838

@@ -42,11 +42,11 @@ configJsonbInSchemaTrue ioManager metadata = do
4242
let dncInsertOptions' = dncInsertOptions initConfigFile
4343
pure $
4444
initConfigFile
45-
{ dncInsertOptions = dncInsertOptions' {sioAddJsonbToSchema = AddJsonbToSchemaConfig True}
45+
{ dncInsertOptions = dncInsertOptions' {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig True}
4646
}
4747

48-
configJsonbInSchemaFalse :: IOManager -> [(Text, Text)] -> Assertion
49-
configJsonbInSchemaFalse ioManager metadata = do
48+
configRemoveJsonbFromSchemaDisabled :: IOManager -> [(Text, Text)] -> Assertion
49+
configRemoveJsonbFromSchemaDisabled ioManager metadata = do
5050
syncNodeConfig <- mksNodeConfig
5151
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
5252
where
@@ -56,12 +56,12 @@ configJsonbInSchemaFalse ioManager metadata = do
5656
assertEqQuery
5757
dbSync
5858
DB.queryJsonbInSchemaExists
59-
False
60-
"There should be no jsonb types in database if option isn't active"
59+
True
60+
"There should be jsonb types in database if option is disabled"
6161
checkStillRuns dbSync
6262

6363
args = initCommandLineArgs {claFullMode = False}
64-
testLabel = "conwayConfigJsonbInSchemaFalse"
64+
testLabel = "conwayConfigRemoveJsonbFromSchemaDisabled"
6565

6666
cfgDir = conwayConfigDir
6767

@@ -71,25 +71,30 @@ configJsonbInSchemaFalse ioManager metadata = do
7171
let dncInsertOptions' = dncInsertOptions initConfigFile
7272
pure $
7373
initConfigFile
74-
{ dncInsertOptions = dncInsertOptions' {sioAddJsonbToSchema = AddJsonbToSchemaConfig False}
74+
{ dncInsertOptions = dncInsertOptions' {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False}
7575
}
7676

77-
configJsonbInSchemaShouldAddThenRemove :: IOManager -> [(Text, Text)] -> Assertion
78-
configJsonbInSchemaShouldAddThenRemove ioManager metadata = do
77+
configJsonbInSchemaShouldRemoveThenAdd :: IOManager -> [(Text, Text)] -> Assertion
78+
configJsonbInSchemaShouldRemoveThenAdd ioManager metadata = do
7979
syncNodeConfig <- mksNodeConfig
8080
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
8181
where
8282
action = \_interpreter _mockServer dbSync -> do
8383
startDBSync dbSync
8484
threadDelay 7_000_000
85+
assertEqQuery
86+
dbSync
87+
DB.queryJsonbInSchemaExists
88+
False
89+
"There should be no jsonb types in database if option has been enabled"
8590
stopDBSync dbSync
8691
let newDbSyncEnv =
8792
dbSync
8893
{ dbSyncConfig =
8994
(dbSyncConfig dbSync)
9095
{ dncInsertOptions =
9196
(dncInsertOptions $ dbSyncConfig dbSync)
92-
{ sioAddJsonbToSchema = AddJsonbToSchemaConfig False
97+
{ sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
9398
}
9499
}
95100
}
@@ -98,13 +103,13 @@ configJsonbInSchemaShouldAddThenRemove ioManager metadata = do
98103
assertEqQuery
99104
dbSync
100105
DB.queryJsonbInSchemaExists
101-
False
102-
"There should be no jsonb types in database if option has been set to False"
106+
True
107+
"There should be jsonb types in database if option has been disabled"
103108
-- Expected to fail
104109
checkStillRuns dbSync
105110

106111
args = initCommandLineArgs {claFullMode = False}
107-
testLabel = "configJsonbInSchemaShouldAddThenRemove"
112+
testLabel = "configJsonbInSchemaShouldRemoveThenAdd"
108113

109114
cfgDir = conwayConfigDir
110115

@@ -114,5 +119,5 @@ configJsonbInSchemaShouldAddThenRemove ioManager metadata = do
114119
let dncInsertOptions' = dncInsertOptions initConfigFile
115120
pure $
116121
initConfigFile
117-
{ dncInsertOptions = dncInsertOptions' {sioAddJsonbToSchema = AddJsonbToSchemaConfig True}
122+
{ dncInsertOptions = dncInsertOptions' {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig True}
118123
}

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/Parse.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ insertConfig = do
101101
, sioGovernance = GovernanceConfig False
102102
, sioOffchainPoolData = OffchainPoolDataConfig False
103103
, sioJsonType = JsonTypeDisable
104-
, sioAddJsonbToSchema = AddJsonbToSchemaConfig False
104+
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
105105
}
106106

107107
dncInsertOptions cfg @?= expected

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import Cardano.DbSync.Rollback (unsafeRollback)
4343
import Cardano.DbSync.Sync (runSyncNodeClient)
4444
import Cardano.DbSync.Tracing.ToObjectOrphans ()
4545
import Cardano.DbSync.Types
46-
import Cardano.DbSync.Util.Constraint (dbJsonbInSchema)
46+
import Cardano.DbSync.Util.Constraint (queryIsJsonbInSchema)
4747
import Cardano.Prelude hiding (Nat, (%))
4848
import Cardano.Slotting.Slot (EpochNo (..))
4949
import Control.Concurrent.Async
@@ -174,7 +174,7 @@ runSyncNode metricsSetters trce iomgr dbConnString ranMigrations runMigrationFnc
174174
\backend -> liftIO $ do
175175
runOrThrowIO $ runExceptT $ do
176176
genCfg <- readCardanoGenesisConfig syncNodeConfigFromFile
177-
resJsonbInSchema <- dbJsonbInSchema backend
177+
isJsonbInSchema <- queryIsJsonbInSchema backend
178178
logProtocolMagicId trce $ genesisProtocolMagicId genCfg
179179
syncEnv <-
180180
ExceptT $
@@ -189,15 +189,15 @@ runSyncNode metricsSetters trce iomgr dbConnString ranMigrations runMigrationFnc
189189
ranMigrations
190190
runMigrationFnc
191191

192-
-- if the database has jsonb datatypes and the configuration does not have add_jsonb_to_schema enabled, then warn the user
193-
when (resJsonbInSchema && not isJsonBInSchemaConfig) $ do
192+
-- Warn the user that jsonb datatypes are being removed from the database schema.
193+
when (isJsonbInSchema && removeJsonbFromSchemaConfig) $ do
194194
liftIO $ logWarning trce "Removing jsonb datatypes from the database. This can take time."
195-
liftIO $ runDisableJsonbInSchema syncEnv
195+
liftIO $ runRemoveJsonbFromSchema syncEnv
196196

197-
-- if the database doesn't have jsonb datatypes and the configuration does have add_jsonb_to_schema enabled, then add jsonb datatypes to the database
198-
when (not resJsonbInSchema && isJsonBInSchemaConfig) $ do
199-
liftIO $ logWarning trce "Adding jsonb datatypes to the database. This can take time."
200-
liftIO $ runEnableJsonbInSchema syncEnv
197+
-- Warn the user that jsonb datatypes are being added to the database schema.
198+
when (not isJsonbInSchema && not removeJsonbFromSchemaConfig) $ do
199+
liftIO $ logWarning trce "Adding jsonb datatypes back to the database. This can take time."
200+
liftIO $ runAddJsonbToSchema syncEnv
201201
liftIO $ runExtraMigrationsMaybe syncEnv
202202
unless useLedger $ liftIO $ do
203203
logInfo trce "Migrating to a no ledger schema"
@@ -221,7 +221,7 @@ runSyncNode metricsSetters trce iomgr dbConnString ranMigrations runMigrationFnc
221221
case dncShelleyHardFork cfg of
222222
HardFork.TriggerHardForkAtEpoch (EpochNo 0) -> True
223223
_other -> False
224-
isJsonBInSchemaConfig = ioAddJsonbToSchema $ soptInsertOptions syncOptions
224+
removeJsonbFromSchemaConfig = ioRemoveJsonbFromSchema $ soptInsertOptions syncOptions
225225
maybeLedgerDir = enpMaybeLedgerStateDir syncNodeParams
226226

227227
logProtocolMagicId :: Trace IO Text -> Crypto.ProtocolMagicId -> ExceptT SyncNodeError IO ()
@@ -276,7 +276,7 @@ extractSyncOptions snp aop snc =
276276
, ioPlutusExtra = isPlutusEnabled (sioPlutus (dncInsertOptions snc))
277277
, ioOffChainPoolData = useOffchainPoolData
278278
, ioGov = useGovernance
279-
, ioAddJsonbToSchema = isAddJsonbToSchemaEnabled (sioAddJsonbToSchema (dncInsertOptions snc))
279+
, ioRemoveJsonbFromSchema = isRemoveJsonbFromSchemaEnabled (sioRemoveJsonbFromSchema (dncInsertOptions snc))
280280
}
281281

282282
useLedger = sioLedger (dncInsertOptions snc) == LedgerEnable

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ module Cardano.DbSync.Api (
2626
runIndexMigrations,
2727
initPruneConsumeMigration,
2828
runExtraMigrationsMaybe,
29-
runEnableJsonbInSchema,
30-
runDisableJsonbInSchema,
29+
runAddJsonbToSchema,
30+
runRemoveJsonbFromSchema,
3131
getSafeBlockNoDiff,
3232
getPruneInterval,
3333
whenConsumeOrPruneTxOut,
@@ -177,12 +177,12 @@ runExtraMigrationsMaybe syncEnv = do
177177
(getSafeBlockNoDiff syncEnv)
178178
pcm
179179

180-
runEnableJsonbInSchema :: SyncEnv -> IO ()
181-
runEnableJsonbInSchema syncEnv =
180+
runAddJsonbToSchema :: SyncEnv -> IO ()
181+
runAddJsonbToSchema syncEnv =
182182
void $ DB.runDbIohkNoLogging (envBackend syncEnv) DB.enableJsonbInSchema
183183

184-
runDisableJsonbInSchema :: SyncEnv -> IO ()
185-
runDisableJsonbInSchema syncEnv =
184+
runRemoveJsonbFromSchema :: SyncEnv -> IO ()
185+
runRemoveJsonbFromSchema syncEnv =
186186
void $ DB.runDbIohkNoLogging (envBackend syncEnv) DB.disableJsonbInSchema
187187

188188
getSafeBlockNoDiff :: SyncEnv -> Word64
@@ -233,7 +233,7 @@ fullInsertOptions =
233233
, sioGovernance = GovernanceConfig True
234234
, sioOffchainPoolData = OffchainPoolDataConfig True
235235
, sioJsonType = JsonTypeText
236-
, sioAddJsonbToSchema = AddJsonbToSchemaConfig False
236+
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
237237
}
238238

239239
onlyUTxOInsertOptions :: SyncInsertOptions
@@ -249,7 +249,7 @@ onlyUTxOInsertOptions =
249249
, sioGovernance = GovernanceConfig False
250250
, sioOffchainPoolData = OffchainPoolDataConfig False
251251
, sioJsonType = JsonTypeText
252-
, sioAddJsonbToSchema = AddJsonbToSchemaConfig False
252+
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
253253
}
254254

255255
onlyGovInsertOptions :: SyncInsertOptions
@@ -272,7 +272,7 @@ disableAllInsertOptions =
272272
, sioOffchainPoolData = OffchainPoolDataConfig False
273273
, sioGovernance = GovernanceConfig False
274274
, sioJsonType = JsonTypeText
275-
, sioAddJsonbToSchema = AddJsonbToSchemaConfig False
275+
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
276276
}
277277

278278
initCurrentEpochNo :: CurrentEpochNo

0 commit comments

Comments
 (0)