Creating Ecto schema from single file (like Laravel Blueprint)

I’ve recently taken a foray into Laravel to understand some of the DX, and specifically what aspects of it could improve my velocity.

One huge win (IMO) is the blueprint package that isn’t part of core Laravel, but is widely used. It allows a set of models to be sketched in a single file (specifying relationships, etc.) in a very succinct way, and also to build out all the models with a single command on the CLI. Even more importantly, there’s a single command to erase the previous iteration of models, update the sketch and rebuild, then migrate and (optionally) seed the database with some fake data.

Comparing this to issuing individual commands via CLI to scaffold out a model, then going into individual model files to remind myself what columns / models I added when trying to iterate quickly is much more difficult. Obviously the end result is very similar, but the individual scaffolding requires a lot more back-and-forth, and many more commands with each iteration.

So, simple question: is there an Ecto equivalent to Blueprint, or a way to achieve a similar effect where I can sketch out models and try it out / roll back as needed?

A slight aside, this also works amazingly well with the Filament package, which introspects the database and generates controllers and views for a CRUD page with a single command. This is very, very handy for checking that relationships defined in the model sketch work as intended.

Would love to know thoughts of the community, since this is probably the main area where I saw a huge difference in how quickly I could build something meaningful.

It shouldn’t be too difficult to read a YAML and generate schemas dynamically in Elixir, but I don’t know about keeping all the rest in sync.

But It’s definitely doable, and although the mental model around schemas and models is different, I think it should be fine for a prototyping tool. I think if Ecto had support for declarative migrations like Prisma or Atlas we would be halfway into the solution.

IMO, the Laravel ecosystem is a great example of the direction to go for improving DX, we need initiates like this so much, thanks for sharing!

1 Like

Thanks for the reply, and for clarity the Laravel tool is very much for rapid prototyping - it doesn’t seek to keep the blueprint in sync once the models etc. are generated (and indeed it’ll overwrite changes made to the models and migrations when you re-run the build commands). They even recommend adding the blueprint to .gitignore which probably demonstrates that it’s only for initial scaffolding, but nonetheless it helps massively with the initial domain modelling piece.

I’m looking into Ash framework, which doesn’t have the single file modelling option but does do quite a bit of the generation and heavy lifting - may try to put a yaml file option together for that