Skip to content

Commit

Permalink
Port yesodweb#672 from mysql-haskell.
Browse files Browse the repository at this point in the history
  • Loading branch information
naushadh committed Aug 7, 2017
1 parent 9374d02 commit 33bd9e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions persistent-mysql-haskell/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.3.2.1
- Port from `mysql-haskell`: Prevent spurious no-op migrations when `default=NULL` is specified - revised version [#672](https://github.com/yesodweb/persistent/pull/672) (which fixes bug [#671](https://github.com/yesodweb/persistent/issues/671) introduced by the earlier attempt [#641](https://github.com/yesodweb/persistent/pull/641)).

## 0.3.2.0
- Added conditional declaration of `Show` instance for mysql-haskell's `ConnectInfo` for compatibility with `mysql-haskell-0.8.1.0+`.

Expand Down
14 changes: 9 additions & 5 deletions persistent-mysql-haskell/Database/Persist/MySQL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ getColumns connectInfo getter def = do
stmtIdClmn <- getter "SELECT COLUMN_NAME, \
\IS_NULLABLE, \
\DATA_TYPE, \
\IF(IS_NULLABLE='YES', COALESCE(COLUMN_DEFAULT, 'NULL'), COLUMN_DEFAULT) \
\COLUMN_DEFAULT \
\FROM INFORMATION_SCHEMA.COLUMNS \
\WHERE TABLE_SCHEMA = ? \
\AND TABLE_NAME = ? \
Expand All @@ -495,7 +495,7 @@ getColumns connectInfo getter def = do
\CHARACTER_MAXIMUM_LENGTH, \
\NUMERIC_PRECISION, \
\NUMERIC_SCALE, \
\IF(IS_NULLABLE='YES', COALESCE(COLUMN_DEFAULT, 'NULL'), COLUMN_DEFAULT) \
\COLUMN_DEFAULT \
\FROM INFORMATION_SCHEMA.COLUMNS \
\WHERE TABLE_SCHEMA = ? \
\AND TABLE_NAME = ? \
Expand Down Expand Up @@ -713,10 +713,12 @@ findAlters tblName allDefs col@(Column name isNull type_ def _defConstraintName
modType | showSqlType type_ maxLen False `ciEquals` showSqlType type_' maxLen' False && isNull == isNull' = []
| otherwise = [(name, Change col)]
-- Default value
-- Avoid DEFAULT NULL, since it is always unnecessary, and is an error for text/blob fields
modDef | def == def' = []
| otherwise = case def of
Nothing -> [(name, NoDefault)]
Just s -> [(name, Default $ T.unpack s)]
Just s -> if T.toUpper s == "NULL" then []
else [(name, Default $ T.unpack s)]
in ( refDrop ++ modType ++ modDef ++ refAdd
, filter ((name /=) . cName) cols )

Expand All @@ -737,7 +739,9 @@ showColumn (Column n nu t def _defConstraintName maxLen ref) = concat
, if nu then "NULL" else "NOT NULL"
, case def of
Nothing -> ""
Just s -> " DEFAULT " ++ T.unpack s
Just s -> -- Avoid DEFAULT NULL, since it is always unnecessary, and is an error for text/blob fields
if T.toUpper s == "NULL" then ""
else " DEFAULT " ++ T.unpack s
, case ref of
Nothing -> ""
Just (s, _) -> " REFERENCES " ++ escapeDBName s
Expand Down Expand Up @@ -1081,6 +1085,6 @@ mockMigration mig = do
connLogFunc = undefined,
connUpsertSql = undefined,
connMaxParams = Nothing}
result = runReaderT . runWriterT . runWriterT $ mig
result = runReaderT . runWriterT . runWriterT $ mig
resp <- result sqlbackend
mapM_ T.putStrLn $ map snd $ snd resp
2 changes: 1 addition & 1 deletion persistent-mysql-haskell/persistent-mysql-haskell.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: persistent-mysql-haskell
version: 0.3.2.0
version: 0.3.2.1
license: MIT
license-file: LICENSE
author: Naushadh <naushadh@protonmail.com>, Felipe Lessa <felipe.lessa@gmail.com>, Michael Snoyman
Expand Down

0 comments on commit 33bd9e0

Please sign in to comment.