local-development-gateway 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -28
  3. data/docker-compose.yml +19 -20
  4. data/docs/README.md +16 -0
  5. data/docs/architecture/gateway-lifecycle.md +39 -0
  6. data/docs/guides/consumer-developer-examples.md +369 -0
  7. data/docs/guides/docker-first-migration.md +180 -0
  8. data/docs/guides/docker-installation.md +84 -0
  9. data/docs/requirements/effective-gateway.md +37 -0
  10. data/examples/shared-databases/README.md +145 -0
  11. data/examples/shared-databases/app/.omp-verifier.json +10 -0
  12. data/examples/shared-databases/app/.oxlintrc.json +3 -0
  13. data/examples/shared-databases/app/Dockerfile +12 -0
  14. data/examples/shared-databases/app/app.mjs +91 -0
  15. data/examples/shared-databases/app/app.test.mjs +67 -0
  16. data/examples/shared-databases/app/database.mjs +31 -0
  17. data/examples/shared-databases/app/migrations/001_notes.cjs +10 -0
  18. data/examples/shared-databases/app/package-lock.json +1705 -0
  19. data/examples/shared-databases/app/package.json +18 -0
  20. data/examples/shared-databases/bin/dev +63 -0
  21. data/examples/shared-databases/bin/provision +24 -0
  22. data/examples/shared-databases/compose.yml +73 -0
  23. data/examples/shared-databases/consumer.yml +64 -0
  24. data/examples/shared-databases/gateway.yml +24 -0
  25. data/examples/shared-databases/provisioning/checkout.sh +12 -0
  26. data/examples/shared-databases/provisioning/postgres/database.sql +16 -0
  27. data/examples/shared-databases/provisioning/postgres/provision.sh +10 -0
  28. data/examples/shared-databases/provisioning/postgres/role.sql +11 -0
  29. data/examples/shared-databases/provisioning/sqlserver/database.sql +34 -0
  30. data/examples/shared-databases/provisioning/sqlserver/login.sql +18 -0
  31. data/examples/shared-databases/provisioning/sqlserver/provision.sh +10 -0
  32. data/lib/local_development_gateway/lifecycle.rb +133 -0
  33. data/lib/local_development_gateway/version.rb +1 -1
  34. data/lib/local_development_gateway.rb +150 -27
  35. metadata +31 -3
  36. data/config/traefik.yml +0 -11
