Skip to content

Commit

Permalink
server: Disallow untrack for system defined tables. Fix #12
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshkky committed Jun 28, 2018
1 parent c0bf346 commit 1969350
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/src-lib/Hasura/RQL/DDL/Schema/Table.hs
Expand Up @@ -206,6 +206,11 @@ unTrackExistingTableOrViewP1 ut@(UntrackTable vn _) = do
unTrackExistingTableOrViewP2 :: (P2C m)
=> UntrackTable -> TableInfo -> m RespBody
unTrackExistingTableOrViewP2 (UntrackTable vn cascade) tableInfo = do
-- Check if table/view is system defined
isSystemDefined <- liftTx isSystemDefinedTx
when isSystemDefined $ throw400 NotSupported $
vn <<> " is system defined. Untrack not supported"

sc <- askSchemaCache

-- Get Foreign key constraints to this table
Expand Down Expand Up @@ -236,13 +241,20 @@ unTrackExistingTableOrViewP2 (UntrackTable vn cascade) tableInfo = do
return successMsg
where
QualifiedTable sn tn = vn
isSystemDefinedTx = Q.catchE defaultTxErrorHandler $
runIdentity . Q.getRow <$> Q.withQ [Q.sql|
SELECT is_system_defined
FROM hdb_catalog.hdb_table
WHERE table_schema = $1
AND table_name = $2
|] (sn, tn) False
getFKeyTables = Q.catchE defaultTxErrorHandler $ Q.listQ [Q.sql|
SELECT constraint_name,
table_schema,
table_name
FROM hdb_catalog.hdb_foreign_key_constraint
WHERE ref_table_table_schema = $1
AND ref_table =$2
AND ref_table = $2
|] (sn, tn) False
filterTables tables tc = flip filter tables $ \(_, s, t) ->
isJust $ M.lookup (QualifiedTable s t) tc
Expand Down

0 comments on commit 1969350

Please sign in to comment.