Skip to content

Commit 398cda7

Browse files
committed
Align test and staging databases with their Terraform stacks (#172 follow-up)
infra/terraform-test and infra/terraform-staging create te_test and te_staging for server admin pgadmin, while the deployer built te_mgmt_test and te_mgmt_staging owned by postgres: the same three-way disagreement #172 fixed for prod. They are code only (#31), so nothing was deployed; this lands before #31 resumes. - env_test/env_staging.example.sql: db_name te_test/te_staging, db_owner pgadmin. deploy_all.sh already reads both from the launcher. - infra/terraform-test, -staging: Key Vault secret and job wiring for APP_USER_PASSWORD, as for prod (entrypoint.sh refuses to deploy without it). - CI creates te_test, te_staging and te_prod owned by pgadmin, dev by postgres. - Consumers of the old names follow: evals Tier E, parity and env tests, run_tests.sh, config examples, provisioning script, README, docs. - tests/test_prod_db_naming.py becomes tests/test_azure_db_naming.py and its static checks run for prod, test and staging, so one test covers every stack. Dev stays te_mgmt_dev / postgres and is pinned as unchanged. - Decision record extended. Stacked on #172: it needs the launcher-driven deployer and the runtime launcher generation from that change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011T6WqjTEDRRQGLEYPPFVXx
1 parent 5c9b930 commit 398cda7

18 files changed

Lines changed: 189 additions & 72 deletions

File tree

‎.github/workflows/quality-gate.yml‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ jobs:
113113
PG_SUPERUSER_PASSWORD="postgres"
114114
PG_DB_DEV="te_mgmt_dev"
115115
PG_SCHEMA_DEV="te_dev"
116-
PG_DB_TEST="te_mgmt_test"
116+
PG_DB_TEST="te_test"
117117
PG_SCHEMA_TEST="te_test"
118-
PG_DB_STAGING="te_mgmt_staging"
118+
PG_DB_STAGING="te_staging"
119119
PG_SCHEMA_STAGING="te_staging"
120120
PG_DB_PROD="te_prod"
121121
PG_SCHEMA_PROD="te_prod"
@@ -133,14 +133,15 @@ jobs:
133133
done
134134
ls -1 build/environments/
135135
136-
# Prod's database is te_prod owned by pgadmin, as in Azure (#172); the
137-
# others are te_mgmt_<env> owned by postgres. The owners must match each
138-
# build/environments/env_<env>.example.sql, or deploy_all.sh warns.
136+
# Test, staging and prod databases are named and owned as in Azure
137+
# (te_<env>, owner pgadmin; #172); dev stays te_mgmt_dev owned by postgres.
138+
# The owners must match each build/environments/env_<env>.example.sql, or
139+
# deploy_all.sh warns.
139140
- name: Create environment databases
140141
run: |
141142
psql -v ON_ERROR_STOP=1 -d postgres -c "CREATE ROLE pgadmin NOLOGIN"
142-
for db in te_mgmt_dev te_mgmt_test te_mgmt_staging te_prod; do
143-
owner=postgres; [ "$db" = te_prod ] && owner=pgadmin
143+
for db in te_mgmt_dev te_test te_staging te_prod; do
144+
owner=pgadmin; [ "$db" = te_mgmt_dev ] && owner=postgres
144145
if [ -z "$(psql -d postgres -tA -c "SELECT 1 FROM pg_database WHERE datname = '$db'")" ]; then
145146
psql -v ON_ERROR_STOP=1 -d postgres -c \
146147
"CREATE DATABASE \"$db\" WITH OWNER = $owner ENCODING = 'UTF8' TEMPLATE = template0 CONNECTION LIMIT = -1"

‎DECISIONS/2026-11-09-prod-db-naming.md‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Decision: Production database is `te_prod`, owned by `pgadmin`
1+
# Decision: Azure databases are `te_<env>`, owned by `pgadmin`
22

33
Status: Decided and applied
44
Date: 2026-11-09
@@ -10,6 +10,10 @@ The production database is **`te_prod`** and its owner is **`pgadmin`**, in all
1010
artefacts that describe it: `infra/terraform-prod/main.tf`, `build/deploy_all.sh` and
1111
`infra/entrypoint.sh`. Option (a) of #172. The schema inside it stays `te_prod`.
1212

13+
**Extended to test and staging (9 Nov 2026, same day):** `te_test` and `te_staging`, also
14+
owned by `pgadmin`, matching `infra/terraform-test` and `infra/terraform-staging`. Dev
15+
stays `te_mgmt_dev` owned by `postgres`: it is local-only and has no stack.
16+
1317
`build/environments/env_prod.example.sql` is the single place that states the name and
1418
owner (`db_name`, `db_owner`). The deployer reads them from the launcher it is about to
1519
run instead of keeping its own copy.
@@ -36,8 +40,9 @@ canonical name on 9 Nov 2026.
3640

3741
## Trade-offs accepted
3842

39-
- Prod now differs from dev, test and staging (`te_mgmt_<env>`, owner `postgres`). The
40-
reading code does not care; the asymmetry is in the data.
43+
- The Azure environments (`te_<env>`, owner `pgadmin`) now differ from dev
44+
(`te_mgmt_dev`, owner `postgres`). The reading code does not care; the asymmetry is in
45+
the data, and it is the difference between a local database and a managed one.
4146
- Where `pgadmin` does not exist (CI, a dev server, the offline install), `deploy_all.sh`
4247
creates it as `NOLOGIN`. It owns the database and nothing else, so it adds no credential,
4348
but a stray role appears on those servers.
@@ -47,14 +52,16 @@ canonical name on 9 Nov 2026.
4752
- `deploy` now requires `APP_USER_PASSWORD`. Without it the application role would be
4853
created with the template's placeholder password.
4954

50-
## Not decided here
55+
## Test and staging
5156

52-
`infra/terraform-test` and `infra/terraform-staging` create `te_test` and `te_staging`,
53-
while the deployer builds `te_mgmt_test` and `te_mgmt_staging`: the same disagreement.
54-
Those stacks are code only (#31). Settle their names before #31 resumes.
57+
`infra/terraform-test` and `infra/terraform-staging` already created `te_test` and
58+
`te_staging`, while the deployer built `te_mgmt_test` and `te_mgmt_staging`: the same
59+
disagreement as prod. Those stacks are code only (#31), so nothing was deployed. They are
60+
aligned now, before #31 resumes, with the same launcher-driven deployer and the same
61+
`APP_USER_PASSWORD` wiring as prod.
5562

5663
## Reopen trigger
5764

58-
Reconsider if test and staging are given the Azure-style names (then prod no longer
59-
stands apart and the `te_mgmt_` prefix may be dropped everywhere), or if the application
60-
is ever to run as a role other than the database owner in Azure.
65+
Reconsider if dev is given an Azure stack (then it should follow `te_dev`/`pgadmin` and the
66+
`te_mgmt_` prefix can go), or if the application is ever to run as a role other than the
67+
database owner in Azure.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ organisations ──< personnel
332332

333333
| Setting | Dev | Test | Staging | Prod |
334334
|---|---|---|---|---|
335-
| Database | `te_mgmt_dev` | `te_mgmt_test` | `te_mgmt_staging` | `te_prod` |
335+
| Database | `te_mgmt_dev` | `te_test` | `te_staging` | `te_prod` |
336336
| Schema | `te_dev` | `te_test` | `te_staging` | `te_prod` |
337337
| App User | `te_dev_user` | `te_test_user` | `te_stg_user` | `te_prod_user` |
338338
| Connection Limit | 10 | 15 | 25 | 50 |

‎build/config.env.example‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ PG_APP_USER_DEV="te_dev_user"
2626
PG_APP_PASSWORD_DEV=""
2727
PG_CONN_LIMIT_DEV="10"
2828

29-
PG_DB_TEST="te_mgmt_test"
29+
PG_DB_TEST="te_test"
3030
PG_SCHEMA_TEST="te_test"
3131
PG_APP_USER_TEST="te_test_user"
3232
PG_APP_PASSWORD_TEST=""
3333
PG_CONN_LIMIT_TEST="15"
3434

35-
PG_DB_STAGING="te_mgmt_staging"
35+
PG_DB_STAGING="te_staging"
3636
PG_SCHEMA_STAGING="te_staging"
3737
PG_APP_USER_STAGING="te_stg_user"
3838
PG_APP_PASSWORD_STAGING=""

‎build/environments/env_staging.example.sql‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
-- env_staging.example.sql (TEMPLATE - safe to commit; no real secrets)
22
-- Copy to env_staging.sql (gitignored) and fill in, or inject app_password at deploy.
3+
-- db_name and db_owner are read by build/deploy_all.sh and must match infra/terraform-staging
4+
-- (database te_staging, server admin pgadmin). #172; DECISIONS/2026-11-09-prod-db-naming.md.
35
\set env_label STAGING
4-
\set db_name te_mgmt_staging
5-
\set db_owner postgres
6+
\set db_name te_staging
7+
\set db_owner pgadmin
68
\set schema_name te_staging
79
\set app_user te_stg_user
810
\set app_password '__INJECT_AT_DEPLOY__'

‎build/environments/env_test.example.sql‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
-- env_test.example.sql (TEMPLATE - safe to commit; no real secrets)
22
-- Copy to env_test.sql (gitignored) and fill in, or inject app_password at deploy.
3+
-- db_name and db_owner are read by build/deploy_all.sh and must match infra/terraform-test
4+
-- (database te_test, server admin pgadmin). #172; DECISIONS/2026-11-09-prod-db-naming.md.
35
\set env_label TEST
4-
\set db_name te_mgmt_test
5-
\set db_owner postgres
6+
\set db_name te_test
7+
\set db_owner pgadmin
68
\set schema_name te_test
79
\set app_user te_test_user
810
\set app_password '__INJECT_AT_DEPLOY__'

‎docs/DATABASE_ENVIRONMENTS.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ for names: `build/config.env.example` (template) / `build/config.local.env`
1212
| Environment | Database | Schema | App user | Conn limit | Seeded? |
1313
|---|---|---|---|---|---|
1414
| **dev** | `te_mgmt_dev` | `te_dev` | `te_dev_user` | 10 | yes (`SEED_DEV=true`) |
15-
| **test** | `te_mgmt_test` | `te_test` | `te_test_user` | 15 | yes (`SEED_TEST=true`) |
16-
| **staging** | `te_mgmt_staging` | `te_staging` | `te_stg_user` | 25 | no (`SEED_STAGING=false`) |
15+
| **test** | `te_test` | `te_test` | `te_test_user` | 15 | yes (`SEED_TEST=true`) |
16+
| **staging** | `te_staging` | `te_staging` | `te_stg_user` | 25 | no (`SEED_STAGING=false`) |
1717
| **prod** | `te_prod` | `te_prod` | `te_prod_user` | 50 | no (`SEED_PROD=false`) |
1818

1919
The database name and owner come from `build/environments/env_<env>.sql` (`db_name`,
2020
`db_owner`), which `deploy_all.sh` reads; nothing else keeps its own copy. Prod's
21-
database is `te_prod`, owned by `pgadmin`, to match `infra/terraform-prod` (#172;
21+
database is `te_prod`, and test and staging are `te_test` and `te_staging`: each owned
22+
by `pgadmin`, to match its `infra/terraform-<env>` stack (#172;
2223
`DECISIONS/2026-11-09-prod-db-naming.md`). Where `pgadmin` does not exist yet (a dev
2324
server, CI, the offline install) `deploy_all.sh` creates it `NOLOGIN`: it owns the
24-
database and nothing else. Dev, test and staging keep `te_mgmt_<env>` owned by `postgres`.
25+
database and nothing else. Dev is local-only and keeps `te_mgmt_dev` owned by `postgres`.
2526

2627
Every environment also gets a `csv_uploads` schema in its own database
2728
(same name across environments — no collision, since each environment is a

‎docs/ENV_VARIABLES.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ the environment SQL templates. Copy `build/config.env.example` to
6060

6161
| Variable | Dev | Test | Staging | Prod |
6262
|---|---|---|---|---|
63-
| `PG_DB_*` | `te_mgmt_dev` | `te_mgmt_test` | `te_mgmt_staging` | `te_prod` |
63+
| `PG_DB_*` | `te_mgmt_dev` | `te_test` | `te_staging` | `te_prod` |
6464
| `PG_SCHEMA_*` | `te_dev` | `te_test` | `te_staging` | `te_prod` |
6565
| `PG_APP_USER_*` | `te_dev_user` | `te_test_user` | `te_stg_user` | `te_prod_user` |
6666
| `PG_APP_PASSWORD_*` | _(empty)_ | _(empty)_ | _(empty)_ | _(empty)_ |

‎evals/runner.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ def _run_fresh_deploy_then_tests(
557557

558558
ENV_TARGETS = [
559559
("dev", "te_mgmt_dev", "te_dev"),
560-
("test", "te_mgmt_test", "te_test"),
561-
("staging", "te_mgmt_staging", "te_staging"),
560+
("test", "te_test", "te_test"),
561+
("staging", "te_staging", "te_staging"),
562562
("prod", "te_prod", "te_prod"),
563563
]
564564

‎infra/terraform-prod/main.tf‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ resource "azurerm_postgresql_flexible_server" "pg" {
295295
# The production database. Its name and the server admin ("pgadmin", the job's
296296
# PGUSER and the database owner) must equal db_name and db_owner in
297297
# build/environments/env_prod.example.sql: that file is what build/deploy_all.sh
298-
# reads. tests/test_prod_db_naming.py fails if they drift (RV-S1, #172;
298+
# reads. tests/test_azure_db_naming.py fails if they drift (RV-S1, #172;
299299
# DECISIONS/2026-11-09-prod-db-naming.md).
300300
resource "azurerm_postgresql_flexible_server_database" "te_prod" {
301301
name = "te_prod"

0 commit comments

Comments
 (0)