ThomWright / postgres-migrations

🐦 A Stack Overflow-inspired PostgreSQL migration library with strict ordering and immutable migrations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Manage functions as standalone files

Craigfis opened this issue · comments

I'd like to be able to define my SQL functions in standalone files so that when I make changes to them they can be diffed against their previous versions. Currently I have to script dropping and recreating the function in a new migration, giving no easy way of seeing what the actual changes are via a diff.
If I could instead reference a function file in my migration I'd get the diff ability and the ability to have it automatically applied by the migration. (The hash for the migration should include hashing the contents of the referenced file.)

e.g. something like
9_ChangeMyFunc.sql:

-- Apply updated version of function
!include ./funcs/my_function.sql

Where funcs/my_function.sql contains:

drop function my_function(IN param number);
create function my_function(IN param number, IN param2 text)
as $BODY$
  select param, param2
$BODY$;

Hi, thanks for the issue. I think this is effectively a duplicate of #27, but with functions as a use case, not just views.

It's something I should consider supporting, I just haven't had the time/energy to put much thought into it.

So, @ThomWright, no thoughts on how you'd like to see this support implemented?