Fork me on GitHub

simple enough idea, but I did get it from you 🙂

Drew Verlee20:01:38

Has anyone seen any attempts to turn a postgres schema into a set of clojure specs so you can generate data like whats in the database? Or vise versa, fill the database with data? In the case where your using postgres or a relational db, would that be helpful?


@drewverlee at one point I did the same thing with a Datomic schema. It was probably simpler because of the natural Datomic/Clojure match, but I'd definitely think you could do the same with a relational DB. You might want to think about what you'd want the specs to capture -- type is the obvious low-hanging fruit, but there might be other stuff. And you could probably capture the set of fields present in each table with s/keys. Possibly other stuff depending on your particular schema, but in my experience worth considering well in advance of taking on the conversion.

Drew Verlee21:01:04

@eggsyntax i’m thinking either this sort of thing already exists (maybe in another language) or there are really good reasons why its not useful. But maybe clojure spec opens some new doors.


it doesn’t take care of traversing the schema, but you can run your data through this to get specs out of them:


(my project btw, so I’m here for questions)

Alex Miller (Clojure team)22:01:45

I’m pretty sure someone has probably done this already for jdbc based on your databasemetadata, and maybe that’s 90% of the work

Alex Miller (Clojure team)22:01:26

don’t think I’ve seen it specifically with spec though