2 ms·
I’ve been using this pattern recently. Very early stages but I like it so far. I wrote some boilerplate tools for easily loading schemata and extensions. This
by chatmasta 7y ago
I’ve been using this pattern recently. Very early stages but I like it so far.
I wrote some boilerplate tools for easily loading schemata and extensions. This is a must have for being able to write isolated tests.
I keep all data definitions in schemata, which can be managed by standard migration scripts. I keep function definitions in extensions, which do not create any data stores but expose functions with well defined interfaces for querying the underlying data. I rely on standard Postgres extension loading to manage migrations.
I really like this pattern, but there is a degree of unapproachability to it. It takes a lot of effort to make sure tests work well - but it’s not so bad. Since your DB functions do everything, the app code is just a shell around those functions (few lines of code to call each function), so by testing those functions you are exercising their Postgres counterparts.
With tools like postgraphile and Postgrest available, this is becoming a more appealing option. What we need is more tooling for managing deployment, installation, migration, verification of and communication with the stored procedures from within application code. Combined with Postgres PL libraries like plv8, it should be possible to write JavaScript code within your application toolchain that you can test locally, but deploy to run in Postgres context.