Skip to content

Fix multiple fk issue with PostgreSQL migrations - #1010

Merged
MaxGabriel merged 5 commits into
yesodweb:masterfrom
robbassi:fix-migration-multiple-fk
Jan 11, 2020
Merged

MaxGabriel merged 5 commits into
yesodweb:masterfrom
robbassi:fix-migration-multiple-fk

Conversation

@robbassi

@robbassi robbassi commented Jan 8, 2020 •

Copy link
Copy Markdown
Contributor

This PR addresses issue #1009 for the PostgreSQL backend. In order to support multiple foreign keys on a single column, we now pass the reference name to getColumn, and use it in the where clause when querying foreign keys for the column.

Before submitting your PR, check that you've:

  • Bumped the version number

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

refMap = Map.fromList $ foldl ref [] cols
where ref rs c = case cReference c of
Nothing -> rs
(Just r) -> (unDBName $ cName c, r) : rs

@robbassi robbassi Jan 8, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we build a map of column names to foreign keys, so we can pass that on to getColumn.

,"AND kcu.table_name=? "
,"AND kcu.column_name=?"]
,"AND kcu.column_name=? "
,"AND tc.constraint_name=?"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now use the reference name to filter the query.

@robbassi

robbassi commented Jan 8, 2020

Copy link
Copy Markdown
Contributor Author

Tests seem to be failing for persistent-mongoDB, doesn't seem related to the changes in this PR though.

@MaxGabriel

Copy link
Copy Markdown
Member

Looks like newer versions of the mongoDB dependency use MonadFail https://hackage.haskell.org/package/mongoDB-2.6.0.0/changelog

@parsonsmatt

Copy link
Copy Markdown
Collaborator

Try merging master - there's an upper bound in place to prevent the cabal solver from picking that version.

@robbassi
robbassi force-pushed the fix-migration-multiple-fk branch from 06fceec to feb00e6 Compare January 10, 2020 16:46
@robbassi

Copy link
Copy Markdown
Contributor Author

@parsonsmatt thanks!

@parsonsmatt parsonsmatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me. Thanks!

, T.unpack (unDBName cname)
, " but got: "
, show xs
]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ great error message!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one is all @MaxGabriel

@MaxGabriel
MaxGabriel merged commit c75890b into yesodweb:master Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants