Commit cc4949f6 authored by Sophie Herold's avatar Sophie Herold 🌼

Allows empty ref_columns in fks

parent 5fc26764
Pipeline #703 passed with stage
in 6 minutes and 30 seconds
......@@ -208,6 +208,8 @@ instance ToSqlStmts (SqlContext (Schema, Table)) where
sqlAddForeignKey' :: ForeignKey -> Maybe SqlStmt
sqlAddForeignKey' fk =
let constr = tableName t <> foreignkeyName fk
refColumns =
fromMaybe (foreignkeyColumns fk) (foreignkeyRefColumns fk)
in newSqlStmt SqlCreateForeignKeyConstr (constrId s t constr) $
"ALTER TABLE " <> sqlIdCode obj <> " ADD CONSTRAINT " <>
toSqlCode constr <>
......@@ -217,7 +219,7 @@ instance ToSqlStmts (SqlContext (Schema, Table)) where
" REFERENCES " <>
toSqlCode (foreignkeyRefTable fk) <>
" (" <>
T.intercalate ", " (map toSqlCode $ foreignkeyRefColumns fk) <>
T.intercalate ", " (map toSqlCode refColumns) <>
")" <>
maybePrefix " ON UPDATE " (foreignkeyOnUpdate fk) <>
maybePrefix " ON DELETE " (foreignkeyOnDelete fk)
......
......@@ -106,7 +106,7 @@ data ForeignKey = ForeignKey
{ foreignkeyName :: SqlName
, foreignkeyColumns :: [SqlName]
, foreignkeyRefTable :: SqlName
, foreignkeyRefColumns :: [SqlName]
, foreignkeyRefColumns :: Maybe [SqlName]
, foreignkeyOnDelete :: Maybe Text
, foreignkeyOnUpdate :: Maybe Text
} deriving (Generic, Show, Data)
......
......@@ -78,7 +78,7 @@ parseYamSql xs = do
else throw $
YamsqlException $
"Found unknown YamSql fields: " <>
T.concat (map (explain (keysOfData parsed)) diff)
T.concat (map (explainMissing (keysOfData parsed)) diff)
where
keysOfData u =
"tag" : map (snakeify . removeFirstPart) (constrFields (toConstr u))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment