graphile / migrate

Opinionated SQL-powered productive roll-forward migration tool for PostgreSQL.
MIT License
751 stars 58 forks source link

Placeholder -> Mustache/handlebars template? #182

Closed tonyxiao closed 1 year ago

tonyxiao commented 1 year ago

I often find myself repeating statements when writing raw sql. For example creating 3 different tables with extremely similar structure & permissions. Given that graphile already has the concept of placeholders, I wonder if it makes sense to implement actual templating using something like handlebars so one could do things like loops to further reduce duplication in sql

benjie commented 1 year ago

This will never be a feature of Graphile Migrate itself, but you could absolutely write queries into the migration folder based on some preprocessing you do elsewhere 👍

Note that the placeholders are designed to be compatible with psql and are specifically there to handle things like roles/schema names and not much else.

tonyxiao commented 1 year ago

Is it possible hook into the compile step of graphile migrate itself? I saw there seems to be an option in gmrc

benjie commented 1 year ago

No; but at some point I'll be replacing .gmrc.js with a graphile.config.js using the standard Graphile config package that I've built for PostGraphile V5 et al, and this will bring with it new capabilities such as plugins and what not that would allow for you to write a plugin to do this.

benjie commented 1 year ago

https://www.npmjs.com/package/graphile-config/v/0.0.1-alpha.1