Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear how to implement models in separate modules when porting 2.11 to 2.14 #1445

Closed
merijn opened this issue Dec 2, 2022 · 2 comments · Fixed by #1446
Closed

Unclear how to implement models in separate modules when porting 2.11 to 2.14 #1445

merijn opened this issue Dec 2, 2022 · 2 comments · Fixed by #1446

Comments

@merijn
Copy link
Contributor

merijn commented Dec 2, 2022

I'm trying to migrate my code to the latest version of persistent, so I can support GHC 9.x, however I'm running into some issues with the API changes and it's unclear how to do the same in the new API.

Essentially, I was using independent definition in separate files for my various entities and then in the end using embedEntityDefs and migrate to fix up the foreign keys (see https://github.com/merijn/Belewitte/blob/master/benchmark-analysis/src/Schema/Utils.hs#L54-L57).

With the new persistent interface I get stuck, embedEntityDefs now expected UnboundEntityDef arguments, but the output of the mkPersist quasi quoter gives me a regular EntityDef. I think I'm supposed to use mkPersistWith to manually pass in the entities I depend on, but this is unclear since the documetation for it is missing (see #1439).

I tried taking this approach of manually passing in the EntityDef I depend on at each invocation of mkPersistWith, but this doesn't seem to work. In my 2.14 branch (https://github.com/merijn/Belewitte/compare/persistent) I explicitly pass in all needed entities to mkPersistWith, but somehow migrateModels or something else does not seem to correctly get all the foreign references, as actually using this code throws away every single foreign reference in my
database, which is rather inconvenient to say the least...

So I'm just kinda lost on how to "properly" have my models split across modules in the 2.14 world.

@parsonsmatt
Copy link
Collaborator

The easiest thing to do is probably mkPersistWith $(discoverEntities) [persistLowerCase| ... |]

Then you don't have to worry about providing definition lists and keeping them up to date

I am curious if the qualified name is maybe breaking the foreign key discovery logic, too

@parsonsmatt
Copy link
Collaborator

Yeah, the qualified names are throwing it for a loop. Tracking in #1446

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants