feat(db-tool): hectic-inheritance: bootstrap hectic.created_at / hectic.updated_at inheritance hook
Adds a SQL bundle plus event triggers that enforce `INHERITS (hectic.created_at)`
on every user CREATE TABLE and auto-attach a BEFORE UPDATE row trigger when a
table inherits `hectic.updated_at`. Always-exempt: `hectic`, `information_schema`,
`pg_*`, declarative partitions, temp tables. Per-DB opt-out via the GUC
`hectic.inheritance_extra_excluded_schemas`.
Exposed three ways:
* `pkgs.hectic.hectic-inheritance` — derivation with the SQL at
$out/share/hectic/hectic-inheritance.sql
* `self.lib.hecticInheritance.{sql,path}` — pkgs-free Nix surface
* `postgres-init` opt-in via `PG_HECTIC_INHERITANCE=1` (HECTIC_INHERITANCE_SQL
overrides the default)
Test postgres-init-hectic-inheritance covers all six branches: bootstrap,
non-inheriting reject, accepting inheritance, auto updated_at trigger fires,
GUC exclusion, declarative partition exemption.
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
{ dash, hectic, postgresql_17, neovim, openssh, coreutils, gawk, lib }:
|
||||
{ dash, hectic, postgresql_17, neovim, openssh, coreutils, gawk, lib, runCommand }:
|
||||
let
|
||||
shell = "${dash}/bin/dash";
|
||||
|
||||
hecticInheritanceSqlPath = ./sql/hectic-inheritance.sql;
|
||||
|
||||
hecticInheritance = runCommand "hectic-inheritance" { } ''
|
||||
mkdir -p "$out/share/hectic"
|
||||
cp ${hecticInheritanceSqlPath} "$out/share/hectic/hectic-inheritance.sql"
|
||||
'';
|
||||
|
||||
mkDatabase =
|
||||
{ postgresql ? postgresql_17 }:
|
||||
hectic.writeShellApplication {
|
||||
@@ -37,7 +44,11 @@ let
|
||||
name = "postgres-init";
|
||||
runtimeInputs = [ postgresql coreutils ];
|
||||
|
||||
text = builtins.readFile ./postgres-init.sh;
|
||||
text = ''
|
||||
HECTIC_INHERITANCE_SQL_DEFAULT="${hecticInheritance}/share/hectic/hectic-inheritance.sql"
|
||||
export HECTIC_INHERITANCE_SQL_DEFAULT
|
||||
${builtins.readFile ./postgres-init.sh}
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "Initialize local PostgreSQL instance";
|
||||
@@ -62,7 +73,8 @@ let
|
||||
};
|
||||
in
|
||||
{
|
||||
"db-tool" = lib.makeOverridable mkDatabase { };
|
||||
"postgres-init" = lib.makeOverridable mkPostgresInit { };
|
||||
"postgres-cleanup" = lib.makeOverridable mkPostgresCleanup { };
|
||||
"db-tool" = lib.makeOverridable mkDatabase { };
|
||||
"postgres-init" = lib.makeOverridable mkPostgresInit { };
|
||||
"postgres-cleanup" = lib.makeOverridable mkPostgresCleanup { };
|
||||
"hectic-inheritance" = hecticInheritance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user