Skip to content

fix: keep nested application relations under the postgres argument limit - #7

Merged
agentHits merged 1 commit into
AgentHits-Devfrom
fix/nested-application-column-limit
Oct 6, 2026
Merged

agentHits merged 1 commit into
AgentHits-Devfrom
fix/nested-application-column-limit

Conversation

@agentHits

@agentHits agentHits commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

What is this PR about?

The application table has 101 columns. Drizzle 0.45 packs every selected column of a nested relation into one json_build_array(...) call, and Postgres rejects calls with more than 100 arguments (54023 cannot pass more than 100 arguments to a function). Three queries in AgentHits-Dev still loaded the whole application row through a nested relation:

  • findDeploymentById (application, schedule.application, volumeBackup.application): now selects only serverId, the only field callers read. The error broke the deployment log WebSocket (it closed silently), deployment.readLogs, killProcess, removeDeployment, rolling back, and rollback creation during deploys with a rollback registry. Removing old rollbacks was skipped silently. Upstream had already narrowed this query (97885ee), but the upstream merge 5a1d8ea (2026-10-01) kept application: true.
  • Volume backup restore check (assertVolumeRestoreObjectBound): application and compose now select only appName. A volume restore could not start.
  • Preview deployment lookup in monitoring-access: application now selects only applicationId and serverId. This lookup runs for every app name that is not an application, so monitoring for compose services, databases and preview deployments failed (docker stats WebSocket, user.getContainerMetrics).

A shared test helper, apps/dokploy/__test__/helpers/postgres-function-args.ts, compiles the real SQL with drizzle.mock({ schema }) and counts json_build_array arguments. Each of the three queries has a test.

No migrations and no new environment variables; only the dokploy service image changes.

Checks

  • The new tests fail on the old code (101, 102 and 101 arguments) and pass now.
  • Vitest on the three touched test files: 28 tests pass. Full vitest run: 2055 pass, 1 skipped; the 8 failures are only in *.real.test.ts (no local Docker socket).
  • bun run typecheck: 4/4 packages pass. Selecting appName instead of serverId in the narrowed relations makes tsc fail in listen-deployment.ts, so typecheck guards the column lists.
  • bun run format-and-lint: no errors.
  • Audit: every other nested relation to application found by grep was compiled with toSQL; they peak at 50 arguments.
  • Not run: the queries against a live database.

Rollout notes

  • Before rollout, record the running dokploy image and take a database backup.
  • After rollout: deployment logs open, deployment.readLogs returns the log text, and monitoring opens for a compose service or a database.

Not in this PR

backup.listBackupFiles fails with the same error in AgentHits-Dev; #6 fixes it. The two branches merge cleanly. The #6 test keeps its own copy of the argument counter, which can switch to the shared helper later.

🤖 Generated with Claude Code

@agentHits
agentHits force-pushed the fix/nested-application-column-limit branch from d93c29c to e13b437 Compare October 6, 2026 18:12
Что:
- findDeploymentById берёт из трёх вложенных связей application (у самого деплоя, у schedule и у volumeBackup) только serverId: другие поля этих связей вызывающий код не читает.
- Проверка восстановления volume backup (assertVolumeRestoreObjectBound) берёт из связей application и compose только appName.
- Поиск preview-деплоя в monitoring-access берёт из связи application только applicationId и serverId.
- Новый тестовый хелпер __test__/helpers/postgres-function-args.ts собирает настоящий SQL через drizzle.mock с реальной схемой и считает аргументы json_build_array. Для каждого из трёх запросов добавлен тест, который проверяет, что аргументов не больше 100.
Зачем:
- В таблице application 101 колонка. Drizzle кладёт все выбранные колонки вложенной связи в один вызов json_build_array, а Postgres принимает не больше 100 аргументов и отвечает ошибкой 54023 "cannot pass more than 100 arguments to a function".
- Из-за findDeploymentById не работали WebSocket логов деплоя (закрывался молча), deployment.readLogs, killProcess и removeDeployment, откат через rollback и создание rollback при деплое с rollback registry. Удаление старых rollback молча пропускалось.
- Из-за проверки восстановления не запускалось восстановление volume backup.
- Поиск preview-деплоя выполняется для каждого имени, которое не нашлось среди application. Поэтому мониторинг compose, баз данных и preview-деплоев (WebSocket docker stats, user.getContainerMetrics) отвечал ошибкой.
- Upstream уже сужал связи в findDeploymentById (97885ee), но при слиянии upstream 5a1d8ea (2026-10-01) конфликт разрешился в пользу application: true.
Риски:
- Если код начнёт читать из этих связей другие поля, их там не будет. Typecheck это ловит: при выборе appName вместо serverId tsc падает в listen-deployment.ts.
- backup.listBackupFiles в AgentHits-Dev падает с той же ошибкой. Его чинит открытый PR #6, здесь он не менялся. В тесте PR #6 своя копия подсчёта аргументов, после слияния её можно заменить общим хелпером.
Проверки:
- Команды и результаты: CI=true bunx vitest run --config __test__/vitest.config.ts __test__/deployment/find-deployment-by-id.test.ts __test__/volume-backups/restore-security.test.ts __test__/server/container-resource-stats-access.test.ts - 28 тестов прошли; на старом коде три новых теста падают с "expected 101 to be less than or equal to 100" (для monitoring - 102). Полный прогон CI=true bunx vitest run --config __test__/vitest.config.ts: 2055 тестов прошли, 1 пропущен, 8 упали только в __test__/deploy/application.real.test.ts и __test__/setup/monitoring-setup.real.test.ts из-за отсутствия сокета Docker Desktop (connect ECONNREFUSED /Users/agent/.docker/run/docker.sock). bun run typecheck - 4/4 пакета без ошибок. bun run format-and-lint - 0 ошибок (33 предупреждения в других файлах, в изменённых файлах их нет). Временный vitest-аудит через toSQL (удалён перед коммитом) проверил остальные вложенные связи с application из grep: у них не больше 50 аргументов.
- Ограничения: запросы не выполнялись против живой базы; *.real.test.ts без локального Docker не проверены; ничего не пушилось и не выкатывалось.

