Fix fresh PostgreSQL initialization without manual baselining #182

Open
opened 2026-09-13 21:20:05 -05:00 by kiyi · 0 comments
Collaborator

Goal and deployment hold

Make GitchAlerts usable by self-hosters who supply an empty PostgreSQL database: the documented normal startup must initialize the schema without manual Prisma baselining. Existing installations must continue to upgrade safely.

The owner requested that dev deployment testing remain paused until this fix is completed, released upstream, and incorporated into the Homelab/GitchAlerts deployment bundle. Implementation will be done by the owner in a separate project. This issue tracks the application fix and the downstream bundle follow-through; it does not authorize a production cutover or database reset.

Confirmed defect in v0.12.2

Upstream source: https://git.gitchegumi.com/gitchegumi/GitchAlerts

Prisma applies migration directories in name order. The earliest migration, 20250608000000_add_linked_accounts, creates linked_accounts and adds a foreign key referencing users(id). The initial migration directory is dated 20260531230000, so it runs later. A completely empty database does not have users when that foreign key is applied.

The bundle runs prisma migrate deploy before starting application services. Its current migration runbook works around this by creating the current schema with db push and marking historical migrations applied, only for a verified-empty dev database. Ordinary self-hosters should not need this procedure.

The ordering defect was verified from the v0.12.2 source. Audit and execute the entire migration sequence: do not assume fixing this first failure proves every later migration works. This issue does not claim a new live empty-database failure was reproduced during issue creation.

Scope

  • Reproduce the failure against a disposable empty PostgreSQL database using the released application's normal migration/startup path.
  • Audit migration ordering, table dependencies, duplicate objects and migration-history compatibility; select and document a safe fresh-install strategy.
  • Preserve existing installation histories. Do not simply rename, delete or rewrite migrations that deployed databases may already record without a tested compatibility plan.
  • Keep fresh initialization automatic and repeatable. Do not require operators to run db push, migrate resolve, reset, or hand-written schema SQL for a normal new installation.
  • Never infer that an existing database is disposable merely because _prisma_migrations is missing or empty. Unknown or partially initialized states must fail clearly rather than silently mark migrations applied.
  • Keep one migration owner per deployment. Web, ingress and worker must not independently race schema setup; dependent services must not start against an incomplete schema.
  • Log migration start, meaningful progress, success and actionable failures to normal container output. Propagate a nonzero exit on failure; do not print connection strings, passwords, tokens or stored data.

The solution should work for ordinary self-hosted/Compose installs as well as UDS. Avoid making this a Kubernetes-only workaround.

Acceptance tests

  • Empty database: normal documented startup creates the complete schema and migration history, creates expected bootstrap records, and reaches healthy application startup without manual commands beyond normal installation.
  • Verify first login/bootstrap, workspace creation, an overlay and a manual test alert on a fresh installation.
  • Repeat startup and migration execution: no duplicate bootstrap records, destructive operations or unintended migration replay.
  • Existing v0.12.2 database: upgrade preserves representative users, workspaces, linked accounts, encrypted integration credentials, display keys and asset references; retained keys can still decrypt existing values.
  • Database created using the currently documented db-push/migrate-resolve baseline: upgrade also succeeds. Test this separately if its recorded history differs from the existing-install fixture.
  • Partial/failed/unknown migration state: clear actionable error, no silent adoption or data deletion, and dependent services remain gated.
  • Supported PostgreSQL versions are documented and covered by automated tests. Homelab source was 17.11 and the shared destination is 18.6; exercise PostgreSQL 17 and 18 compatibility for this upgrade.
  • CI exercises both fresh installation and existing-database upgrade with disposable data. Test the packaged production image/startup path, not only source-level SQL.

Release and bundle follow-through

  • Link the upstream implementation PR and its passing test evidence here.
  • Publish an upstream release and immutable application images containing the fix; record release notes and any upgrade requirements.
  • Update Homelab/GitchAlerts's image lock/pins, package and bundle version, and startup commands if the supported entrypoint changes. Preserve the single-migrator gate and existing admission fixes.
  • Update upstream self-hosting documentation and the Homelab/GitchAlerts bundle runbook to remove the manual fresh-database baseline prerequisite once the new release supports normal initialization.
  • Run bundle validation/security checks and publish a new signed bundle. Record the exact release tag/digests here.
  • Only then resume dev deployment against its separate empty database and record acceptance results. Production cutover remains a separate decision.

Deployment hold and downstream tracking

Dev deployment testing is paused at the owner’s request until the upstream fix is released and the deployment bundle consumes it. Dev is intended to start with an empty database; restoring production data is not a substitute for fresh-install coverage. End-to-end dev acceptance remains pending.

Originally filed in the bundle repository as Homelab/GitchAlerts#9; this source-repository issue supersedes it. Downstream migration tracking: Homelab/GitchAlerts#1 and Homelab/platform#28.

