circuithub / rel8

Hey! Hey! Can u rel8?
https://rel8.readthedocs.io
Other
150 stars 38 forks source link

[Feature Request] Generate tests that can check against an actual postgres schema #274

Open JonathanLorimer opened 10 months ago

JonathanLorimer commented 10 months ago

It would be really nice to be able to be able to generate a test suite that will connect to a local postgres instance and verify that all TableSchema types match the postgres database's schema.

I am imagining that you would register each table schema in a list and maybe provide a pg connection string or something, and then the tests would be generated.

I am happy to help implement this, but I would definitely need lots of direction.

KaneTW commented 7 months ago

This would be immensely helpful, as it's very easy to make a mistake when writing the Haskell types.

KaneTW commented 7 months ago

Quick and dirty poc https://gist.github.com/KaneTW/0f321b6ccf0143611c43e2d087e939d3

Basically checks if the types match (i.e. bidirectional casts exists, so varchar and text match, but int8 and int2 don't), all non-nullables are present, and the hs ty has no extraneous types.

vst commented 2 months ago

Quick and dirty poc https://gist.github.com/KaneTW/0f321b6ccf0143611c43e2d087e939d3

Thanks a ton! This was super helpful.

If only #291 would become a reality. I had to fork Rel8 like you apparently did.

KaneTW commented 2 months ago

Glad this helped. Here's an updated version that I ended up using with more detailed error handling (and some other changes that I don't remember): https://gist.github.com/KaneTW/c223d4da042f5d66e41ee27a46bcefc5

And a way to extract the schemas using the GHC API (at least as of writing that code half a year ago, this was not possible with any other method). Can also list them manually, but I found that too error-prone. https://gist.github.com/KaneTW/d8c897a86a7e6049e607f5c4246d677e

Runs like this: https://gist.github.com/KaneTW/586cd308736803efeca37fa6cb59f2d0

vst commented 2 months ago

That's getting better :smiley: Thanks!