2018-06-27 16:11:32 +03:00
|
|
|
module Ops
|
|
|
|
( initCatalogSafe
|
|
|
|
, cleanCatalog
|
|
|
|
, migrateCatalog
|
|
|
|
, execQuery
|
|
|
|
) where
|
|
|
|
|
2018-09-14 14:41:51 +03:00
|
|
|
import Data.Time.Clock (UTCTime)
|
2019-01-02 14:24:17 +03:00
|
|
|
import Language.Haskell.TH.Syntax (Q, TExp, unTypeQ)
|
2018-06-27 16:11:32 +03:00
|
|
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.DDL.Schema.Table
|
2018-09-28 13:52:54 +03:00
|
|
|
import Hasura.RQL.DDL.Utils (clearHdbViews)
|
2018-06-27 16:11:32 +03:00
|
|
|
import Hasura.RQL.Types
|
|
|
|
import Hasura.Server.Query
|
|
|
|
import Hasura.SQL.Types
|
|
|
|
|
2018-09-14 14:41:51 +03:00
|
|
|
import qualified Data.Aeson as A
|
|
|
|
import qualified Data.ByteString.Lazy as BL
|
|
|
|
import qualified Data.Text as T
|
2019-01-02 14:24:17 +03:00
|
|
|
import qualified Data.Yaml.TH as Y
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2018-09-14 14:41:51 +03:00
|
|
|
import qualified Database.PG.Query as Q
|
|
|
|
import qualified Database.PG.Query.Connection as Q
|
2018-06-27 16:11:32 +03:00
|
|
|
|
|
|
|
curCatalogVer :: T.Text
|
2019-01-28 16:55:28 +03:00
|
|
|
curCatalogVer = "9"
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
initCatalogSafe
|
|
|
|
:: (QErrM m, UserInfoM m, CacheRWM m, MonadTx m, MonadIO m, HasHttpManager m)
|
|
|
|
=> UTCTime -> m String
|
|
|
|
initCatalogSafe initTime = do
|
|
|
|
hdbCatalogExists <- liftTx $ Q.catchE defaultTxErrorHandler $
|
2018-06-27 16:11:32 +03:00
|
|
|
doesSchemaExist $ SchemaName "hdb_catalog"
|
2018-12-13 10:26:15 +03:00
|
|
|
bool (initCatalogStrict True initTime) onCatalogExists hdbCatalogExists
|
2018-06-27 16:11:32 +03:00
|
|
|
where
|
|
|
|
onCatalogExists = do
|
2018-12-13 10:26:15 +03:00
|
|
|
versionExists <- liftTx $ Q.catchE defaultTxErrorHandler $
|
2018-06-27 16:11:32 +03:00
|
|
|
doesVersionTblExist
|
|
|
|
(SchemaName "hdb_catalog") (TableName "hdb_version")
|
2018-12-13 10:26:15 +03:00
|
|
|
bool (initCatalogStrict False initTime) (return initialisedMsg) versionExists
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2019-01-02 14:24:17 +03:00
|
|
|
initialisedMsg = "the state is already initialised"
|
2018-06-27 16:11:32 +03:00
|
|
|
|
|
|
|
doesVersionTblExist sn tblN =
|
|
|
|
(runIdentity . Q.getRow) <$> Q.withQ [Q.sql|
|
|
|
|
SELECT EXISTS (
|
|
|
|
SELECT 1
|
|
|
|
FROM pg_tables
|
|
|
|
WHERE schemaname = $1 AND tablename = $2)
|
|
|
|
|] (sn, tblN) False
|
|
|
|
|
|
|
|
doesSchemaExist sn =
|
|
|
|
(runIdentity . Q.getRow) <$> Q.withQ [Q.sql|
|
|
|
|
SELECT EXISTS (
|
|
|
|
SELECT 1
|
|
|
|
FROM information_schema.schemata
|
|
|
|
WHERE schema_name = $1
|
|
|
|
)
|
|
|
|
|] (Identity sn) False
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
initCatalogStrict
|
|
|
|
:: (QErrM m, UserInfoM m, CacheRWM m, MonadTx m, MonadIO m, HasHttpManager m)
|
|
|
|
=> Bool -> UTCTime -> m String
|
|
|
|
initCatalogStrict createSchema initTime = do
|
|
|
|
liftTx $ Q.catchE defaultTxErrorHandler $
|
2018-06-27 16:11:32 +03:00
|
|
|
when createSchema $ do
|
|
|
|
Q.unitQ "CREATE SCHEMA hdb_catalog" () False
|
|
|
|
-- This is where the generated views and triggers are stored
|
|
|
|
Q.unitQ "CREATE SCHEMA hdb_views" () False
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
pgcryptoExtExists <- liftTx $
|
|
|
|
Q.catchE defaultTxErrorHandler $ isExtAvailable "pgcrypto"
|
|
|
|
|
2018-09-14 14:41:51 +03:00
|
|
|
if pgcryptoExtExists
|
|
|
|
-- only if we created the schema, create the extension
|
2018-12-13 10:26:15 +03:00
|
|
|
then when createSchema $ liftTx $ Q.unitQE needsPgCryptoExt
|
|
|
|
"CREATE EXTENSION IF NOT EXISTS pgcrypto SCHEMA public" () False
|
2019-01-08 12:05:25 +03:00
|
|
|
else throw500 pgcryptoNotAvlMsg
|
2018-09-14 14:41:51 +03:00
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
liftTx $ Q.catchE defaultTxErrorHandler $ do
|
2018-06-27 16:11:32 +03:00
|
|
|
Q.Discard () <- Q.multiQ $(Q.sqlFromFile "src-rsr/initialise.sql")
|
|
|
|
return ()
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
-- add default metadata
|
|
|
|
void $ runQueryM metadataQuery
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2018-09-05 14:42:20 +03:00
|
|
|
setAllAsSystemDefined >> addVersion initTime
|
2019-01-02 14:24:17 +03:00
|
|
|
return "successfully initialised"
|
2018-09-14 14:41:51 +03:00
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
where
|
2018-12-13 10:26:15 +03:00
|
|
|
metadataQuery =
|
|
|
|
$(unTypeQ (Y.decodeFile "src-rsr/hdb_metadata.yaml" :: Q (TExp RQLQuery)))
|
2018-09-14 14:41:51 +03:00
|
|
|
needsPgCryptoExt :: Q.PGTxErr -> QErr
|
|
|
|
needsPgCryptoExt e@(Q.PGTxErr _ _ _ err) =
|
|
|
|
case err of
|
|
|
|
Q.PGIUnexpected _ -> (err500 PostgresError pgcryptoReqdMsg) { qeInternal = Just $ A.toJSON e }
|
|
|
|
Q.PGIStatement pgErr ->
|
|
|
|
case Q.edStatusCode pgErr of
|
|
|
|
Just "42501" -> err500 PostgresError pgcryptoPermsMsg
|
|
|
|
_ -> (err500 PostgresError pgcryptoReqdMsg) { qeInternal = Just $ A.toJSON e }
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
addVersion modTime = liftTx $ Q.catchE defaultTxErrorHandler $
|
2018-06-27 16:11:32 +03:00
|
|
|
Q.unitQ [Q.sql|
|
2019-01-28 16:55:28 +03:00
|
|
|
INSERT INTO "hdb_catalog"."hdb_version"
|
|
|
|
(version, upgraded_on) VALUES ($1, $2)
|
2018-06-27 16:11:32 +03:00
|
|
|
|] (curCatalogVer, modTime) False
|
|
|
|
|
2018-09-14 14:41:51 +03:00
|
|
|
isExtAvailable :: T.Text -> Q.Tx Bool
|
|
|
|
isExtAvailable sn =
|
2018-06-27 16:11:32 +03:00
|
|
|
(runIdentity . Q.getRow) <$> Q.withQ [Q.sql|
|
|
|
|
SELECT EXISTS (
|
|
|
|
SELECT 1
|
|
|
|
FROM pg_catalog.pg_available_extensions
|
|
|
|
WHERE name = $1
|
|
|
|
)
|
|
|
|
|] (Identity sn) False
|
|
|
|
|
|
|
|
|
2019-01-25 06:31:54 +03:00
|
|
|
migrateMetadata
|
|
|
|
:: (MonadTx m, HasHttpManager m, CacheRWM m, UserInfoM m, MonadIO m)
|
|
|
|
=> RQLQuery -> m ()
|
|
|
|
migrateMetadata rqlQuery = do
|
|
|
|
-- build schema cache
|
|
|
|
buildSchemaCache
|
|
|
|
-- run the RQL query to migrate metadata
|
|
|
|
void $ runQueryM rqlQuery
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
setAllAsSystemDefined :: (MonadTx m) => m ()
|
|
|
|
setAllAsSystemDefined = liftTx $ Q.catchE defaultTxErrorHandler $ do
|
2018-09-05 14:42:20 +03:00
|
|
|
Q.unitQ "UPDATE hdb_catalog.hdb_table SET is_system_defined = 'true'" () False
|
|
|
|
Q.unitQ "UPDATE hdb_catalog.hdb_relationship SET is_system_defined = 'true'" () False
|
|
|
|
Q.unitQ "UPDATE hdb_catalog.hdb_permission SET is_system_defined = 'true'" () False
|
|
|
|
Q.unitQ "UPDATE hdb_catalog.hdb_query_template SET is_system_defined = 'true'" () False
|
|
|
|
|
2019-01-25 06:31:54 +03:00
|
|
|
setAsSystemDefinedFor2 :: (MonadTx m) => m ()
|
|
|
|
setAsSystemDefinedFor2 =
|
2018-12-13 10:26:15 +03:00
|
|
|
liftTx $ Q.catchE defaultTxErrorHandler $
|
2018-09-05 14:42:20 +03:00
|
|
|
Q.multiQ [Q.sql|
|
|
|
|
UPDATE hdb_catalog.hdb_table
|
|
|
|
SET is_system_defined = 'true'
|
2019-01-25 06:31:54 +03:00
|
|
|
WHERE table_schema = 'hdb_catalog'
|
|
|
|
AND ( table_name = 'event_triggers'
|
|
|
|
OR table_name = 'event_log'
|
|
|
|
OR table_name = 'event_invocation_logs'
|
|
|
|
);
|
|
|
|
UPDATE hdb_catalog.hdb_relationship
|
2018-09-05 14:42:20 +03:00
|
|
|
SET is_system_defined = 'true'
|
2019-01-25 06:31:54 +03:00
|
|
|
WHERE table_schema = 'hdb_catalog'
|
|
|
|
AND ( table_name = 'event_triggers'
|
|
|
|
OR table_name = 'event_log'
|
|
|
|
OR table_name = 'event_invocation_logs'
|
|
|
|
);
|
|
|
|
|]
|
|
|
|
|
|
|
|
setAsSystemDefinedFor5 :: (MonadTx m) => m ()
|
|
|
|
setAsSystemDefinedFor5 =
|
|
|
|
liftTx $ Q.catchE defaultTxErrorHandler $
|
|
|
|
Q.multiQ [Q.sql|
|
|
|
|
UPDATE hdb_catalog.hdb_table
|
|
|
|
SET is_system_defined = 'true'
|
|
|
|
WHERE table_schema = 'hdb_catalog'
|
|
|
|
AND table_name = 'remote_schemas';
|
|
|
|
|]
|
2018-09-05 14:42:20 +03:00
|
|
|
|
2019-01-25 06:31:54 +03:00
|
|
|
setAsSystemDefinedFor8 :: (MonadTx m) => m ()
|
|
|
|
setAsSystemDefinedFor8 =
|
|
|
|
liftTx $ Q.catchE defaultTxErrorHandler $
|
|
|
|
Q.multiQ [Q.sql|
|
|
|
|
UPDATE hdb_catalog.hdb_table
|
|
|
|
SET is_system_defined = 'true'
|
|
|
|
WHERE table_schema = 'hdb_catalog'
|
|
|
|
AND ( table_name = 'hdb_function_agg'
|
|
|
|
OR table_name = 'hdb_function'
|
|
|
|
);
|
2018-09-05 14:42:20 +03:00
|
|
|
UPDATE hdb_catalog.hdb_relationship
|
|
|
|
SET is_system_defined = 'true'
|
2019-01-25 06:31:54 +03:00
|
|
|
WHERE table_schema = 'hdb_catalog'
|
|
|
|
AND table_name = 'hdb_function_agg';
|
|
|
|
|]
|
2018-09-05 14:42:20 +03:00
|
|
|
|
2019-01-28 16:55:28 +03:00
|
|
|
setAsSystemDefinedFor9 :: (MonadTx m) => m ()
|
|
|
|
setAsSystemDefinedFor9 =
|
|
|
|
liftTx $ Q.catchE defaultTxErrorHandler $
|
|
|
|
Q.multiQ [Q.sql|
|
|
|
|
UPDATE hdb_catalog.hdb_table
|
|
|
|
SET is_system_defined = 'true'
|
|
|
|
WHERE table_schema = 'hdb_catalog'
|
|
|
|
AND table_name = 'hdb_version';
|
|
|
|
|]
|
|
|
|
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
cleanCatalog :: (MonadTx m) => m ()
|
|
|
|
cleanCatalog = liftTx $ Q.catchE defaultTxErrorHandler $ do
|
2018-06-27 16:11:32 +03:00
|
|
|
-- This is where the generated views and triggers are stored
|
|
|
|
Q.unitQ "DROP SCHEMA IF EXISTS hdb_views CASCADE" () False
|
|
|
|
Q.unitQ "DROP SCHEMA hdb_catalog CASCADE" () False
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
getCatalogVersion
|
|
|
|
:: (MonadTx m)
|
|
|
|
=> m T.Text
|
2018-06-27 16:11:32 +03:00
|
|
|
getCatalogVersion = do
|
2018-12-13 10:26:15 +03:00
|
|
|
res <- liftTx $ Q.withQE defaultTxErrorHandler [Q.sql|
|
2018-06-27 16:11:32 +03:00
|
|
|
SELECT version FROM hdb_catalog.hdb_version
|
|
|
|
|] () False
|
|
|
|
return $ runIdentity $ Q.getRow res
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
from08To1 :: (MonadTx m) => m ()
|
|
|
|
from08To1 = liftTx $ Q.catchE defaultTxErrorHandler $ do
|
2018-06-27 16:11:32 +03:00
|
|
|
Q.unitQ "ALTER TABLE hdb_catalog.hdb_relationship ADD COLUMN comment TEXT NULL" () False
|
|
|
|
Q.unitQ "ALTER TABLE hdb_catalog.hdb_permission ADD COLUMN comment TEXT NULL" () False
|
|
|
|
Q.unitQ "ALTER TABLE hdb_catalog.hdb_query_template ADD COLUMN comment TEXT NULL" () False
|
|
|
|
Q.unitQ [Q.sql|
|
|
|
|
UPDATE hdb_catalog.hdb_query_template
|
|
|
|
SET template_defn =
|
|
|
|
json_build_object('type', 'select', 'args', template_defn->'select');
|
|
|
|
|] () False
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
from1To2
|
|
|
|
:: (MonadTx m, HasHttpManager m, CacheRWM m, UserInfoM m, MonadIO m)
|
|
|
|
=> m ()
|
|
|
|
from1To2 = do
|
2018-09-05 14:42:20 +03:00
|
|
|
-- migrate database
|
2018-12-13 10:26:15 +03:00
|
|
|
Q.Discard () <- liftTx $ Q.multiQE defaultTxErrorHandler
|
2018-09-05 14:42:20 +03:00
|
|
|
$(Q.sqlFromFile "src-rsr/migrate_from_1.sql")
|
2019-01-25 06:31:54 +03:00
|
|
|
migrateMetadata migrateMetadataFrom1
|
2018-09-05 14:42:20 +03:00
|
|
|
-- set as system defined
|
2019-01-25 06:31:54 +03:00
|
|
|
setAsSystemDefinedFor2
|
2018-12-13 10:26:15 +03:00
|
|
|
where
|
|
|
|
migrateMetadataFrom1 =
|
|
|
|
$(unTypeQ (Y.decodeFile "src-rsr/migrate_metadata_from_1.yaml" :: Q (TExp RQLQuery)))
|
2018-09-05 14:42:20 +03:00
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
from2To3 :: (MonadTx m) => m ()
|
|
|
|
from2To3 = liftTx $ Q.catchE defaultTxErrorHandler $ do
|
2018-09-24 14:50:11 +03:00
|
|
|
Q.unitQ "ALTER TABLE hdb_catalog.event_triggers ADD COLUMN headers JSON" () False
|
|
|
|
Q.unitQ "ALTER TABLE hdb_catalog.event_log ADD COLUMN next_retry_at TIMESTAMP" () False
|
|
|
|
Q.unitQ "CREATE INDEX ON hdb_catalog.event_log (trigger_id)" () False
|
|
|
|
Q.unitQ "CREATE INDEX ON hdb_catalog.event_invocation_logs (event_id)" () False
|
|
|
|
|
2018-11-23 16:02:46 +03:00
|
|
|
-- custom resolver
|
2018-12-13 10:26:15 +03:00
|
|
|
from4To5
|
|
|
|
:: (MonadTx m, HasHttpManager m, CacheRWM m, UserInfoM m, MonadIO m)
|
|
|
|
=> m ()
|
|
|
|
from4To5 = do
|
|
|
|
Q.Discard () <- liftTx $ Q.multiQE defaultTxErrorHandler
|
2018-11-23 16:02:46 +03:00
|
|
|
$(Q.sqlFromFile "src-rsr/migrate_from_4_to_5.sql")
|
2019-01-25 06:31:54 +03:00
|
|
|
migrateMetadata migrateMetadataFrom4
|
2018-11-23 16:02:46 +03:00
|
|
|
-- set as system defined
|
2019-01-25 06:31:54 +03:00
|
|
|
setAsSystemDefinedFor5
|
2018-12-13 10:26:15 +03:00
|
|
|
where
|
|
|
|
migrateMetadataFrom4 =
|
|
|
|
$(unTypeQ (Y.decodeFile "src-rsr/migrate_metadata_from_4_to_5.yaml" :: Q (TExp RQLQuery)))
|
2018-11-23 16:02:46 +03:00
|
|
|
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
from3To4 :: (MonadTx m) => m ()
|
|
|
|
from3To4 = liftTx $ Q.catchE defaultTxErrorHandler $ do
|
2018-11-14 10:13:01 +03:00
|
|
|
Q.unitQ "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 "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
|
2018-11-23 16:02:46 +03:00
|
|
|
uncurryEventTrigger (trn, Q.AltJ tDef, w, nr, rint, Q.AltJ headers) =
|
|
|
|
EventTriggerConf trn tDef (Just w) Nothing (RetryConf nr rint) headers
|
2018-11-14 10:13:01 +03:00
|
|
|
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
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
from5To6 :: (MonadTx m) => m ()
|
|
|
|
from5To6 = liftTx $ do
|
2018-11-27 19:10:54 +03:00
|
|
|
-- migrate database
|
|
|
|
Q.Discard () <- Q.multiQE defaultTxErrorHandler
|
|
|
|
$(Q.sqlFromFile "src-rsr/migrate_from_5_to_6.sql")
|
|
|
|
return ()
|
|
|
|
|
2019-01-04 14:06:05 +03:00
|
|
|
from6To7 :: (MonadTx m) => m ()
|
|
|
|
from6To7 = liftTx $ do
|
|
|
|
-- migrate database
|
|
|
|
Q.Discard () <- Q.multiQE defaultTxErrorHandler
|
|
|
|
$(Q.sqlFromFile "src-rsr/migrate_from_6_to_7.sql")
|
|
|
|
return ()
|
|
|
|
|
2019-01-25 06:31:54 +03:00
|
|
|
from7To8
|
|
|
|
:: (MonadTx m, HasHttpManager m, CacheRWM m, UserInfoM m, MonadIO m)
|
|
|
|
=> m ()
|
|
|
|
from7To8 = do
|
|
|
|
-- migrate database
|
|
|
|
Q.Discard () <- liftTx $ Q.multiQE defaultTxErrorHandler
|
|
|
|
$(Q.sqlFromFile "src-rsr/migrate_from_7_to_8.sql")
|
|
|
|
-- migrate metadata
|
|
|
|
migrateMetadata migrateMetadataFrom7
|
|
|
|
setAsSystemDefinedFor8
|
|
|
|
where
|
|
|
|
migrateMetadataFrom7 =
|
|
|
|
$(unTypeQ (Y.decodeFile "src-rsr/migrate_metadata_from_7_to_8.yaml" :: Q (TExp RQLQuery)))
|
|
|
|
|
2019-01-28 16:55:28 +03:00
|
|
|
-- alter hdb_version table and track it (telemetry changes)
|
|
|
|
from8To9
|
|
|
|
:: (MonadTx m, HasHttpManager m, CacheRWM m, UserInfoM m, MonadIO m)
|
|
|
|
=> m ()
|
|
|
|
from8To9 = do
|
|
|
|
Q.Discard () <- liftTx $ Q.multiQE defaultTxErrorHandler
|
|
|
|
$(Q.sqlFromFile "src-rsr/migrate_from_8_to_9.sql")
|
|
|
|
void $ runQueryM migrateMetadataFrom8
|
|
|
|
-- set as system defined
|
|
|
|
setAsSystemDefinedFor9
|
|
|
|
where
|
|
|
|
migrateMetadataFrom8 =
|
|
|
|
$(unTypeQ (Y.decodeFile "src-rsr/migrate_metadata_from_8_to_9.yaml" :: Q (TExp RQLQuery)))
|
|
|
|
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
migrateCatalog
|
|
|
|
:: (MonadTx m, CacheRWM m, MonadIO m, UserInfoM m, HasHttpManager m)
|
|
|
|
=> UTCTime -> m String
|
|
|
|
migrateCatalog migrationTime = do
|
2018-06-27 16:11:32 +03:00
|
|
|
preVer <- getCatalogVersion
|
|
|
|
if | preVer == curCatalogVer ->
|
2019-01-02 14:24:17 +03:00
|
|
|
return "already at the latest version"
|
2018-09-28 13:52:54 +03:00
|
|
|
| preVer == "0.8" -> from08ToCurrent
|
|
|
|
| preVer == "1" -> from1ToCurrent
|
|
|
|
| preVer == "2" -> from2ToCurrent
|
2018-11-14 10:13:01 +03:00
|
|
|
| preVer == "3" -> from3ToCurrent
|
2018-11-23 16:02:46 +03:00
|
|
|
| preVer == "4" -> from4ToCurrent
|
2018-11-27 19:10:54 +03:00
|
|
|
| preVer == "5" -> from5ToCurrent
|
2019-01-04 14:06:05 +03:00
|
|
|
| preVer == "6" -> from6ToCurrent
|
2019-01-25 06:31:54 +03:00
|
|
|
| preVer == "7" -> from7ToCurrent
|
2019-01-28 16:55:28 +03:00
|
|
|
| preVer == "8" -> from8ToCurrent
|
2018-06-27 16:11:32 +03:00
|
|
|
| otherwise -> throw400 NotSupported $
|
2019-01-02 14:24:17 +03:00
|
|
|
"unsupported version : " <> preVer
|
2018-06-27 16:11:32 +03:00
|
|
|
where
|
2019-01-28 16:55:28 +03:00
|
|
|
from8ToCurrent = do
|
|
|
|
from8To9
|
|
|
|
postMigrate
|
|
|
|
|
2019-01-25 06:31:54 +03:00
|
|
|
from7ToCurrent = do
|
|
|
|
from7To8
|
2019-01-28 16:55:28 +03:00
|
|
|
from8ToCurrent
|
2019-01-25 06:31:54 +03:00
|
|
|
|
2019-01-04 14:06:05 +03:00
|
|
|
from6ToCurrent = do
|
|
|
|
from6To7
|
2019-01-25 06:31:54 +03:00
|
|
|
from7ToCurrent
|
2019-01-04 14:06:05 +03:00
|
|
|
|
2018-11-27 19:10:54 +03:00
|
|
|
from5ToCurrent = do
|
|
|
|
from5To6
|
2019-01-04 14:06:05 +03:00
|
|
|
from6ToCurrent
|
2018-11-27 19:10:54 +03:00
|
|
|
|
2018-11-23 16:02:46 +03:00
|
|
|
from4ToCurrent = do
|
2018-12-13 10:26:15 +03:00
|
|
|
from4To5
|
2018-11-27 19:10:54 +03:00
|
|
|
from5ToCurrent
|
2018-11-23 16:02:46 +03:00
|
|
|
|
2018-11-14 10:13:01 +03:00
|
|
|
from3ToCurrent = do
|
|
|
|
from3To4
|
2018-11-23 16:02:46 +03:00
|
|
|
from4ToCurrent
|
2018-11-14 10:13:01 +03:00
|
|
|
|
2018-09-28 13:52:54 +03:00
|
|
|
from2ToCurrent = do
|
|
|
|
from2To3
|
2018-11-14 10:13:01 +03:00
|
|
|
from3ToCurrent
|
2018-09-28 13:52:54 +03:00
|
|
|
|
|
|
|
from1ToCurrent = do
|
2018-12-13 10:26:15 +03:00
|
|
|
from1To2
|
2018-09-28 13:52:54 +03:00
|
|
|
from2ToCurrent
|
|
|
|
|
|
|
|
from08ToCurrent = do
|
|
|
|
from08To1
|
|
|
|
from1ToCurrent
|
|
|
|
|
|
|
|
postMigrate = do
|
2018-09-05 14:42:20 +03:00
|
|
|
-- update the catalog version
|
|
|
|
updateVersion
|
|
|
|
-- clean hdb_views
|
2018-12-13 10:26:15 +03:00
|
|
|
liftTx $ Q.catchE defaultTxErrorHandler clearHdbViews
|
2018-09-05 14:42:20 +03:00
|
|
|
-- try building the schema cache
|
2019-01-25 06:31:54 +03:00
|
|
|
buildSchemaCache
|
2019-01-02 14:24:17 +03:00
|
|
|
return $ "successfully migrated to " ++ show curCatalogVer
|
2018-09-05 14:42:20 +03:00
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
updateVersion =
|
2018-12-13 10:26:15 +03:00
|
|
|
liftTx $ Q.unitQE defaultTxErrorHandler [Q.sql|
|
2018-06-27 16:11:32 +03:00
|
|
|
UPDATE "hdb_catalog"."hdb_version"
|
|
|
|
SET "version" = $1,
|
|
|
|
"upgraded_on" = $2
|
|
|
|
|] (curCatalogVer, migrationTime) False
|
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
execQuery
|
|
|
|
:: (MonadTx m, CacheRWM m, MonadIO m, UserInfoM m, HasHttpManager m)
|
|
|
|
=> BL.ByteString -> m BL.ByteString
|
|
|
|
execQuery queryBs = do
|
2018-06-27 16:11:32 +03:00
|
|
|
query <- case A.decode queryBs of
|
|
|
|
Just jVal -> decodeValue jVal
|
|
|
|
Nothing -> throw400 InvalidJSON "invalid json"
|
2018-12-13 10:26:15 +03:00
|
|
|
buildSchemaCache
|
|
|
|
runQueryM query
|
2018-09-14 14:41:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
-- error messages
|
|
|
|
pgcryptoReqdMsg :: T.Text
|
|
|
|
pgcryptoReqdMsg =
|
2019-01-08 12:05:25 +03:00
|
|
|
"pgcrypto extension is required, but could not install; encountered unknown postgres error"
|
2018-09-14 14:41:51 +03:00
|
|
|
|
|
|
|
pgcryptoPermsMsg :: T.Text
|
|
|
|
pgcryptoPermsMsg =
|
|
|
|
"pgcrypto extension is required, but current user doesn't have permission to create it. "
|
|
|
|
<> "Please grant superuser permission or setup initial schema via "
|
|
|
|
<> "https://docs.hasura.io/1.0/graphql/manual/deployment/postgres-permissions.html"
|
2019-01-08 12:05:25 +03:00
|
|
|
|
|
|
|
pgcryptoNotAvlMsg :: T.Text
|
|
|
|
pgcryptoNotAvlMsg =
|
|
|
|
"pgcrypto extension is required, but could not find the extension in the "
|
|
|
|
<> "PostgreSQL server. Please make sure this extension is available."
|