server: fix bug when downgrading from v2 to v1 when there is atleast one cron trigger present in the metadata

https://github.com/hasura/graphql-engine-mono/pull/2101

GitOrigin-RevId: 7011f0c18cb0cef828214ec084adc39cfb3aba1c
This commit is contained in:
Karthikeyan Chinnakonda 2021-08-17 12:31:14 +05:30 committed by hasura-bot
parent ef2278f9c7
commit 1294ae59f2
4 changed files with 30 additions and 5 deletions

View File

@ -4,6 +4,8 @@
(Add entries below in the order of server, console, cli, docs, others)
- server: fix v2 -> v1 downgrade bug when cron triggers exist
- server: add index on the `event_id` column of the `hdb_cron_event_invocation_logs` table
- server: fix GraphQL type for remote relationship field (close #7284)
- server: support EdDSA algorithm and key type for JWT

View File

@ -3,6 +3,7 @@ module Hasura.RQL.DDL.Schema.LegacyCatalog
( saveMetadataToHdbTables
, fetchMetadataFromHdbTables
, recreateSystemMetadata
, addCronTriggerForeignKeyConstraint
) where
import Hasura.Prelude
@ -529,6 +530,16 @@ fetchMetadataFromHdbTables = liftTx do
, RemoteRelationshipMetadata name definition
)
addCronTriggerForeignKeyConstraint :: MonadTx m => m ()
addCronTriggerForeignKeyConstraint =
liftTx $
Q.unitQE defaultTxErrorHandler [Q.sql|
ALTER TABLE hdb_catalog.hdb_cron_events ADD CONSTRAINT
hdb_cron_events_trigger_name_fkey FOREIGN KEY (trigger_name)
REFERENCES hdb_catalog.hdb_cron_triggers(name)
ON UPDATE CASCADE ON DELETE CASCADE;
|] () False
-- | Drops and recreates all “system-defined” metadata, aka metadata for tables and views in the
-- @information_schema@ and @hdb_catalog@ schemas. These tables and views are tracked to expose them
-- to the console, which allows us to reuse the same functionality we use to implement user-defined

View File

@ -301,5 +301,12 @@ migrations maybeDefaultSourceConfig dryRun maintenanceMode =
MetadataNoSources _smTables _smFunctions _metaRemoteSchemas _metaQueryCollections
_metaAllowlist _metaCustomTypes _metaActions _metaCronTriggers
_ -> throw400 NotSupported "Cannot downgrade since there are more than one source"
liftTx $ runHasSystemDefinedT (SystemDefined False) $ saveMetadataToHdbTables metadataV2
liftTx $ do
runHasSystemDefinedT (SystemDefined False) $ saveMetadataToHdbTables metadataV2
-- when the graphql-engine is migrated from v1 to v2, we drop the foreign key
-- constraint of the `hdb_catalog.hdb_cron_event` table because the cron triggers
-- in v2 are saved in the `hdb_catalog.hdb_metadata` table. So, when a downgrade
-- happens, we need to delay adding the foreign key constraint until the
-- cron triggers are added in the `hdb_catalog.hdb_cron_triggers`
addCronTriggerForeignKeyConstraint
recreateSystemMetadata

View File

@ -675,11 +675,16 @@ CREATE TABLE hdb_catalog.hdb_cron_triggers
comment TEXT
);
-- The below statement is run separately and is run after the cron triggers
-- are inserted in the hdb_catalog.hdb_cron_events table. See `from43To42`
-- in Migrate.hs for more details.
-- Add foreign key constraint from hdb_cron_events to hdb_cron_triggers
ALTER TABLE hdb_catalog.hdb_cron_events ADD CONSTRAINT
hdb_cron_events_trigger_name_fkey FOREIGN KEY (trigger_name)
REFERENCES hdb_catalog.hdb_cron_triggers(name)
ON UPDATE CASCADE ON DELETE CASCADE;
-- ALTER TABLE hdb_catalog.hdb_cron_events ADD CONSTRAINT
-- hdb_cron_events_trigger_name_fkey FOREIGN KEY (trigger_name)
-- REFERENCES hdb_catalog.hdb_cron_triggers(name)
-- ON UPDATE CASCADE ON DELETE CASCADE;
CREATE VIEW hdb_catalog.hdb_cron_events_stats AS
SELECT ct.name,