yesodweb / yesod-scaffold

The Yesod scaffolding, with branches for different versions.
MIT License
76 stars 39 forks source link

[WIP] Trying to get postgres scaffold work with latest persistent #211

Closed schoettl closed 2 years ago

schoettl commented 2 years ago

Fixes #210

Thanks for your help @snoyberg and @parsonsmatt!

Now that I tried the current scaffold from scratch, I found that it works because persistent-postgresql have correct bounds in package.yml (<2.11). Maybe I just apply this bounds in my projects, too.

I still created this PR as a basis for a future upgrade to a newer version of persistent. Hope that helps.

parsonsmatt commented 2 years ago

You'll need to update the version bounds here, too - that function was introduced after 2.11.

You could use CPP to work across persistent versions, but I'd rather have folks on newer versions 😄

schoettl commented 2 years ago

So you say we better upgrade sooner than later?

Then, I'll need to change version boundaries to >= 2.13 && < 3?

schoettl commented 2 years ago

yesod-form also advanced to 1.7.3 which I use and maybe that was the reason for stack resolving to use the incompatible persistent version.....

schoettl commented 2 years ago

The next problem when I try to upgrade to a newer persistent version is this error:

/home/jakob/projects/yesod-scaffold/test/TestImport.hs:60:48: error:
    • Couldn't match expected type ‘Text’
                  with actual type ‘Database.Persist.SqlBackend.Internal.SqlBackend’
    • In the first argument of ‘getEscapedRawName’, namely ‘sqlBackend’
      In the first argument of ‘map’, namely
        ‘(getEscapedRawName sqlBackend)’
      In the expression: map (getEscapedRawName sqlBackend) tables
   |        
60 |     let escapedTables = map (getEscapedRawName sqlBackend) tables
   |                                                ^^^^^^^^^^

I can't find ask in the ChangeLog nor in Hoogle. How can I find out where it comes from and how to replace it? Oh, I finally found it in classy-prelude. But I'm afraid I don't understand the problem.

parsonsmatt commented 2 years ago

oh, i have the arguments backward, do a flip or operator section or maybe getEscapedRawNameFunction which will do m (Text -> Text) and specialize to SqlBackend -> Text -> Text

schoettl commented 2 years ago

Thanks @parsonsmatt, now I got it, too. Alright, I pushed a version that seems to work.

stack test and build are working.

I only slightly changed the package version boundaries to make resolver lts-19.29 and lts-19.30 happy.

Should we merge that into postgres branch? And other branches are rebased on that? (Haven't read the complete README yet.)

snoyberg commented 2 years ago

This now has a bunch of name shadowing warnings, anyone have thoughts on why that's happening?

[ 1 of 12] Compiling Model

/home/michael/haskell/yesod-scaffold/yesod-scaffold/src/Model.hs:23:1: error: [-Wname-shadowing, -Werror=name-shadowing]
    This binding for ‘commentUserId’ shadows the existing binding
      defined at src/Model.hs:23:1
   |
23 | share [mkPersist sqlSettings, mkMigrate "migrateAll"]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

/home/michael/haskell/yesod-scaffold/yesod-scaffold/src/Model.hs:23:1: error: [-Wname-shadowing, -Werror=name-shadowing]
    This binding for ‘commentMessage’ shadows the existing binding
      defined at src/Model.hs:23:1
   |
23 | share [mkPersist sqlSettings, mkMigrate "migrateAll"]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
schoettl commented 2 years ago

Oh, I missed that – for me it looks like the template function share causes that. But "share" is not mentioned in the ChangeLog. I have no idea.

parsonsmatt commented 2 years ago

It's this fix which is in 2.14.0.2, but not backported to 2.13.

schoettl commented 2 years ago

OK, so it's good for now and should resolve at the next upgrade (as soon a new LTS is available and the bounds on persistent* in package.yml are increased to <2.15)

snoyberg commented 2 years ago

Great, thanks! I've pushed the changes to the stack-templates repo.