server: Disallow untrack_table for system defined tables. Fix #12 (#15)

This commit is contained in:
Rakesh Emmadi 2018-06-28 17:26:40 +05:30 committed by Vamshi Surabhi
parent f625882199
commit a4dbe58c15

View File

@ -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, cannot untrack"
sc <- askSchemaCache
-- Get Foreign key constraints to this table
@ -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