File tree Expand file tree Collapse file tree 4 files changed +52
-12
lines changed
cardano-db-sync/src/Cardano Expand file tree Collapse file tree 4 files changed +52
-12
lines changed Original file line number Diff line number Diff line change @@ -175,17 +175,6 @@ runSyncNode metricsSetters trce iomgr dbConnString ranMigrations runMigrationFnc
175
175
runOrThrowIO $ runExceptT $ do
176
176
genCfg <- readCardanoGenesisConfig syncNodeConfigFromFile
177
177
resJsonbInSchema <- dbJsonbInSchema backend
178
-
179
- -- if the database has jsonb datatypes and the configuration does not have add_jsonb_to_schema enabled, then warn the user
180
- when (resJsonbInSchema && not isJsonBInSchemaConfig) $
181
- liftIO $
182
- logAndThrowIO trce $
183
- SNErrJsonbInSchema
184
- ( " The database has jsonb datatypes active. "
185
- <> " Once jsonb datatypes have been enabled via `add_jsonb_to_schema` "
186
- <> " configuration you need to make sure that configuration is not removed and always present."
187
- )
188
-
189
178
logProtocolMagicId trce $ genesisProtocolMagicId genCfg
190
179
syncEnv <-
191
180
ExceptT $
@@ -199,6 +188,12 @@ runSyncNode metricsSetters trce iomgr dbConnString ranMigrations runMigrationFnc
199
188
syncNodeParams
200
189
ranMigrations
201
190
runMigrationFnc
191
+
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
194
+ liftIO $ logWarning trce " The database has jsonb datatypes, but the configuration does not have add_jsonb_to_schema enabled. The all jsonb datatypes will be put back which can take time."
195
+ liftIO $ runDisableJsonbInSchema syncEnv
196
+
202
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
203
198
when (not resJsonbInSchema && isJsonBInSchemaConfig) $ liftIO $ runEnableJsonbInSchema syncEnv
204
199
liftIO $ runExtraMigrationsMaybe syncEnv
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ module Cardano.DbSync.Api (
27
27
initPruneConsumeMigration ,
28
28
runExtraMigrationsMaybe ,
29
29
runEnableJsonbInSchema ,
30
+ runDisableJsonbInSchema ,
30
31
getSafeBlockNoDiff ,
31
32
getPruneInterval ,
32
33
whenConsumeOrPruneTxOut ,
@@ -180,6 +181,10 @@ runEnableJsonbInSchema :: SyncEnv -> IO ()
180
181
runEnableJsonbInSchema syncEnv =
181
182
void $ DB. runDbIohkNoLogging (envBackend syncEnv) DB. enableJsonbInSchema
182
183
184
+ runDisableJsonbInSchema :: SyncEnv -> IO ()
185
+ runDisableJsonbInSchema syncEnv =
186
+ void $ DB. runDbIohkNoLogging (envBackend syncEnv) DB. disableJsonbInSchema
187
+
183
188
getSafeBlockNoDiff :: SyncEnv -> Word64
184
189
getSafeBlockNoDiff syncEnv = 2 * getSecurityParam syncEnv
185
190
Original file line number Diff line number Diff line change @@ -54,6 +54,46 @@ enableJsonbInSchema = do
54
54
" ALTER TABLE off_chain_vote_data ALTER COLUMN json TYPE jsonb USING json::jsonb"
55
55
[]
56
56
57
+ disableJsonbInSchema ::
58
+ forall m .
59
+ ( MonadBaseControl IO m
60
+ , MonadIO m
61
+ ) =>
62
+ ReaderT SqlBackend m ()
63
+ disableJsonbInSchema = do
64
+ handle exceptHandler $
65
+ rawExecute
66
+ " ALTER TABLE 'tx_metadata' ALTER COLUMN 'json' TYPE VARCHAR"
67
+ []
68
+ handle exceptHandler $
69
+ rawExecute
70
+ " ALTER TABLE 'script' ALTER COLUMN 'json' TYPE VARCHAR"
71
+ []
72
+ handle exceptHandler $
73
+ rawExecute
74
+ " ALTER TABLE 'datum' ALTER COLUMN 'value' TYPE VARCHAR"
75
+ []
76
+ handle exceptHandler $
77
+ rawExecute
78
+ " ALTER TABLE 'redeemer_data' ALTER COLUMN 'value' TYPE VARCHAR"
79
+ []
80
+ handle exceptHandler $
81
+ rawExecute
82
+ " ALTER TABLE 'cost_model' ALTER COLUMN 'costs' TYPE VARCHAR"
83
+ []
84
+ handle exceptHandler $
85
+ rawExecute
86
+ " ALTER TABLE 'gov_action_proposal' ALTER COLUMN 'description' TYPE VARCHAR"
87
+ []
88
+ handle exceptHandler $
89
+ rawExecute
90
+ " ALTER TABLE 'off_chain_pool_data' ALTER COLUMN 'json' TYPE VARCHAR"
91
+ []
92
+ handle exceptHandler $
93
+ rawExecute
94
+ " ALTER TABLE 'off_chain_vote_data' ALTER COLUMN 'json' TYPE VARCHAR"
95
+ []
96
+
57
97
queryJsonbInSchemaExists ::
58
98
(MonadIO m ) =>
59
99
ReaderT SqlBackend m Bool
Original file line number Diff line number Diff line change 5
5
next_version int ;
6
6
BEGIN
7
7
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8
- IF next_version = 40 THEN
8
+ IF next_version = 41 THEN
9
9
EXECUTE ' ALTER TABLE "tx_metadata" ALTER COLUMN "json" TYPE VARCHAR' ;
10
10
EXECUTE ' ALTER TABLE "script" ALTER COLUMN "json" TYPE VARCHAR' ;
11
11
EXECUTE ' ALTER TABLE "datum" ALTER COLUMN "value" TYPE VARCHAR' ;
You can’t perform that action at this time.
0 commit comments