## Goal and deployment hold Make GitchAlerts usable by self-hosters who supply an empty PostgreSQL database: the documented normal startup must initialize the schema without manual Prisma baselining. Existing installations must continue to upgrade safely. The owner requested that **dev deployment testing remain paused until this fix is completed, released upstream, and incorporated into the Homelab/GitchAlerts deployment bundle**. Implementation will be done by the owner in a separate project. This issue tracks the application fix and the downstream bundle follow-through; it does not authorize a production cutover or database reset. ## Confirmed defect in v0.12.2 Upstream source: https://git.gitchegumi.com/gitchegumi/GitchAlerts Prisma applies migration directories in name order. The earliest migration, [20250608000000_add_linked_accounts](https://git.gitchegumi.com/gitchegumi/GitchAlerts/src/tag/v0.12.2/packages/database/prisma/migrations/20250608000000_add_linked_accounts/migration.sql), creates linked_accounts and adds a foreign key referencing users(id). The initial migration directory is dated 20260531230000, so it runs later. A completely empty database does not have users when that foreign key is applied. The bundle runs prisma migrate deploy before starting application services. Its [current migration runbook](https://git.gitchegumi.com/Homelab/GitchAlerts/src/branch/main/docs/migration.md) works around this by creating the current schema with db push and marking historical migrations applied, only for a verified-empty dev database. Ordinary self-hosters should not need this procedure. The ordering defect was verified from the v0.12.2 source. Audit and execute the entire migration sequence: do not assume fixing this first failure proves every later migration works. This issue does not claim a new live empty-database failure was reproduced during issue creation. ## Scope - Reproduce the failure against a disposable empty PostgreSQL database using the released application's normal migration/startup path. - Audit migration ordering, table dependencies, duplicate objects and migration-history compatibility; select and document a safe fresh-install strategy. - Preserve existing installation histories. Do not simply rename, delete or rewrite migrations that deployed databases may already record without a tested compatibility plan. - Keep fresh initialization automatic and repeatable. Do not require operators to run db push, migrate resolve, reset, or hand-written schema SQL for a normal new installation. - Never infer that an existing database is disposable merely because _prisma_migrations is missing or empty. Unknown or partially initialized states must fail clearly rather than silently mark migrations applied. - Keep one migration owner per deployment. Web, ingress and worker must not independently race schema setup; dependent services must not start against an incomplete schema. - Log migration start, meaningful progress, success and actionable failures to normal container output. Propagate a nonzero exit on failure; do not print connection strings, passwords, tokens or stored data. The solution should work for ordinary self-hosted/Compose installs as well as UDS. Avoid making this a Kubernetes-only workaround. ## Acceptance tests - [ ] Empty database: normal documented startup creates the complete schema and migration history, creates expected bootstrap records, and reaches healthy application startup without manual commands beyond normal installation. - [ ] Verify first login/bootstrap, workspace creation, an overlay and a manual test alert on a fresh installation. - [ ] Repeat startup and migration execution: no duplicate bootstrap records, destructive operations or unintended migration replay. - [ ] Existing v0.12.2 database: upgrade preserves representative users, workspaces, linked accounts, encrypted integration credentials, display keys and asset references; retained keys can still decrypt existing values. - [ ] Database created using the currently documented db-push/migrate-resolve baseline: upgrade also succeeds. Test this separately if its recorded history differs from the existing-install fixture. - [ ] Partial/failed/unknown migration state: clear actionable error, no silent adoption or data deletion, and dependent services remain gated. - [ ] Supported PostgreSQL versions are documented and covered by automated tests. Homelab source was 17.11 and the shared destination is 18.6; exercise PostgreSQL 17 and 18 compatibility for this upgrade. - [ ] CI exercises both fresh installation and existing-database upgrade with disposable data. Test the packaged production image/startup path, not only source-level SQL. ## Release and bundle follow-through - [ ] Link the upstream implementation PR and its passing test evidence here. - [ ] Publish an upstream release and immutable application images containing the fix; record release notes and any upgrade requirements. - [ ] Update Homelab/GitchAlerts's image lock/pins, package and bundle version, and startup commands if the supported entrypoint changes. Preserve the single-migrator gate and existing admission fixes. - [ ] Update upstream self-hosting documentation and the Homelab/GitchAlerts bundle runbook to remove the manual fresh-database baseline prerequisite once the new release supports normal initialization. - [ ] Run bundle validation/security checks and publish a new signed bundle. Record the exact release tag/digests here. - [ ] Only then resume dev deployment against its separate empty database and record acceptance results. Production cutover remains a separate decision. ## Deployment hold and downstream tracking Dev deployment testing is paused at the owner’s request until the upstream fix is released and the deployment bundle consumes it. Dev is intended to start with an empty database; restoring production data is not a substitute for fresh-install coverage. End-to-end dev acceptance remains pending. Originally filed in the bundle repository as [Homelab/GitchAlerts#9](https://git.gitchegumi.com/Homelab/GitchAlerts/issues/9); this source-repository issue supersedes it. Downstream migration tracking: [Homelab/GitchAlerts#1](https://git.gitchegumi.com/Homelab/GitchAlerts/issues/1) and [Homelab/platform#28](https://git.gitchegumi.com/Homelab/platform/issues/28).
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gitchegumi/GitchAlerts#182
No description provided.