Skip to content

fix(cli): detect existing pgdata/ subdir when resolving OPENSHIP_PGDATA - #494

Open
santhiprakash wants to merge 1 commit into
oblien:mainfrom
santhiprakash:fix/pgdata-reinstall-487
Open

fix(cli): detect existing pgdata/ subdir when resolving OPENSHIP_PGDATA#494
santhiprakash wants to merge 1 commit into
oblien:mainfrom
santhiprakash:fix/pgdata-reinstall-487

Conversation

@santhiprakash

Copy link
Copy Markdown
Contributor

Summary

Fixes resolvePgData so re-running openship up --compose over an existing Postgres data volume that already has the cluster at /var/lib/postgresql/data/pgdata keeps OPENSHIP_PGDATA pointed at the pgdata/ subdirectory, instead of defaulting to the volume root and causing initdb: error: directory ... exists but is not empty.

Motivation

dbVolumeExists only tells us that the <project>_postgres_data volume exists; it doesn't say where the cluster is inside it. Since the EPERM fix in #350, fresh installs use a pgdata/ subdirectory, but older volumes may still have the cluster at the volume root. The previous code returned the root whenever the volume existed, which broke reinstalls over volumes created with the new subdirectory.

Closes #487.

Changes

  • apps/cli/src/lib/compose.ts
    • Adds pgDataLocation() to inspect the volume: pgdata/PG_VERSIONsubdir, root PG_VERSIONroot, empty → empty, anything else → unknown.
    • resolvePgData() uses the probe to pick the correct OPENSHIP_PGDATA path, and fails loudly when the volume is non-empty but unrecognizable.
    • Updates the OPENSHIP_PGDATA env comment to reflect the new logic.
  • apps/cli/test/unit/compose-pgdata.test.ts (new)
    • 4 unit tests: fresh install, existing pgdata/ cluster, legacy root cluster, and an unrecognizable non-empty volume.

Verification

$ cd /home/ubuntu/Projects/open-source/openship-pgdata-487
$ python3 /home/ubuntu/Projects/open-source/scripts/preflight_ship.py \
    --repo oblien/openship --local openship-pgdata-487 --branch main --issue 487 \
    --file apps/cli/src/lib/compose.ts \
    --must-contain 'return dbVolumeExists(composeProjectName(prev)) ? PGDATA_ROOT : `${PGDATA_ROOT}/pgdata`;' \
    --search 'OPENSHIP_PGDATA in:body'
PREFLIGHT CLEAR — safe to implement against current upstream.

$ bun run --cwd apps/cli lint
$ tsc --noEmit

$ bun run --cwd apps/cli test
 Test Files  28 passed (28)
      Tests  229 passed (229)

Checklist

  • One change per PR — one bug, with nothing unrelated bundled in
  • The diff is scoped — no reformatting or lint fixes on lines I wasn't otherwise changing
  • A test fails without this change and passes with it
  • bun run --cwd apps/cli test and bun run --cwd apps/cli lint pass locally
  • I understand every line of this diff and can explain it in review

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.

OPENSHIP_PGDATA detection picks the volume root when re-installing over an existing pgdata/ subdirectory

1 participant