graphile / migrate

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

"Include" comment #163

Closed benjie closed 10 months ago

benjie commented 2 years ago

Feature description

We already have --! no-transaction special comment, and we have :PLACEHOLDER replacement... This feature would replace a --! include funcs/my_func.sql comment with the contents of the funcs/my_func.sql file from the migrations/ folder. This is akin to symlinking the file into the current/ directory, but with the following advantages:

  1. works on Windows :wink:
  2. works with current.sql in addition to current/ folder
  3. easier to view history in git
  4. no need to come up with a numeric prefix for it - can just reorder as text

On commit a snapshot of the file will be included into the migrations/committed/ entry (and this is the code that would run on graphile-migrate migrate, rather than performing the --! include at that time).

Motivating example

Iterating functions, policies, and other stateless resources can be annoying - having to copy the definitions out from a previous migration or from a DB dump and then edit them. Also tracking history of them is a pain. Easier to edit them in one place (like regular code) and then "pull" them into the migration for execution.

Breaking changes

None.

kaushalyap commented 1 year ago

easier to view history in git no need to come up with a numeric prefix for it - can just reorder as text

These are really beneficial, any plans for adding them?

benjie commented 1 year ago

Yep, have filed #163 to track the idea for when I (or someone else) have time to implement it.

jnbarlow commented 11 months ago

I was just looking for a way to pull this off, this is exciting :)

jnbarlow commented 9 months ago

@benjie quick question... when do you plan on pushing the next release.... I may be asking selfishly :)

benjie commented 9 months ago

This is already available as graphile-migrate@next:

https://www.npmjs.com/package/graphile-migrate?activeTab=versions