Skip to content

Commit

Permalink
Column deletion removes assigned foreign key constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
nezbite committed Aug 17, 2020
1 parent aae41f4 commit d3c6fe1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion IHP/IDE/SchemaDesigner/Controller/Columns.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import IHP.IDE.SchemaDesigner.View.Columns.EditForeignKey
import IHP.IDE.SchemaDesigner.Parser
import IHP.IDE.SchemaDesigner.Compiler
import IHP.IDE.SchemaDesigner.Types
import IHP.IDE.SchemaDesigner.View.Layout (findStatementByName, findStatementByName, removeQuotes, replace, getDefaultValue, isIllegalKeyword)
import IHP.IDE.SchemaDesigner.View.Layout (findStatementByName, findStatementByName, removeQuotes, replace, getDefaultValue, isIllegalKeyword, findForeignKey)
import qualified IHP.SchemaCompiler as SchemaCompiler
import qualified System.Process as Process
import IHP.IDE.SchemaDesigner.Parser (schemaFilePath)
Expand Down Expand Up @@ -101,6 +101,9 @@ instance Controller ColumnsController where
statements <- readSchema
let tableName = param "tableName"
let columnId = param "columnId"
let columnName = param "columnName"
case findForeignKey statements tableName columnName of
Just AddConstraint { constraintName, .. } -> updateSchema (deleteForeignKeyConstraint constraintName)
updateSchema (map (deleteColumnInTable tableName columnId))
redirectTo ShowTableAction { .. }

Expand Down
4 changes: 2 additions & 2 deletions IHP/IDE/SchemaDesigner/View/Layout.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module IHP.IDE.SchemaDesigner.View.Layout (schemaDesignerLayout, findStatementByName, visualNav, renderColumnSelector, renderColumn, renderEnumSelector, renderValue, renderObjectSelector, removeQuotes, replace, getDefaultValue, databaseControls, isIllegalKeyword) where
module IHP.IDE.SchemaDesigner.View.Layout (schemaDesignerLayout, findStatementByName, visualNav, renderColumnSelector, renderColumn, renderEnumSelector, renderValue, renderObjectSelector, removeQuotes, replace, getDefaultValue, databaseControls, isIllegalKeyword, findForeignKey) where

import IHP.ViewPrelude
import IHP.IDE.SchemaDesigner.Types
Expand Down Expand Up @@ -123,7 +123,7 @@ renderColumn Column { name, primaryKey, columnType, defaultValue, notNull, isUni
</tr>
<div class="custom-menu menu-for-column shadow backdrop-blur" id={contextMenuId}>
<a href={EditColumnAction tableName id}>Edit Column</a>
<a href={DeleteColumnAction tableName id} class="js-delete">Delete Column</a>
<a href={DeleteColumnAction tableName id name} class="js-delete">Delete Column</a>
<div></div>
<form action={ToggleColumnUniqueAction tableName id}><button type="submit" class="link-button">{toggleButtonText}</button></form>
{foreignKeyOption}
Expand Down
2 changes: 1 addition & 1 deletion IHP/IDE/ToolServer/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ data ColumnsController
| CreateColumnAction
| EditColumnAction { tableName :: Text, columnId :: Int }
| UpdateColumnAction
| DeleteColumnAction { tableName :: Text, columnId :: Int }
| DeleteColumnAction { tableName :: Text, columnId :: Int, columnName :: Text }
| ToggleColumnUniqueAction { tableName :: Text, columnId :: Int }
| NewForeignKeyAction { tableName :: Text, columnName :: Text }
| CreateForeignKeyAction
Expand Down

0 comments on commit d3c6fe1

Please sign in to comment.