diff --git a/IHP/IDE/SchemaDesigner/SchemaOperations.hs b/IHP/IDE/SchemaDesigner/SchemaOperations.hs index 4e0986129..93fdc964c 100644 --- a/IHP/IDE/SchemaDesigner/SchemaOperations.hs +++ b/IHP/IDE/SchemaDesigner/SchemaOperations.hs @@ -552,11 +552,43 @@ deleteColumn DeleteColumnOptions { .. } schema = then deleteTriggerIfExists (updatedAtTriggerName tableName) else \schema -> schema ) + |> filter deletePolicyReferencingPolicy where deleteColumnInTable :: Statement -> Statement deleteColumnInTable (StatementCreateTable table@CreateTable { name, columns }) | name == tableName = StatementCreateTable $ table { columns = delete (columns !! columnId) columns} deleteColumnInTable statement = statement + deletePolicyReferencingPolicy :: Statement -> Bool + deletePolicyReferencingPolicy CreatePolicy { tableName = policyTable, using, check } | policyTable == tableName = + case (using, check) of + (Just using, Nothing) -> not (isRef using) + (Nothing, Just check) -> not (isRef check) + (Just using, Just check) -> not (isRef using && isRef check) + where + isRef :: Expression -> Bool + isRef (TextExpression {}) = False + isRef (VarExpression var) = var == columnName + isRef (CallExpression _ args) = foldl' (||) False (map isRef args) + isRef (NotEqExpression a b) = isRef a || isRef b + isRef (EqExpression a b) = isRef a || isRef b + isRef (AndExpression a b) = isRef a || isRef b + isRef (IsExpression a b) = isRef a || isRef b + isRef (InExpression a b) = isRef a || isRef b + isRef (NotExpression a) = isRef a + isRef (ExistsExpression a) = isRef a + isRef (OrExpression a b) = isRef a || isRef b + isRef (LessThanExpression a b) = isRef a || isRef b + isRef (LessThanOrEqualToExpression a b) = isRef a || isRef b + isRef (GreaterThanExpression a b) = isRef a || isRef b + isRef (GreaterThanOrEqualToExpression a b) = isRef a || isRef b + isRef (DoubleExpression _) = False + isRef (IntExpression _) = False + isRef (TypeCastExpression a _) = isRef a + isRef (SelectExpression _) = False + isRef (DotExpression a _) = isRef a + isRef (ConcatenationExpression a b) = isRef a || isRef b + deletePolicyReferencingPolicy otherwise = True + -- | Returns True if a CreateIndex statement references a specific column -- -- E.g. given a schema like this: diff --git a/IHP/IDE/SchemaDesigner/View/Layout.hs b/IHP/IDE/SchemaDesigner/View/Layout.hs index 7aa0dc6e0..46d2bd677 100644 --- a/IHP/IDE/SchemaDesigner/View/Layout.hs +++ b/IHP/IDE/SchemaDesigner/View/Layout.hs @@ -345,12 +345,12 @@ suggestedColumnsSection tableName indexAndColumns = unless isUsersTable [hsx| - + - +