What:
- findDeploymentById loads only serverId from its three nested application relations (on the deployment itself, on schedule and on volumeBackup); callers read no other field from them.
- The volume backup restore check (assertVolumeRestoreObjectBound) loads only appName from the application and compose relations.
- The preview deployment lookup in monitoring-access loads only applicationId and serverId from the application relation.
- A new test helper, __test__/helpers/postgres-function-args.ts, compiles the real SQL with drizzle.mock and the real schema and counts json_build_array arguments. Each of the three queries gets a test that checks there are no more than 100.
Why:
- The application table has 101 columns. Drizzle puts every selected column of a nested relation into one json_build_array call, and Postgres accepts at most 100 arguments and fails with 54023 "cannot pass more than 100 arguments to a function".
- Because of findDeploymentById, the deployment log WebSocket (closed silently), deployment.readLogs, killProcess and removeDeployment, rolling back, and rollback creation during deploys with a rollback registry all failed. Removing old rollbacks was silently skipped.
- Because of the restore check, a volume backup restore could not start.
- The preview deployment lookup runs for every name that is not found among applications. Monitoring for compose services, databases and preview deployments (the docker stats WebSocket, user.getContainerMetrics) therefore failed.
- Upstream had already narrowed the relations in findDeploymentById (97885ee), but the upstream merge 5a1d8ea (2026-10-01) resolved the conflict in favour of application: true.
Risks:
- Code that starts reading other fields from these relations will not find them there. Typecheck catches this: selecting appName instead of serverId makes tsc fail in listen-deployment.ts.
- backup.listBackupFiles fails with the same error in AgentHits-Dev. Open PR #6 fixes it, so it is unchanged here. The PR #6 test has its own copy of the argument counter, which can switch to the shared helper after both are merged.
Checks:
- Commands and results: CI=true bunx vitest run --config __test__/vitest.config.ts __test__/deployment/find-deployment-by-id.test.ts __test__/volume-backups/restore-security.test.ts __test__/server/container-resource-stats-access.test.ts - 28 tests passed; on the old code the three new tests fail with "expected 101 to be less than or equal to 100" (102 for monitoring). Full run CI=true bunx vitest run --config __test__/vitest.config.ts: 2055 passed, 1 skipped, 8 failed, all in __test__/deploy/application.real.test.ts and __test__/setup/monitoring-setup.real.test.ts because the Docker Desktop socket is missing (connect ECONNREFUSED /Users/agent/.docker/run/docker.sock). bun run typecheck - 4/4 packages clean. bun run format-and-lint - 0 errors (33 warnings in other files, none in the changed files). A temporary vitest audit with toSQL (removed before the commit) checked the other nested application relations found by grep: they peak at 50 arguments.
- Limitations: the queries were not run against a live database; the *.real.test.ts tests were not verified without a local Docker; nothing was pushed or deployed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@agentHits
agentHits force-pushed the fix/nested-application-column-limit branch from e13b437 to 44ebb05 Compare October 6, 2026 18:24
@agentHits
agentHits merged commit 44db1c6 into AgentHits-Dev Oct 6, 2026
4 checks passed
@agentHits
agentHits deleted the fix/nested-application-column-limit branch October 6, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant