Commit 05ddf85
committed
fix(postgres): only honour a search_path that was deliberately set
Honouring current_schema() unconditionally changed behaviour for every Postgres
connection in order to fix the subset that keeps tables outside `public`. That is
the wrong trade, because the risk is not hypothetical: Postgres ships
`search_path = "$user", public` everywhere, RDS and Aurora included, and the
leading "$user" is inert only while no schema matches the connecting role's name.
SHOW search_path; -> "$user", public
SELECT current_schema(); -> public
CREATE SCHEMA postgres; -- named after the connecting role
SELECT current_schema(); -> postgres
Per-tenant layouts, and the per-user pattern the Postgres docs recommend and
which spread after PG15 hardened `public`, make that live. An untouched
connection would then read an empty user schema and report a healthy, empty
brain — the failure this feature exists to fix, inverted. The warning added
earlier makes that visible after the fact; it does not prevent it.
resolveSchema() now reads search_path and current_user alongside
current_schema(), and ignores a schema that was selected by the implicit "$user"
entry: current_schema() equal to current_user while search_path is still exactly
what Postgres ships. Such a connection introspects `public`, bit for bit as
before.
The blast radius is now the connections that asked for this. Nothing changes
unless an operator sets a search_path — `ALTER ROLE … SET search_path`, or the
JDBC currentSchema parameter — which is how the reported warehouse enabled it,
so that case is unaffected.
The check is deliberately narrow: it matches the shipped default exactly. A path
of `"$user", marts` states an intent and is honoured, verified by test.
No new configuration: DatabaseConnection carries no schema field, so a config
route would mean entity, DTO, API and UI. The database-side search_path is
already the opt-in.
Tests: 16/16, covering the implicit "$user" match, a configured path, "$user"
inside a non-default path, and a NULL current_schema().1 parent f63eea0 commit 05ddf85
2 files changed
Lines changed: 115 additions & 6 deletions
File tree
- backend/src
- main/java/com/dbaagent/provider/postgres
- test/java/com/dbaagent/provider/postgres
Lines changed: 50 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
821 | 821 | | |
822 | 822 | | |
823 | 823 | | |
824 | | - | |
825 | | - | |
826 | | - | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
827 | 853 | | |
828 | 854 | | |
829 | 855 | | |
830 | | - | |
| 856 | + | |
| 857 | + | |
831 | 858 | | |
832 | 859 | | |
833 | | - | |
834 | | - | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
835 | 868 | | |
| 869 | + | |
836 | 870 | | |
837 | 871 | | |
838 | 872 | | |
| |||
841 | 875 | | |
842 | 876 | | |
843 | 877 | | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
844 | 888 | | |
845 | 889 | | |
846 | 890 | | |
| |||
Lines changed: 65 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
62 | 65 | | |
| 66 | + | |
| 67 | + | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
| |||
198 | 203 | | |
199 | 204 | | |
200 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
201 | 266 | | |
202 | 267 | | |
203 | 268 | | |
| |||
0 commit comments