Skip to content

Commit

Permalink
Sqlite: do not add foreign key constraints to columns of temporary ta…
Browse files Browse the repository at this point in the history
…bles
  • Loading branch information
paul-rouse committed Nov 24, 2017
1 parent cac89e1 commit ebad2e2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions persistent-sqlite/Database/Persist/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ mkCreateTable isTemp entity (cols, uniqs) =
, " TABLE "
, escape $ entityDB entity
, "("
, T.drop 1 $ T.concat $ map sqlColumn cols
, T.drop 1 $ T.concat $ map (sqlColumn isTemp) cols
, ", PRIMARY KEY "
, "("
, T.intercalate "," $ map (escape . fieldDB) $ compositeFields pdef
Expand All @@ -447,7 +447,7 @@ mkCreateTable isTemp entity (cols, uniqs) =
, showSqlType $ fieldSqlType $ entityId entity
," PRIMARY KEY"
, mayDefault $ defaultAttribute $ fieldAttrs $ entityId entity
, T.concat $ map sqlColumn cols
, T.concat $ map (sqlColumn isTemp) cols
, T.concat $ map sqlUnique uniqs
, ")"
]
Expand All @@ -457,8 +457,8 @@ mayDefault def = case def of
Nothing -> ""
Just d -> " DEFAULT " <> d

sqlColumn :: Column -> Text
sqlColumn (Column name isNull typ def _cn _maxLen ref) = T.concat
sqlColumn :: Bool -> Column -> Text
sqlColumn noRef (Column name isNull typ def _cn _maxLen ref) = T.concat
[ ","
, escape name
, " "
Expand All @@ -467,7 +467,7 @@ sqlColumn (Column name isNull typ def _cn _maxLen ref) = T.concat
, mayDefault def
, case ref of
Nothing -> ""
Just (table, _) -> " REFERENCES " <> escape table
Just (table, _) -> if noRef then "" else " REFERENCES " <> escape table
]

sqlUnique :: UniqueDef -> Text
Expand Down

0 comments on commit ebad2e2

Please sign in to comment.