@@ -0,0 +1,369 @@
1
+ # Consumer developer examples
2
+
3
+ These are **adoption designs**, not changes applied to ELCC, WRAP, Travel Authorization, or Traditional Knowledge (TK). They answer: “What would my existing `bin/dev` and development Compose configuration change, and what would I type every day?” Snippets are focused edits to the named owners, not complete replacement files. No consumer tests, restore, registry publication, or installed-gateway replacement is established here.
4
+
5
+ Use the [migration guide](/docs/guides/docker-first-migration.md) for backup, restore, restricted-login provisioning, rollback, and acceptance gates, and [Docker installation](/docs/guides/docker-installation.md) for the coordinated gateway installation. Preserve native engine versions below; the generic example's engines are not substitutes. Never edit production Compose, copy production secrets/data into examples, upgrade an engine implicitly, or remove old volumes during adoption.
6
+
7
+ ## Source identity
8
+
9
+ The snippets adapt these actual, clean local HEADs inspected on 2026-11-17. The migration guide's older ELCC baseline remains historical; the ELCC examples below use its newer actual revision.
10
+
11
+ | Consumer | Actual inspected revision | Main source owners |
12
+ | --- | --- | --- |
13
+ | ELCC | `d2e2a46e3a3e73e2680a4342343a4a28306401b6` | [bin/dev](https://github.com/icefoganalytics/elcc-data-management/blob/d2e2a46e3a3e73e2680a4342343a4a28306401b6/bin/dev), [development Compose](https://github.com/icefoganalytics/elcc-data-management/blob/d2e2a46e3a3e73e2680a4342343a4a28306401b6/docker-compose.development.yaml) |
14
+ | WRAP | `67883eb5612162b8bd67541dfd522148f70e24b1` | [bin/dev](https://github.com/icefoganalytics/wrap/blob/67883eb5612162b8bd67541dfd522148f70e24b1/bin/dev), [development Compose](https://github.com/icefoganalytics/wrap/blob/67883eb5612162b8bd67541dfd522148f70e24b1/docker-compose.development.yml) |
15
+ | Travel | `5966448cb387227fa9d7c51b42da4906d0ccc85d` | [bin/dev](https://github.com/icefoganalytics/travel-authorization/blob/5966448cb387227fa9d7c51b42da4906d0ccc85d/bin/dev), [development Compose](https://github.com/icefoganalytics/travel-authorization/blob/5966448cb387227fa9d7c51b42da4906d0ccc85d/docker-compose.development.yml) |
16
+ | TK | `9699f8ac89d5fc7935c40f95f44c64bfeaf0931f` | [bin/dev](https://github.com/icefoganalytics/traditional-knowledge/blob/9699f8ac89d5fc7935c40f95f44c64bfeaf0931f/bin/dev), [development Compose](https://github.com/icefoganalytics/traditional-knowledge/blob/9699f8ac89d5fc7935c40f95f44c64bfeaf0931f/docker-compose.development.yml) |
17
+
18
+ For additional files named below, use the same repository and pinned revision, not a moving default branch. The inspected ELCC, WRAP, and Travel baselines lock gateway gem 0.2.2; TK locks 0.1.2. Each adoption must update its existing Gemfile/lock to `~> 0.4.0` before using this lifecycle contract. Do not commit a personal source path.
19
+
20
+ ## Shared contract: ordinary app commands, automatic gateway
21
+
22
+ The intended daily behavior is: project `up` makes the shared gateway ready before starting the project; project `down` does not start an absent gateway; the last active consumer's teardown stops gateway **services**, preserving `local-gateway`. Idle shared DB servers remain running but do not retain the gateway. An explicit desktop-client hold does retain it.
23
+
24
+ The existing Ruby integration owns that coordination:
25
+
26
+ ```ruby
27
+ LocalDevelopmentGateway.with_running do
28
+ # Existing project up/run operation; wait for it to finish.
29
+ end
30
+
31
+ LocalDevelopmentGateway.with_running(ensure_running: false) do
32
+ # Existing project down/stop operation; wait for it to finish.
33
+ end
34
+ ```
35
+
36
+ Keep this inside development paths only; preserve each wrapper's existing nondevelopment delegation. Retain the existing module-level `LocalDevelopmentGateway.with_running` calls: updating the bundle selects the coordinated client contract without changing their receivers. Do not wrap it in a second management CLI. In particular, a wrapped `compose` call must use `execution_mode: WAIT_FOR_PROCESS`, not `exec`: replacing Ruby would skip block cleanup. Propagate failed Compose operations; do not report a successful test or teardown from an unchecked `system` result.
37
+
38
+ The client, not downstream Ruby wrappers, owns per-user/per-Docker-daemon coordination: short coordinator file locks serialize lifecycle decisions; pending operations retain their own file locks while project commands execute. A simultaneous `up` must not lose the gateway to another checkout's `down` between readiness and container attachment. Locks are scoped to Docker daemon identity, not merely a checkout directory. Consumer wrappers must not invent lock files, counters, stale PID cleanup, or private gateway ownership.
39
+
40
+ ### Label and network ownership
41
+
42
+ Only an explicit `local-gateway.lifecycle: passive` label exempts a running container from retention. Do not infer passivity from a service name, database image, missing HTTP label, or idle connections. Unknown/legacy attachments conservatively keep the gateway alive. Use `consumer` for active app/job/test containers that need to retain it, including private-network-only consumers; do not mark workers passive just because they have no browser route.
43
+
44
+ A proposed project-owner server file, distinct from every checkout app stack, has this shape (ELCC shown):
45
+
46
+ ```yaml
47
+ name: elcc-shared-db
48
+ services:
49
+ sqlserver:
50
+ image: mcr.microsoft.com/mssql/server:2019-CU28-ubuntu-20.04
51
+ environment:
52
+ ACCEPT_EULA: "Y"
53
+ MSSQL_SA_PASSWORD: "${ELCC_DB_ADMIN_PASSWORD:?local provisioning secret required}"
54
+ volumes:
55
+ - sqlserver-data:/var/opt/mssql/data
56
+ networks:
57
+ project-db:
58
+ aliases: [elcc-sqlserver]
59
+ local-gateway: {}
60
+ labels:
61
+ local-gateway.tcp.hostname: "db.elcc.localhost"
62
+ local-gateway.tcp.driver: "sql_server"
63
+ local-gateway.tcp.port: "1433"
64
+ local-gateway.lifecycle: passive
65
+ networks:
66
+ project-db:
67
+ name: elcc-shared-db
68
+ local-gateway:
69
+ external: true
70
+ name: local-gateway
71
+ volumes:
72
+ sqlserver-data: {}
73
+ ```
74
+
75
+ The project server stack owns its new volume and private `elcc-shared-db` network; the gateway owns `local-gateway`. No database host ports are published. Apps connect directly through private DNS, not through the desktop router. The shared-server labels supply one unique project endpoint per server; they do not grant database permissions. Reuse this ownership shape with WRAP/TK/Travel's exact engines and distinct names, never one cross-project engine. Gateway listeners remain host-loopback only.
76
+
77
+ Checkout Compose declares the private network **external**, retaining its normal checkout `default` network. Put database fields, lifecycle labels, and private network attachments in the base development file, not only `docker-compose.development.gateway.yml`: tests and `run` do not all load that overlay. On services already declaring networks in the gateway overlay, preserve `default` and `local-gateway` and explicitly retain `project-db` in the merged configuration. Keep existing HTTP routes. The database route moves to the project server; remove obsolete checkout DB route stanzas rather than allowing an overlay to recreate a deleted DB service.
78
+
79
+ ### Setup is not the daily loop
80
+
81
+ A project-owner adoption PR first creates its own shared-server Compose/provisioning owners and preserves/backs up old volumes. After the coordinated gateway installation, run `local-development-gateway hold setup` before the first server startup: it ensures gateway readiness and creates the external `local-gateway` network that server Compose requires. Start servers with native Compose and provision restricted development/test databases while that hold remains active. For example, **after creating the proposed file above**, `docker compose -f compose.shared-db.yml up -d sqlserver` starts ELCC's server. Equivalent proposed owners start WRAP's `sqlserver`, TK's `sqlserver`, or Travel's `postgres travcom travelport`. These are design names, not files or commands that already exist in the consumers. When provisioning is finished, run `local-development-gateway release setup`; the passive servers remain running, and idle-stop preserves the network. This initial setup hold is not another step in the daily loop.
82
+
83
+ Per checkout, allocate a stable collision-resistant key (examples use `a7c91`), provision the named databases and distinct dev/test logins administratively, restore development data explicitly, and record connection inputs in ignored local root `.env`/approved local configuration. Do not print credentials or put admin credentials in apps. Compose `${NAME:?message}` inputs below require those local values; no secret values are included. Extend the existing configuration owner rather than adding another shell command for developers to remember. Normal migrations/seeds/test resets remain application-owned, but automatic server-level database creation must become validation of the provisioned target.
84
+
85
+ Server maintenance is separate: checkout `down` neither stops shared databases nor removes their networks/volumes. Gateway idle-stop is also not shared-server teardown. Preserve all old data until native restore and rollback are accepted; new databases do not authorize deleting previous ones.
86
+
87
+ ## 1. ELCC: one SQL Server, two databases per checkout
88
+
89
+ **One-time setup:** retain SQL Server `2019-CU28-ubuntu-20.04`. Provision `elcc_a7c91_dev` and `elcc_a7c91_test` on `elcc-sqlserver`, with different restricted logins/passwords. Use the project-server shape above. ELCC has no observed `bin/dev db --export` implementation: establish the canonical native SQL Server backup/restore procedure before moving data, rather than inventing an export command.
90
+
91
+ **Small existing-wrapper change:** retain `bin/dev#up` and `#down`'s module-level gateway calls, `OpenInEditorBridge.compose` bodies and UID/GID/environment assembly; update the bundle to select version 0.4.0. In `down`, select the same development files as `up` (`compose_file_options(gateway: true, **kwargs)`). Adjust the existing `run` method, which is also used by `test_api`, to wait:
92
+
93
+ ```ruby
94
+ def run(*args, **kwargs)
95
+ LocalDevelopmentGateway.with_running do
96
+ compose(*%w[run --rm], *args, gateway: true,
97
+ execution_mode: WAIT_FOR_PROCESS, **kwargs)
98
+ end
99
+ end
100
+ ```
101
+
102
+ This excerpt is the development branch of `run`; keep nondevelopment delegation outside it. No DB-engine switch, provisioning dispatcher, or new daily CLI belongs in this method.
103
+
104
+ **Base `docker-compose.development.yaml` edits** (merge into existing services; retain unrelated environment keys):
105
+
106
+ ```yaml
107
+ x-checkout-db: &checkout-db
108
+ DB_HOST: elcc-sqlserver
109
+ DB_PORT: "1433"
110
+ DB_NAME: "${ELCC_DEV_DATABASE:?provision checkout database}"
111
+ DB_USER: "${ELCC_DEV_USER:?provision scoped login}"
112
+ DB_PASS: "${ELCC_DEV_PASSWORD:?local secret required}"
113
+ DB_TRUST_SERVER_CERTIFICATE: "true"
114
+ services:
115
+ api:
116
+ environment:
117
+ <<: [*checkout-db, *default-environment]
118
+ networks: [default, project-db]
119
+ labels:
120
+ local-gateway.lifecycle: consumer
121
+ test_api:
122
+ environment:
123
+ <<: [*checkout-db, *default-environment]
124
+ NODE_ENV: test
125
+ DB_NAME: "${ELCC_TEST_DATABASE:?provision test database}"
126
+ DB_USER: "${ELCC_TEST_USER:?provision test login}"
127
+ DB_PASS: "${ELCC_TEST_PASSWORD:?local secret required}"
128
+ networks: [default, project-db]
129
+ labels:
130
+ local-gateway.lifecycle: consumer
131
+ networks:
132
+ project-db:
133
+ external: true
134
+ name: elcc-shared-db
135
+ ```
136
+
137
+ Remove `db` and the API/test dependency edges to it from this file and its obsolete gateway-overlay DB stanza; retain old `db_data`. Keep the optional Linux override, host user behavior, frontend route and editor bridge. Retarget existing `db`/`sqlcmd` helpers away from `exec db`; SQL Server server selection is `-S host,port`, not the current helper's `-H` workstation flag.
138
+
139
+ **Daily, from the adopted ELCC checkout:**
140
+
141
+ ```sh
142
+ ./bin/dev up -d
143
+ ./bin/dev test api -- --run
144
+ ./bin/dev down
145
+ ```
146
+
147
+ `test api` is the real wrapper route to `test_api npm run test`; the `--` separator forwards `--run` to Vitest for a finite invocation. Acceptance must retain normal `api/tests/global-setup.ts` initializers and test seed policy, replace `10-ensure-database.ts`'s server-creation fallback, and prove `api/tests/support/clean-database.ts` only resets the private test database while another checkout retains data. Do not use `--skip-setup` for adoption acceptance.
148
+
149
+ ## 2. WRAP: SQL Server full-text, jobs, and checkout search
150
+
151
+ **One-time setup:** project-owned `wrap-sqlserver` must use the existing `wrap-db:full-text` build from [db.Dockerfile](https://github.com/icefoganalytics/wrap/blob/67883eb5612162b8bd67541dfd522148f70e24b1/db.Dockerfile): SQL Server **2025 CU7 / Ubuntu 24.04** plus `mssql-server-fts`. Provision `wrap_a7c91_dev` / `wrap_a7c91_test` and separate logins. Give the server `local-gateway.tcp.hostname: db.wrap.localhost`, `local-gateway.tcp.driver: sql_server`, `local-gateway.tcp.port: "1433"`, and lifecycle `passive`, attached to project-owned `wrap-shared-db` plus external `local-gateway`.
152
+
153
+ **Small existing-wrapper change:** keep `up`'s `check_development_environment`, Compose flags, `WAIT_FOR_PROCESS`, and existing module-level gateway calls in `up`/`down`; update the bundle to version 0.4.0. Add `gateway: true` to development teardown to match the startup files. In the existing `run`, preserve the web `--no-deps` special case and wrap the final Compose operation:
154
+
155
+ ```ruby
156
+ LocalDevelopmentGateway.with_running do
157
+ compose(*compose_arguments, *args, execution_mode: WAIT_FOR_PROCESS, **kwargs)
158
+ end
159
+ ```
160
+
161
+ This is the development branch only. The existing guard must still run; do not bypass it to pass connection inputs.
162
+
163
+ **Base `docker-compose.development.yml` edits:** introduce a connection anchor and apply it to **both `api` and `jobs`**. Keep `jobs`' `RUN_SCHEDULER`, `APPLICATION_NAME`, and existing resource settings.
164
+
165
+ ```yaml
166
+ x-checkout-db: &checkout-db
167
+ AZURE_SQL_HOST: wrap-sqlserver
168
+ AZURE_SQL_PORT: "1433"
169
+ AZURE_SQL_DATABASE: "${WRAP_DEV_DATABASE:?provision checkout database}"
170
+ AZURE_SQL_USERNAME: "${WRAP_DEV_USER:?provision scoped login}"
171
+ AZURE_SQL_PASSWORD: "${WRAP_DEV_PASSWORD:?local secret required}"
172
+ DB_TRUST_SERVER_CERTIFICATE: "true"
173
+ services:
174
+ api:
175
+ environment:
176
+ <<: [*checkout-db, *default-environment]
177
+ networks: [default, project-db]
178
+ labels:
179
+ local-gateway.lifecycle: consumer
180
+ jobs:
181
+ environment:
182
+ <<: [*checkout-db, *default-environment]
183
+ RUN_SCHEDULER: "true"
184
+ APPLICATION_NAME: Jobs
185
+ networks: [default, project-db]
186
+ labels:
187
+ local-gateway.lifecycle: consumer
188
+ test_api:
189
+ environment:
190
+ <<: [*checkout-db, *default-environment]
191
+ NODE_ENV: test
192
+ AZURE_SQL_DATABASE: "${WRAP_TEST_DATABASE:?provision test database}"
193
+ AZURE_SQL_USERNAME: "${WRAP_TEST_USER:?provision test login}"
194
+ AZURE_SQL_PASSWORD: "${WRAP_TEST_PASSWORD:?local secret required}"
195
+ networks: [default, project-db]
196
+ labels:
197
+ local-gateway.lifecycle: consumer
198
+ networks:
199
+ project-db:
200
+ external: true
201
+ name: wrap-shared-db
202
+ ```
203
+
204
+ Remove checkout `db`, all three DB dependency edges, and its gateway-overlay route; preserve old `db_data`. Keep Redis, mail, Elasticsearch 9.5.2, their dependencies, test profiles and test Redis database unchanged. The environment snippets do not replace the services' other explicit keys.
205
+
206
+ WRAP's [environment guard](https://github.com/icefoganalytics/wrap/blob/67883eb5612162b8bd67541dfd522148f70e24b1/bin/lib/development_environment/command.rb) discovers Compose-owned names and interpolation inputs. Keep the new `WRAP_*` inputs in the root/host configuration, not `api/.env.development`; reconcile its existing policy with private secrets without weakening the guard. Separately reconcile ignored `api/.env.test`: `api/src/config.ts` uses dotenv `override: true`. Assert actual database/principal before setup/reset, not just intended Compose values.
207
+
208
+ **Daily, from the adopted WRAP checkout:**
209
+
210
+ ```sh
211
+ ./bin/dev up -d
212
+ ./bin/dev test api -- --run
213
+ ./bin/dev down
214
+ ```
215
+
216
+ **Adoption-only checks:** run `./bin/dev check-environment`; retain normal initializers; retarget `bin/lib/database/command.rb` export/import and `sqlcmd` to explicit shared destinations. Correct the hard-coded `wrap_development.dbo.workflow_histories` rollback in migration `20250414162002_increase-size-of-workflow-histories-subtitle-field-to-better-support-commenting.ts` before allowing scoped rollback. Full-text remains necessary for historical migration replay/rollback even though current search uses Elasticsearch. `ELASTICSEARCH_INDEX_PREFIX` defaults to the lowercased SQL database name: restore does not migrate search documents, so rebuild/verify each checkout's intended search namespace. See the pinned consumer's `docs/architecture/workflow-search.md` and the migration guide's WRAP gates.
217
+
218
+ ## 3. Travel Authorization: three engine families, six databases
219
+
220
+ **One-time setup:** retain three project-owned servers, not one generalized SQL server:
221
+
222
+ | Proposed service / private DNS / desktop route | Native engine | Provisioned checkout dev / test databases |
223
+ | --- | --- | --- |
224
+ | `postgres` / `travel-postgres` / `db.travel.localhost` | `postgres:14.4` | `travel_a7c91_dev` / `travel_a7c91_test` |
225
+ | `travcom` / `travel-travcom` / `db-trav-com.travel.localhost` | SQL Server `2022-CU14-ubuntu-22.04` | `travcom_a7c91_dev` / `travcom_a7c91_test` |
226
+ | `travelport` / `travel-travelport` / `db-travelport.travel.localhost` | SQL Server `2019-CU28-ubuntu-20.04`, `SQL_Latin1_General_CP1_CI_AS` | `travelport_a7c91_dev` / `travelport_a7c91_test` |
227
+
228
+ All three attach to project-owned `travel-shared-db` and external `local-gateway`, with `passive` lifecycle labels. Set `local-gateway.tcp.hostname` to the table's desktop route and `local-gateway.tcp.driver` / `local-gateway.tcp.port` to `postgresql` / `"5432"` on PostgreSQL and `sql_server` / `"1433"` on each SQL Server endpoint. Use distinct restricted roles for all six databases. The current PostgreSQL `app` bootstrap role and SQL Server `sa` are not the desired app identities. Do not point these local simulators or tests at real production Travelport.
229
+
230
+ **Small existing-wrapper change:** Travel already waits in `run` and `stop` and uses `OpenInEditorBridge.compose` for `up`/`down`. Retain its existing module-level gateway calls and update the bundle to version 0.4.0, preserving `ensure_running: false` in `down`/`stop`, nondevelopment guards, the one-off `traefik.enable=false` label, editor-bridge environment and checkout-name hashing. No receiver changes or additional command dispatch are needed.
231
+
232
+ **Base development Compose edits:** use all five fields of each family, with explicit test overrides. This development anchor shows the complete connection surface:
233
+
234
+ ```yaml
235
+ x-checkout-db: &checkout-db
236
+ DB_HOST: travel-postgres
237
+ DB_PORT: "5432"
238
+ DB_NAME: "${TRAVEL_DEV_DATABASE:?provision checkout database}"
239
+ DB_USER: "${TRAVEL_DEV_USER:?provision scoped role}"
240
+ DB_PASS: "${TRAVEL_DEV_PASSWORD:?local secret required}"
241
+ TRAVCOM_DB_HOST: travel-travcom
242
+ TRAVCOM_DB_PORT: "1433"
243
+ TRAVCOM_DB_NAME: "${TRAVCOM_DEV_DATABASE:?provision checkout database}"
244
+ TRAVCOM_DB_USER: "${TRAVCOM_DEV_USER:?provision scoped login}"
245
+ TRAVCOM_DB_PASS: "${TRAVCOM_DEV_PASSWORD:?local secret required}"
246
+ TRAVCOM_DB_TRUST_SERVER_CERTIFICATE_ENABLED: "true"
247
+ TRAVELPORT_DB_HOST: travel-travelport
248
+ TRAVELPORT_DB_PORT: "1433"
249
+ TRAVELPORT_DB_NAME: "${TRAVELPORT_DEV_DATABASE:?provision checkout database}"
250
+ TRAVELPORT_DB_USER: "${TRAVELPORT_DEV_USER:?provision scoped login}"
251
+ TRAVELPORT_DB_PASS: "${TRAVELPORT_DEV_PASSWORD:?local secret required}"
252
+ TRAVELPORT_DB_TRUST_SERVER_CERTIFICATE_ENABLED: "true"
253
+ ```
254
+
255
+ Merge `<<: [*checkout-db, *default-environment]` into both `api` and `test_api`, attach each to `[default, project-db]`, label each `local-gateway.lifecycle: consumer`, and declare external `project-db` named `travel-shared-db`. In `test_api`, replace all nine database/name/user/password fields explicitly:
256
+
257
+ ```yaml
258
+ NODE_ENV: test
259
+ DB_NAME: "${TRAVEL_TEST_DATABASE:?provision test database}"
260
+ DB_USER: "${TRAVEL_TEST_USER:?provision test role}"
261
+ DB_PASS: "${TRAVEL_TEST_PASSWORD:?local secret required}"
262
+ TRAVCOM_DB_NAME: "${TRAVCOM_TEST_DATABASE:?provision test database}"
263
+ TRAVCOM_DB_USER: "${TRAVCOM_TEST_USER:?provision test login}"
264
+ TRAVCOM_DB_PASS: "${TRAVCOM_TEST_PASSWORD:?local secret required}"
265
+ TRAVELPORT_DB_NAME: "${TRAVELPORT_TEST_DATABASE:?provision test database}"
266
+ TRAVELPORT_DB_USER: "${TRAVELPORT_TEST_USER:?provision test login}"
267
+ TRAVELPORT_DB_PASS: "${TRAVELPORT_TEST_PASSWORD:?local secret required}"
268
+ ```
269
+
270
+ Retain each family's host, port, and local trust settings from the anchor. Remove `db`, `db_trav_com`, `db_travelport`, their app/test dependency edges, and all three gateway-overlay route stanzas. Preserve `db_data`, `db_trav_com_data`, `db_travelport_data`. Private database reachability must not depend on loading the gateway overlay even though Travel's wrapper currently loads it by default.
271
+
272
+ **Daily, from the adopted Travel checkout:**
273
+
274
+ ```sh
275
+ ./bin/dev up -d
276
+ ./bin/dev test api -- --run
277
+ ./bin/dev down
278
+ ```
279
+
280
+ Before this becomes a supported loop, change the PostgreSQL initializer's maintenance-database creation path and both integrations' ensure-database paths to provisioned-target validation. Retarget existing `psql` and PostgreSQL export/import owners; that export does **not** back up either SQL source simulator. Establish native SQL backups separately. Reconcile the development-env-as-test-env mount. Prove actual identities and reset/seed results for all three test databases and untouched neighboring checkout sentinels. The migration guide records swallowed initializer/TravCom cleanup failures: fix those existing owners, not merely the wrapper's exit handling, before treating command success as acceptance.
281
+
282
+ ## 4. Traditional Knowledge: SQL Server plus the archiver writer
283
+
284
+ TK is not just another API/web pair. At the pinned revision its development stack contains `api`, `web`, `api_wait`, `test_api`, `test_web`, Redis `bitnamilegacy/redis:8.0.2`, MailDev `2.2.1`, optional PlantUML, and an **archiver** service. Both API and archiver connect to SQL Server `2022-CU14-ubuntu-22.04`; archiver also depends on Redis. Its DB configuration is consumed by `archiver/src/config.ts` and `archiver/src/db/db-client.ts`. Keep its local certificate mounts and other private configuration outside examples.
285
+
286
+ **One-time setup:** provision `tk_a7c91_dev` / `tk_a7c91_test` with separate logins on project-owned `tk-sqlserver`, preserving the 2022 CU14 engine. The server owns `tk-shared-db`, a new SQL volume and route `db.tk.localhost` (`sql_server`, `1433`, lifecycle `passive`), and joins external `local-gateway`. Stop **API and archiver writers** before native backup/restore; retain old `db_data`. No DB backup/export implementation was observed in TK's `bin/dev`; adopt a canonical native procedure rather than advertise an imaginary wrapper command.
287
+
288
+ **Small existing-wrapper change:** retain the module-level gateway calls, `OpenInEditorBridge.with_running` nesting in `up` and `down`, and both existing `WAIT_FOR_PROCESS` calls; update the bundle to version 0.4.0. Make development `down` use `gateway: true` to match `up`. TK's current `run` has no gateway wrapper; replace its development branch with:
289
+
290
+ ```ruby
291
+ LocalDevelopmentGateway.with_running do
292
+ compose(*%w[run --rm], *args, gateway: true,
293
+ execution_mode: WAIT_FOR_PROCESS, **kwargs)
294
+ end
295
+ ```
296
+
297
+ Keep the nondevelopment branch separate and preserve the existing Linux override and host IDs. Do not replace the local editor bridge implementation while adopting the gateway.
298
+
299
+ **Base development Compose edits** use TK's real variable names, which differ from ELCC's:
300
+
301
+ ```yaml
302
+ x-checkout-db: &checkout-db
303
+ DB_HOST: tk-sqlserver
304
+ DB_PORT: "1433"
305
+ DB_DATABASE: "${TK_DEV_DATABASE:?provision checkout database}"
306
+ DB_USERNAME: "${TK_DEV_USER:?provision scoped login}"
307
+ DB_PASSWORD: "${TK_DEV_PASSWORD:?local secret required}"
308
+ DB_TRUST_SERVER_CERTIFICATE: "true"
309
+ services:
310
+ api:
311
+ environment:
312
+ <<: [*checkout-db, *default-environment]
313
+ networks: [default, project-db]
314
+ labels:
315
+ local-gateway.lifecycle: consumer
316
+ archiver:
317
+ environment:
318
+ <<: [*checkout-db, *default-environment]
319
+ networks: [default, project-db]
320
+ labels:
321
+ local-gateway.lifecycle: consumer
322
+ test_api:
323
+ environment:
324
+ <<: [*checkout-db, *default-environment]
325
+ NODE_ENV: test
326
+ DB_DATABASE: "${TK_TEST_DATABASE:?provision test database}"
327
+ DB_USERNAME: "${TK_TEST_USER:?provision test login}"
328
+ DB_PASSWORD: "${TK_TEST_PASSWORD:?local secret required}"
329
+ networks: [default, project-db]
330
+ labels:
331
+ local-gateway.lifecycle: consumer
332
+ networks:
333
+ project-db:
334
+ external: true
335
+ name: tk-shared-db
336
+ ```
337
+
338
+ Remove checkout `db` and the `api`, `archiver`, and `test_api` dependency edges to it, preserving mail/cache dependencies. TK's existing gateway overlay routes **API, web, and mail only**; there is no DB route stanza to remove. Keep those HTTP labels and external `local-gateway`, and add the new project-server DB route only once. Archiver/test lifecycle labels belong in the base file even though neither needs an HTTP route.
339
+
340
+ **Daily, from the adopted TK checkout:**
341
+
342
+ ```sh
343
+ ./bin/dev up -d
344
+ ./bin/dev test api -- --run
345
+ ./bin/dev down
346
+ ```
347
+
348
+ The real `test_api` owner runs `test_api npm run test`; `api/tests/global-setup.ts` invokes normal initializers. Replace `api/src/initializers/10-ensure-database.ts`'s server-level fallback/`CREATE DATABASE` with provisioned-target validation. `api/src/config.ts` uses dotenv `override: true`, and Compose mounts `.env.development` as `.env.test`: reconcile ignored local DB declarations so they cannot override test isolation. `api/tests/support/clean-database.ts` disables constraints, deletes rows and reseeds identities; assert test database/principal before cleanup and prove a second checkout survives. Retarget existing `sqlcmd` from `exec db` and its `-H` workstation assumption to explicit `-S host,port` and database selection. Validate archiver behavior against the new restricted development login independently; API test success cannot establish that writer's compatibility.
349
+
350
+ ## DBeaver without keeping an app checkout alive
351
+
352
+ After the coordinated gateway is installed and project servers/routes are configured:
353
+
354
+ ```sh
355
+ local-development-gateway hold dbeaver
356
+ # Open DBeaver; select the project route and explicit checkout database.
357
+ # Close/disconnect DBeaver when finished.
358
+ local-development-gateway release dbeaver
359
+ ```
360
+
361
+ `hold dbeaver` ensures the gateway is ready and records a durable named hold for this user/daemon. Closing DBeaver does not release it automatically. `release dbeaver` removes that hold and stops gateway services only if no active consumers, other holds, or pending lifecycle operations require them. It must not delete `local-gateway` or stop project servers. Do not replace this with “leave an unused project up.”
362
+
363
+ Use each project's shared-server hostname, loopback port 1433 (SQL Server) or 5432 (PostgreSQL), explicit checkout database, and its restricted credentials. Travel has three separate endpoints. A route chooses a server, not an authorization boundary. Preserve existing protocol/TLS behavior; raw TCP readiness is not SQL login/query evidence.
364
+
365
+ ## What remains to establish in each consumer PR
366
+
367
+ The source facts above establish owners, field names, versions, commands and topology—not adoption success. Each consumer PR must demonstrate a cold `bin/dev up` to a ready gateway; ordinary tests with correct effective identities; overlapping up/down without a stop race; last-consumer down stopping services despite passive servers; legacy/unknown attachment keepalive; DBeaver hold/release; preserved shared networks/data; native backup/restore and neighbor isolation. WRAP also needs jobs/full-text-history/search evidence; Travel needs six-database/three-engine evidence; TK needs archiver evidence. Project-specific RAM reduction requires equivalent measured workloads, not engine upgrades or a smaller configuration file.
368
+
369
+ No consumer rollout, image publication, gateway deployment, restore compatibility, or passing consumer test suite is claimed by these examples.
@@ -0,0 +1,180 @@
1
+ # Docker-first gateway and project-local database migration
2
+
3
+ This guide is for the owner migrating WRAP, ELCC Data Management, Travel Authorization, or Traditional Knowledge development worktrees. It describes proposed consumer changes, not completed adoption. Start with the [four developer UX examples](consumer-developer-examples.md) for the current source-backed command and configuration contracts, including Traditional Knowledge. No consumer compatibility, data restore, network recovery, or RAM saving is established by reading source. Keep production Compose and externally managed production databases outside this migration.
4
+
5
+ There are two independent cutovers:
6
+
7
+ 1. **Gateway packaging:** replace the machine-wide gateway installation with the self-contained Docker router image. Database ownership and checkout data do not change. Packaging alone does not materially reduce RAM.
8
+ 2. **Project-local database pooling:** replace repeated database server processes across a project's worktrees with project-owned shared servers. Each checkout retains separate development and test databases and restricted credentials. This is the source of potential RAM reduction; measure it before acceptance.
9
+
10
+ Never share a database engine between projects. A project server restart or resource limit affects every worktree using it. Application, cache, mail, search, and default-network isolation remain checkout concerns.
11
+
12
+ ## Source baseline and adoption status
13
+
14
+ The consumer inventory below was read from these local source revisions. Recheck the named owners against the revision selected for a consumer migration PR; local uncommitted changes may also affect a checkout.
15
+
16
+ | Consumer | Inspected HEAD |
17
+ | --- | --- |
18
+ | `icefoganalytics/wrap` | `67883eb5612162b8bd67541dfd522148f70e24b1` |
19
+ | `icefoganalytics/elcc-data-management` | `474b622cc9cec8f4abb10bd20450e654b275f652` |
20
+ | `icefoganalytics/travel-authorization` | `5966448cb387227fa9d7c51b42da4906d0ccc85d` |
21
+
22
+ The generic [shared-database example](../../examples/shared-databases/README.md) demonstrates the isolation contract using SQL Server 2022 and PostgreSQL 17. It is not a drop-in consumer deployment: WRAP requires a newer full-text-enabled engine, ELCC currently uses SQL Server 2019, and Travel currently uses PostgreSQL 14.4 plus two different SQL Server versions. Consumer engine upgrades require independent restore and behavior evidence.
23
+
24
+ ## Downstream complexity acceptance
25
+
26
+ Do not replace a consumer's wrapper with a shared-database management CLI. The example keeps only ordinary application command methods and Compose delegation in `bin/dev`. Server startup uses native Compose; the separate project-owner `bin/provision CHECKOUT_NAME` operation selects an internal adapter using `DB_ENGINE`. Shared checkout validation and environment naming are engine-neutral; native clients and permission SQL live inside `provisioning/postgres` and `provisioning/sqlserver`. Engine-specific administration does not enter the consumer command dispatcher or gateway runtime. Development/test connection overrides remain visible in Compose, and migrations/test reset remain application-owned.
27
+
28
+ For an ELCC-shaped adoption, the intended responsibility delta is:
29
+
30
+ | Existing owner | Consumer change | Remaining responsibility |
31
+ | --- | --- | --- |
32
+ | `bin/dev` command methods and Compose delegation | Retain; do not add engine/group dispatch or database deletion commands | Normal application workflow |
33
+ | Gateway calls around `up`, `down`, and `run` | Update to the coordinated lifecycle contract; preserve editor-bridge hooks | First-use startup and last-consumer shutdown |
34
+ | Checkout `db` service and dependencies on it | Replace with a project-server connection and external network | Project owner starts and maintains the server |
35
+ | Administrator-powered application database creation | Remove after explicit database/login provisioning is established | One project-owned provisioning operation per checkout |
36
+ | Application migrations and test setup | Retain against separate restricted development/test connections | Consumer owns schema and test cleanup |
37
+ | Backup/restore and destructive reset commands | Retarget existing owners, never add parallel generic helpers | Explicit database selection and neighbor-preservation proof |
38
+
39
+ This is an adoption design, not an applied consumer diff. Sharing reduces repeated server processes but introduces coordinated server maintenance and provisioning. Accept the downstream PR only after reviewing its actual removed/added responsibilities and exercising its existing developer commands. A smaller example file or lower synthetic RAM measurement alone does not establish net downstream simplification.
40
+
41
+ ## A. Swap only the machine-wide gateway
42
+
43
+ Follow [Docker installation](docker-installation.md) for the versioned Compose download, single-file installation, native start/stop commands, and release prerequisites. Require Docker Engine and Compose **2.20.2 or newer** on the supported Linux amd64 platform. The Compose file selects the immutable digest of `ghcr.io/icefoganalytics/local-development-gateway/database-router:0.4.0`. `LOCAL_DEVELOPMENT_GATEWAY_IMAGE` selects an alternate image. The installed router needs no host Ruby library/configuration mounts or runtime source checkout.
44
+
45
+ Inventory the previous installation's Compose project, containers, image/version labels, port bindings, network ownership, lifecycle caller, and saved Compose file. Save its configuration and image references for rollback. Do not start a second pair on occupied loopback ports 80, 1433, and 5432. Replacing the running machine-wide pair requires coordinated downtime; authorization alone is not evidence that active consumers can tolerate interruption. Preserve `local-gateway` while consumers are attached and leave database volumes alone.
46
+
47
+ Use **one coordinated lifecycle contract** in every cooperating wrapper. The historical consumer baselines below select gateway gem **0.2.2**. Leaving their existing hooks on that gem is not safe adoption: when no ready gateway exists, it can recreate its bundled bind-mounted installation and bypass version 0.4.0's synchronization.
48
+
49
+ Update each consumer's existing Gemfile/lock owner to `~> 0.4.0`. Retain `LocalDevelopmentGateway.with_running` around a waiting `up` command and use `with_running(ensure_running: false)` around waiting `down`/`stop` commands. Preserve editor-bridge nesting and command dispatch. Do not `exec` out of the block. Long-running commands retain a pending-operation lock without serializing other checkouts' commands.
50
+
51
+ Label shared database containers `local-gateway.lifecycle: passive`, and label active app/job/test services `local-gateway.lifecycle: consumer`, including services on private networks only. Unknown attached containers keep the gateway alive. After the final consumer disappears, guarded cleanup stops only the routers and preserves their network, idle databases, and data. For desktop-only access use a named hold. See [lifecycle ownership](../architecture/gateway-lifecycle.md).
52
+
53
+ Do not add a second manager around retained hooks or remove automatic startup from the normal developer path. Consumer wrappers still need Ruby for other duties; Docker-only router installation does not make those wrappers Ruby-free. Explicit native Compose operation remains available for machine owners, but bypasses the guard. Existing aliases from gem 0.2.2 are not proof of version 0.4.0's alias derivation: validate host resolution and each selected route explicitly.
54
+
55
+ Before accepting the gateway swap, verify image/version labels, health, HTTP routes, SQL Server/PostgreSQL client connections, and existing TLS/cancellation behavior with disposable clients. Preserve the established loopback ports and network/labels. TCP health alone is not protocol evidence.
56
+
57
+ **Gateway rollback:** stop only the new pair using its recorded owner, leaving database containers, consumer networks, and volumes intact; restore the previous saved gateway configuration/image and start it through its original owner. Recheck routes. This rollback moves no database data and does not undo a database-pool migration.
58
+
59
+ ## B. Common project-local database cutover
60
+
61
+ ### Establish ownership and names first
62
+
63
+ For each project, give its shared-server Compose stack a stable project name distinct from every checkout's app stack. Keep the server's persistent volumes and private external network owned by that project. Checkout Compose files reference that network as external; checkout `down` must never stop the shared stack, remove its network, or delete its volumes. Shared-server shutdown is an explicit project-owner operation, coordinated with all worktrees, not an `ensure` block or automatic checkout cleanup.
64
+
65
+ Allocate a stable checkout key with a collision-resistant suffix rather than relying solely on branch-name sanitization. Use identifier-safe names such as `wrap_wt_a7c91_dev` and `wrap_wt_a7c91_test`, and record their mapping to the actual checkout. Allocate distinct restricted development and test credentials. Repeat for every Travel source database as well. Restrict each login to its assigned database; do not grant `sysadmin`, `dbcreator`, PostgreSQL `SUPERUSER`, or `CREATEDB` to applications. Database-scoped schema/migration and test-reset permissions may be needed; they must not permit access to another checkout or project. Keep administrative provisioning/restore credentials outside app environments and version control.
66
+
67
+ For PostgreSQL, database separation alone is insufficient because `PUBLIC` normally has `CONNECT`: revoke inappropriate public connection privileges and grant only the intended role, including any intentionally retained maintenance access. For SQL Server, avoid cross-database ownership chaining, trusted databases, and broad server roles. After restore, remap users to the intended scoped logins and remove copied administrative or unrelated application access.
68
+
69
+ ### Change the consumer's existing owners once
70
+
71
+ Edit the consumer's development Compose and existing `bin/dev` configuration assembly, rather than adding a competing wrapper or asking developers to stack extra flags manually:
72
+
73
+ - Put the private shared-network attachment and connection configuration on **both** development and `test_api` paths. Include jobs and source integrations where present. A gateway overlay may not be loaded for tests, `run`, migrations, or backup commands; it cannot be the only owner of private database reachability.
74
+ - Replace fixed development/test names and administrator credentials with checkout-scoped inputs. Existing literal `environment` values override `env_file`; merely adding a private env file will not replace them. Keep private values in ignored local configuration and pass them through the existing wrapper consistently, without printing secrets.
75
+ - Remove the checkout database service definitions and their `depends_on` edges from the development file, and remove their database-service stanzas from `docker-compose.development.gateway.yml`. Otherwise an overlay can resurrect an obsolete service or `up` can continue starting a second engine. Preserve old named volumes and their recorded names; removing a service definition is not permission to remove its data.
76
+ - Attach the project server, not each checkout's database, to `local-gateway` for desktop access. Give each server endpoint one project-owned hostname/driver/port label, unique across projects. Keep apps on the project's private network, using the stable server DNS alias directly. Keep HTTP routing labels on checkout apps unchanged. Do not advertise the same database hostname from multiple containers.
77
+ - Update the existing SQL console and import/export helpers to use the shared-server owner, explicit destination database, and correct scoped credentials. They must not infer a destination from `POSTGRES_DB` or a container's single development default. Keep one canonical implementation; retire the old `exec db` assumptions rather than wrapping them in another command layer.
78
+ - Pre-provision the exact databases administratively. Change automatic creation paths to validate a provisioned database and fail clearly if absent, rather than falling back to server-level creation or granting server administration to apps.
79
+
80
+ ### Transfer data and prove isolation
81
+
82
+ 1. Inventory all checkout volumes, engines/versions, collation/extensions/full-text requirements, database names, writers, and backup owners. Save old config, resolved nonsecret connection mappings, volume names, and backup paths. Do not mount an old data directory into a different engine version.
83
+ 2. Stop the selected checkout's writers using its existing wrapper. Make a database-native backup of every development database that matters, including Travel source simulators when they contain useful data. Treat SQL Server backups and PostgreSQL dumps as sensitive data. Preserve the original volumes untouched.
84
+ 3. Restore into **new, explicitly named** databases on the project servers, initially disconnected from apps. SQL Server restore needs explicit `WITH MOVE` destinations for every data/log file, verified from `RESTORE FILELISTONLY`; do not use a generic `REPLACE` against another checkout. PostgreSQL major-version migration uses a supported logical dump/restore path and version-compatible clients, not volume reuse. Validate row counts, migration history, expected text/search behavior, and scoped-user mappings before cutover.
85
+ 4. Provision independent test databases and run their normal initializers/seeds/reset path with their test credentials. Do not copy development credentials into tests. Assert the connected server, database, and current principal before any reset; deny connection to another checkout's development and test databases. Pre-provisioning must work without server creation privileges.
86
+ 5. Apply the consumer edits below and recreate only its app resources. Verify development access and a destructive test reset while another checkout retains a sentinel record and usable connection. Stop/down checkout A through its wrapper and prove checkout B and the project servers remain available. Record actual commands/results in the consumer PR; the generic example does not prove consumer adoption.
87
+ 6. Measure equivalent workloads before and after: same number of worktrees, data, warm-up, query/test load, engine versions, and memory settings. Record process/container inventory plus repeated `docker stats --no-stream` samples covering **all** old/new DB, app, and gateway containers, and host available RAM. Report both total and database-only RAM and any throughput regression. Lowering a memory cap, omitting a source engine, or moving a process outside the measurement is not an equivalent saving. Require a measured reduction in total RAM; do not attribute it to image packaging.
88
+
89
+ Retain old volumes and backups until the project owner accepts the restore and rollback evidence. Only then schedule separately authorized retirement.
90
+
91
+ ### Database-pool rollback
92
+
93
+ Stop the affected checkout's writers. If it has written to the new database, export those writes and restore to a compatible rollback destination or explicitly accept their loss before switching; the preserved old volume is a point-in-time snapshot, not a live replica. A SQL Server backup from a newer server cannot simply be restored to an older version. Establish a compatible logical transfer or retain a rollback server on the supported version before accepting an engine upgrade.
94
+
95
+ Restore the checkout's old development Compose/service/dependency and gateway-overlay configuration, previous restricted/default connection mapping as appropriate, and exact original volume attachment. Start it via the original wrapper, then validate data and test isolation. Do not stop a shared engine used by other checkouts. Do not delete pooled databases until their data is reconciled and their owner approves retirement. Gateway rollback is unnecessary unless the gateway itself failed.
96
+
97
+ ## WRAP: full-text engine, jobs, and hard-coded rollback SQL
98
+
99
+ **Observed owners:** `docker-compose.development.yml`, `docker-compose.development.gateway.yml`, `db.Dockerfile`, `bin/dev`, `bin/lib/database/command.rb`, `bin/lib/development_environment/command.rb`, `api/src/config.ts`, `api/src/db/db-client.ts`, and `api/src/db/db-client-legacy.ts`.
100
+
101
+ - Development `api` and `jobs` inherit `AZURE_SQL_HOST`, `AZURE_SQL_USERNAME`, `AZURE_SQL_DATABASE`, `AZURE_SQL_PASSWORD`, and `AZURE_SQL_PORT`; trust uses `DB_TRUST_SERVER_CERTIFICATE`. The current host is `${COMPOSE_PROJECT_NAME}-db`, username is `sa`, and the development name is `${AZURE_SQL_DATABASE:-wrap_development}`. `test_api` overrides the name to literal `wrap_test`. Replace **all five connection fields** consistently for `api`, `jobs`, and `test_api`, with a distinct test database and login/password. Preserve the configured SQL TLS/trust behavior for local development; do not globally weaken production TLS.
102
+ - WRAP's environment guard rejects infrastructure-owned declarations in `api/.env.development`. Extend its existing ownership policy deliberately when introducing private database inputs, and run its documented `./bin/dev check-environment` in the consumer migration QA. Do not bypass the guard by scattering database overrides across files. The current database-name interpolation belongs to the host/root `.env`, not the API private env file.
103
+ - Test configuration needs a separate check: `api/src/config.ts` loads `api/.env.test` with dotenv `override: true`, so local declarations can replace Compose-selected test connections. The development environment guard does not inspect this ignored test file. Reconcile its declarations locally without exposing values, and assert the effective database identity and principal before initializers as well as destructive resets.
104
+ - `db.Dockerfile` builds `wrap-db:full-text` from **SQL Server 2025 CU7, Ubuntu 24.04**, installing `mssql-server-fts`. Preserve that engine capability and backup compatibility; SQL Server 2022 cannot restore a WRAP 2025 backup. Full-text support remains necessary for historical migration replay/rollback, not current runtime search: `20260812014500_create-workflow-search-documents-full-text-catalog.ts` creates the catalog/index; `20261020160018_retire-workflow-search-full-text-index-and-catalog.ts` retires them, and `20261020160020_retire-workflow-search-documents-table.ts` removes the table (all under `api/src/db/migrations`). Follow `docs/architecture/workflow-search.md`: verify historical replay/rollback on disposable data and current Elasticsearch indexing/search after restore, rather than expecting a surviving SQL full-text index.
105
+ - `api/src/db/migrations/20250414162002_increase-size-of-workflow-histories-subtitle-field-to-better-support-commenting.ts` has a `down` query against **`wrap_development.dbo.workflow_histories`**. The consumer owner must replace that cross-database reference with the connected database's table before permitting checkout-scoped rollback. Never grant a test login access to `wrap_development` to make this succeed. Audit remaining migrations/raw SQL against the selected consumer revision before adoption.
106
+ - Remove development `db`, `api/jobs/test_api` dependency edges to it, and the overlay's `db` TCP route stanza. Preserve `db_data` and its physical volume. Leave Redis, Elasticsearch, mail, and their dependencies alone. `ELASTICSEARCH_INDEX_PREFIX` defaults from `AZURE_SQL_DATABASE` in `api/src/config.ts`; changing the database name also changes that default search namespace. Plan index rebuilding/verification rather than assuming old indexed data follows the database restore.
107
+ - `./bin/dev db --export PATH` / `--import PATH` are implemented by `bin/lib/database/command.rb`. Today it discovers `db`, reads its `AZURE_SQL_DATABASE`, executes `BACKUP ... COPY_ONLY` and `RESTORE ... WITH MOVE, REPLACE`, copies a staged `.bak`, and uses `MSSQL_SA_PASSWORD`/`master`. Use the old export **before** removing `db`; stop API and jobs first. Rewrite this owner for explicit project-server and checkout-database selection with administrative operations isolated from app credentials. `bin/dev`'s `sqlcmd` also executes in `db`; migrate it with the same connection contract.
108
+ - Use `./bin/dev test api` or `./bin/dev test_api`, not `test-api`. The wrapper also owns `knex`, `migrate`, and `seed`. `api/tests/global-setup.mts` runs initializers; `api/src/initializers/10-ensure-database.ts` attempts server-level fallback/creation; `20-run-migrations.ts` and `30-run-seeds.ts` are the initialization owners. Pre-provision both databases and replace creation assumptions. `api/tests/support/clean-database.ts` disables constraints, deletes rows, and reseeds identities in the connected database: it must only receive the private test connection. Do not use `--skip-setup` for first migration acceptance.
109
+ - `bin/dev` loads the gateway overlay for `up`, but its common Compose assembly does not always load it. Keep the private network and dev/test database fields in the base development configuration. Apply the lifecycle choice in section A to this wrapper's `up`/`down` hooks and top-level gateway require; do not retain the 0.2.2 hooks unchanged or add a second gateway-start wrapper.
110
+
111
+ **Adoption gates:** full-text-capable 2025 server/restore, hard-coded migration correction, environment-owner update, jobs/test connection separation, backup/console retargeting, normal initializers and destructive reset isolation, and search namespace validation. None is established by this gateway draft.
112
+
113
+ ## ELCC Data Management: SQL Server 2019 and base-file test configuration
114
+
115
+ **Observed owners:** `docker-compose.development.yaml` (note `.yaml`), optional `docker-compose.development.linux.yml`, `docker-compose.development.gateway.yml`, `bin/dev`, `api/src/config.ts`, `api/src/db/db-client.ts`, and `api/src/db/db-migration-client.ts`.
116
+
117
+ - Replace `DB_HOST`, `DB_USER`, `DB_NAME`, `DB_PASS`, and `DB_PORT` in the base development environment. Current values use `${COMPOSE_PROJECT_NAME}-db`, `sa`, and `elcc_development`; `test_api` hard-codes `elcc_test`. Supply an independent test login/password/name, keeping `DB_TRUST_SERVER_CERTIFICATE` appropriate to the local server. Changing only `api/.env.development` loses to the Compose literals.
118
+ - Current development SQL Server is **2019 CU28, Ubuntu 20.04**, not the base production Compose file's `2019-latest`. Select a project-owned supported image and test its restore; SQL Server 2022 is an upgrade, not a neutral packaging change. Preserve original `db_data`; do not attach it to the upgraded engine.
119
+ - Remove development `db`, `api` and `test_api` dependencies on it, and the overlay's obsolete `db` route. Put the external private-network attachment on `api` and `test_api` in the base development file so tests do not depend on gateway activation.
120
+ - `bin/dev#compose_file_options` combines the `.yaml` base, an optional Linux override, and the gateway overlay only when requested. Its `up` coordinates both `LocalDevelopmentGateway` and `OpenInEditorBridge`; `run` coordinates only the gateway. Apply section A's gateway ownership choice to `up`, `down`, and `run` and the top-level require; preserve the existing editor-bridge behavior. Update `dynamic_environment_variables` only as needed for checkout database inputs rather than introducing another wrapper. Preserve host UID/GID behavior.
121
+ - `bin/dev` owns `test api` (also `test_api`), `knex`, `migrate`, `seed`, `db`, and `sqlcmd`. The latter two currently `exec db`; retarget them to explicit shared-server/database connections. The observed `sqlcmd` uses `-H "$DB_HOST"` (workstation name), not `-S` server selection; do not copy that assumption into a remote/shared-server helper. Set server and port explicitly in the consumer fix.
122
+ - No export/import implementation was found in this wrapper. Add the project-owned native SQL Server backup/restore procedure to the existing database tooling before migration: explicit source/target names, privileged restore outside the app, `COPY_ONLY` backup, `RESTORE FILELISTONLY` and unique `WITH MOVE` files, then remap restricted users. Do not invent a working `./bin/dev db --export` command for ELCC.
123
+ - `api/tests/global-setup.ts` runs `npm run initializers`; `api/src/initializers/10-ensure-database.ts` has creation/fallback logic, `20-run-migrations.ts` runs Knex, and `30-run-seeds.ts` skips seeding entirely when `NODE_ENV` is `test`. Outside tests it selects environment seeds with `SKIP_SEEDING_UNLESS_EMPTY` behavior. Pre-provision and validate both databases, preserving that test seed policy. `api/tests/support/clean-database.ts` performs constraint disabling, deletion and identity reseeding. Execute that reset only against the new checkout test connection and prove a second checkout is intact. Do not use `--skip-setup` to hide provisioning failures.
124
+
125
+ **Adoption gates:** supported engine/restore decision, new canonical backup procedure, remote console targeting, dev/test credentials and network coverage, and initializers/reset isolation. Source inspection did not establish shared-engine compatibility.
126
+
127
+ ## Travel Authorization: PostgreSQL plus two SQL Server source simulators
128
+
129
+ **Observed owners:** `docker-compose.development.yml`, `docker-compose.development.gateway.yml`, `bin/dev`, `bin/lib/database/command.rb`, `api/src/config.ts`, `api/src/db/db-client.ts`, and `api/src/integrations/{trav-com-integration,travel-port-integration}`.
130
+
131
+ | Connection family | Current development / test database | Current engine |
132
+ | --- | --- | --- |
133
+ | `DB_HOST`, `DB_PORT`, `DB_USER`, `DB_PASS`, `DB_NAME` | `travel_development` / `travel_test` | PostgreSQL `14.4` |
134
+ | `TRAVCOM_DB_HOST`, `TRAVCOM_DB_PORT`, `TRAVCOM_DB_USER`, `TRAVCOM_DB_PASS`, `TRAVCOM_DB_NAME` | `trav_com_development` / `trav_com_test` | SQL Server `2022-CU14-ubuntu-22.04` |
135
+ | `TRAVELPORT_DB_HOST`, `TRAVELPORT_DB_PORT`, `TRAVELPORT_DB_USER`, `TRAVELPORT_DB_PASS`, `TRAVELPORT_DB_NAME` | `travelport_development` / `travelport_test` | SQL Server `2019-CU28-ubuntu-20.04`, `SQL_Latin1_General_CP1_CI_AS` collation |
136
+
137
+ - Pool each engine role **within Travel only** across its worktrees. Initially retain separate project-owned TravCom and Travelport SQL Server processes because the observed versions/collation differ. Consolidating those two roles further needs its own compatibility decision. Each checkout needs six independent databases and their scoped dev/test credentials, not just a renamed PostgreSQL database. Never point a development initializer or test reset at a real external production Travelport source.
138
+ - Set every field in all three connection families on both `api` and `test_api`; the SQL families also use `TRAVCOM_DB_TRUST_SERVER_CERTIFICATE_ENABLED` and `TRAVELPORT_DB_TRUST_SERVER_CERTIFICATE_ENABLED`. Current test names are Compose literals. The PostgreSQL `app` role is created through `POSTGRES_USER`, which creates a bootstrap superuser in the official image; its friendly name does not make it a restricted app role. The SQL source connections currently use `sa`. Replace all three with scoped credentials.
139
+ - Remove development `db`, `db_trav_com`, and `db_travelport`, their `api`/`test_api` dependency edges, and all three database route stanzas from the gateway overlay. Keep `db_data`, `db_trav_com_data`, and `db_travelport_data` preserved. Attach both app/test services to Travel's private external network. Advertise stable project-server routes rather than old checkout-specific `db.*`, `db-trav-com.*`, and `db-travelport.*` routes.
140
+ - `bin/dev#compose_file_options` currently includes the gateway overlay for development operations, plus an optional Linux override. Keep the private database contract in the base development file anyway: direct commands or future nongateway test configuration must not change which database is selected. Apply section A's lifecycle choice to `up`, `down`, `stop`, and `run` and the top-level gateway require. Preserve the editor bridge without adding another manager.
141
+ - `./bin/dev db --export PATH` exports only PostgreSQL via `pg_dump --format=custom`; `--import PATH` drops/recreates the database then runs `pg_restore --no-owner --exit-on-error --single-transaction`. These are development-only operations in `bin/lib/database/command.rb`, currently executed in `db` using `POSTGRES_USER`/`POSTGRES_DB`. Export before service removal. Rewrite this owner and `bin/dev#psql` to use an explicit shared endpoint/database and appropriately scoped role. Move administrative create/drop to provisioning rather than granting `CREATEDB` to the app. Preserve private backup permissions. Provide native SQL Server backups separately for useful TravCom and Travelport data; the PostgreSQL helper does not cover them.
142
+ - PostgreSQL 17 is a major upgrade from 14.4. Use logical dump/restore into a new volume and verify extensions/schema/migrations rather than reusing `db_data`. Keep the old 14.4 volume until rollback is accepted. Validate each SQL source's version/collation and restore independently.
143
+ - `api/src/initializers/10-create-database.ts` always connects to the maintenance database **`postgres`** to inspect/create `DB_NAME`. A role restricted to only its private database will not satisfy this as written. Change the initializer to validate the already provisioned target database instead of granting global maintenance access or database-creation privileges. The SQL integrations' `initializers/10-ensure-database.ts` also need their provisioned-target path validated under restricted credentials.
144
+ - Main initializers run migrations/seeds; `45-initialize-travel-port-development.ts` dispatches the local Travelport sequence, while both integrations own their own `initializers/20-run-migrations.ts` and `30-run-seeds.ts`. `api/tests/global-setup.ts` runs normal initializers. Keep synthetic-source creation and writable test seeding scoped to their corresponding private source databases; production Travelport's read-only source contract is different.
145
+ - `api/tests/support/clean-database.ts` truncates PostgreSQL tables with `RESTART IDENTITY CASCADE`; `clean-trav-com-database.ts` and `clean-travel-port-database.ts` disable SQL constraints, delete rows, and reseed identities. Review their callers and assert all three test database identities before destructive execution. `test_api` also mounts `api/.env.development` as `.env.test`; check this dotenv path alongside Compose precedence so no development or production source credential leaks into tests.
146
+ - Require positive database-state assertions, not successful command exits alone: `api/src/initializers/index.ts` catches initialization errors and exits zero; `clean-trav-com-database.ts` catches query failures and returns true. Verify expected migration history, seed records, and post-reset table contents in each target database, alongside untouched neighbor sentinels. Correct error propagation in those existing consumer owners before relying on them as migration acceptance checks.
147
+
148
+ **Adoption gates:** six-database provisioning, restricted PostgreSQL initializer behavior, both source-simulator reset/seed paths, three native backup/restore paths, PostgreSQL upgrade evidence if selected, and concurrent-checkout isolation. The generic two-engine proof does not establish these consumer behaviors.
149
+
150
+ ## Desktop database clients after pooling
151
+
152
+ Select the **project shared-server hostname plus explicit checkout database**, not a per-checkout container hostname. SQL Server clients use the gateway's existing loopback port 1433; PostgreSQL clients use 5432. Use the appropriate project's scoped login, and set the database explicitly in every saved connection. A hostname chooses the server process, not the database or authorization boundary. For Travel, retain separate shared-server hostnames for PostgreSQL, TravCom SQL Server, and Travelport SQL Server. Retire obsolete checkout database routes only after saved clients and scripts are migrated; never keep duplicate containers claiming a hostname as a transition strategy.
153
+
154
+ Before the last app stops, acquire a named hold with `local-development-gateway hold dbeaver`; release it with `local-development-gateway release dbeaver` after closing desktop connections. Passive database servers do not keep routers running by themselves. A live DBeaver TCP connection is not an implicit lifecycle registration.
155
+
156
+ ## Network exhaustion and ownership-aware cleanup (#41)
157
+
158
+ Database pooling reduces engine count, not necessarily checkout Compose networks. A stopped checkout can still retain containers and network allocations. This procedure diagnoses [issue #41](https://github.com/icefoganalytics/local-development-gateway/issues/41); it is **not verified recovery evidence** and does not mark that issue fixed.
159
+
160
+ Before removing anything, inspect exact IDs and ownership, including stopped containers:
161
+
162
+ ```sh
163
+ docker network ls --no-trunc
164
+ docker network inspect NETWORK_ID
165
+ docker ps -a --no-trunc --filter network=NETWORK_ID
166
+ # For each attached or ownership-related container, including stopped ones:
167
+ docker inspect CONTAINER_ID
168
+ ```
169
+
170
+ Read `com.docker.compose.project`, `com.docker.compose.network`, container Compose labels (including working directory/config files when present), IPAM subnet/gateway, and actual container network attachments. Compare them with the owning checkout's Compose files, root `.env`/project-name configuration, and `bin/dev` file-selection logic. Do not assume a network belongs to the current directory merely because its name resembles a branch. Resolve which checkout/project owner controls it and whether active worktrees or shared servers need it.
171
+
172
+ For an unwanted **checkout-owned** stack, confirm with its owner, then run that checkout's documented `./bin/dev down` using its original project-name/configuration environment, **without `--volumes`**. WRAP and ELCC do not load their gateway overlay on every `down` path; inspect the resolved owner/config before relying on teardown. Do not substitute a raw `docker compose down` from the gateway checkout. Keep project-server and machine gateway lifecycles separate. If the wrapper cannot run, establish the exact original files/project name from labels and obtain owner approval for an equivalent targeted command; do not guess.
173
+
174
+ Only after the owner confirms that a particular leftover network is an orphan, and fresh inspection plus `docker ps -a --filter network=NETWORK_ID` establishes that **no containers, including stopped containers, reference it**, remove that exact owned network:
175
+
176
+ ```sh
177
+ docker network rm NETWORK_ID
178
+ ```
179
+
180
+ Do not remove the machine `local-gateway` network or a project's shared-database network as checkout cleanup. Never use blanket `docker network prune`, `docker system prune`, or delete unrelated containers to free address space. If ownership is uncertain or any container remains, stop and resolve it with the owner. Keep diagnosis and any later recovery commands/results in #41. Its recovery acceptance requires the previously blocked consumer lint command to succeed; successful gateway packaging or an empty-network removal alone does not prove that recovery.