3

Using postgresql functions is convenient, but keeping them updated is rather difficult. Ideally one would want to keep this separate from database migrations (possibly up to some version constraint mechanism in the migrations), and be able to work collaboratively on a repository for your postgres functions that the database is synced to.

Is there any tool to do this and work on functions in a git repository instead of basically writing a migration script for every change?

saolof
  • 1,097
  • 1
  • 15
  • 12
  • 1
    "*Ideally one would want to keep this separate from database migrations*" - why? Ideally those should be **included** in the database migrations. –  May 03 '22 at 11:45
  • 1
    @a_horse_with_no_name They should be included in the sense that revisions should know which versions are compatible with which revisions. But functions are stateless so it makes no sense to use migrations for adding convenience functions, or for internal performance improvements that make no significant difference. Most of the software world just has packages that act as black boxes and can be upgraded independently of each other, subject to compatibility constraints. – saolof May 03 '22 at 11:50
  • 1
    Well, a specific version of a function belongs to a specific version of your application and the corresponding data model and thus the corresponding migration (version). Of course the function has to be included in the regular migrations. Smart migration tools will simply not re-run the CREATE FUNCTION statement if the function hasn't changed since the last deployment. –  May 03 '22 at 11:54
  • 1
    I use [Sqitch](https://sqitch.org/) for all my schema change needs. You could use it to just track functions. – Adrian Klaver May 03 '22 at 15:06

0 Answers0