forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: Apply migrations when catalog version < 43
Co-authored-by: Rakesh Emmadi <12475069+rakeshkky@users.noreply.github.com> GitOrigin-RevId: 4fa1a04
- Loading branch information
1 parent
8ab4213
commit 4fa34e1
Showing
4 changed files
with
88 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Hasura.Server.Migrate.Internal | ||
( runTx | ||
, getCatalogVersion | ||
, from3To4 | ||
) | ||
where | ||
import Hasura.Backends.Postgres.Connection | ||
import Hasura.Prelude | ||
import Hasura.RQL.Types.EventTrigger | ||
|
||
import qualified Data.Aeson as A | ||
import qualified Database.PG.Query as Q | ||
|
||
runTx :: (MonadTx m) => Q.Query -> m () | ||
runTx = liftTx . Q.multiQE defaultTxErrorHandler | ||
|
||
-- | The old 0.8 catalog version is non-integral, so we store it in the database as a | ||
-- string. | ||
getCatalogVersion :: MonadTx m => m Text | ||
getCatalogVersion = liftTx $ runIdentity . Q.getRow <$> Q.withQE defaultTxErrorHandler | ||
[Q.sql| SELECT version FROM hdb_catalog.hdb_version |] () False | ||
|
||
from3To4 :: MonadTx m => m () | ||
from3To4 = liftTx $ Q.catchE defaultTxErrorHandler $ do | ||
Q.unitQ [Q.sql| | ||
ALTER TABLE hdb_catalog.event_triggers | ||
ADD COLUMN configuration JSON |] () False | ||
eventTriggers <- map uncurryEventTrigger <$> Q.listQ [Q.sql| | ||
SELECT e.name, e.definition::json, e.webhook, e.num_retries, e.retry_interval, e.headers::json | ||
FROM hdb_catalog.event_triggers e |] () False | ||
forM_ eventTriggers updateEventTrigger3To4 | ||
Q.unitQ [Q.sql| | ||
ALTER TABLE hdb_catalog.event_triggers | ||
DROP COLUMN definition, | ||
DROP COLUMN query, | ||
DROP COLUMN webhook, | ||
DROP COLUMN num_retries, | ||
DROP COLUMN retry_interval, | ||
DROP COLUMN headers |] () False | ||
where | ||
uncurryEventTrigger (trn, Q.AltJ tDef, w, nr, rint, Q.AltJ headers) = | ||
EventTriggerConf trn tDef (Just w) Nothing (RetryConf nr rint Nothing) headers | ||
updateEventTrigger3To4 etc@(EventTriggerConf name _ _ _ _ _) = Q.unitQ [Q.sql| | ||
UPDATE hdb_catalog.event_triggers | ||
SET | ||
configuration = $1 | ||
WHERE name = $2 | ||
|] (Q.AltJ $ A.toJSON etc, name) True |