Skip to content

Move .env ownership to this repo and default CDC to pgoutput - #74

Open
DmitriiAn wants to merge 3 commits into
mainfrom
feat/central-jobs-env
Open

Move .env ownership to this repo and default CDC to pgoutput#74
DmitriiAn wants to merge 3 commits into
mainfrom
feat/central-jobs-env

Conversation

@DmitriiAn

@DmitriiAn DmitriiAn commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

~/.env is now owned by this repo instead of the provisioning templates, and every remaining hardcoded tunable moves into it. CDC defaults to the pgoutput plugin.

env-template

New file pgcopydb-helpers/env-template is the reference ~/.env. On the instance:

cp ~/env-template ~/.env
chmod 600 ~/.env

It cannot be named .env in the repo. .gitignore blocks that name to keep credentials out of git, and the templates deploy with cp -r pgcopydb-helpers/* /home/ubuntu/, where the shell glob does not match dotfiles. Naming it env-template means it deploys with the scripts and needs no template change.

Tunables moved into ~/.env

Variable Default Was
TABLE_JOBS 8 already moved, earlier in this PR
INDEX_JOBS 6 already moved, earlier in this PR
SPLIT_TABLES_LARGER_THAN 50GB literal in 3 scripts
OUTPUT_PLUGIN pgoutput literal wal2json in 3 scripts
FILTER_FILE ~/filters.ini literal in 5 scripts

run-migration.sh, resume-migration.sh and resume-cdc.sh now log the effective plugin, jobs, split size and filter path to migration.log.

pgoutput

planetscale/pgcopydb#58 adds the pgoutput plugin and makes it the pgcopydb default. This PR follows it. pgoutput is part of PostgreSQL core, so the source server needs no extension, and it sends about 4.5x less network volume than wal2json. Set OUTPUT_PLUGIN=wal2json to keep the previous plugin.

drop-replication-slots.sh also drops the source publication now. pgcopydb creates one named after the replication slot for pgoutput, so without this it is left behind on the source after every migration. The drop needs ownership of the publication, so the script warns and continues on failure.

Templates

The three templates no longer create ~/.env. pgcopydb-templates/README.md now gives the cp ~/env-template ~/.env steps.

Missing .env guard

No template creates ~/.env any more, so a fresh instance has none. Every script that sources it failed with a raw shell error:

/home/ubuntu/preflight-check.sh: line 21: /home/ubuntu/.env: No such file or directory

verify-migration.sh already guarded this. The same check is now in the other 13 scripts:

ERROR: ~/.env not found. Create it from the template:
  cp ~/env-template ~/.env && chmod 600 ~/.env

Docs

pgcopydb-helpers/README.md and AGENTS.md are rewritten around the env-template flow, each with a single configuration table and an output-plugin section.

Tests

No automated suite in this repo. Checked manually:

  • bash -n on all helper scripts and both terraform templates: pass.
  • shellcheck -S error on all helper scripts: clean, apart from the pre-existing SC2148 in filters-lib.sh.
  • cfn-lint on the CloudFormation template: exit 0, no output.
  • Env resolution smoke test: FILTER_FILE=~/filters.ini expands correctly through set -a; source, and defaults apply with an empty .env.
  • Missing-.env guard: exits 1 with the message above.

DmitriiAn and others added 3 commits August 12, 2026 11:31
Add pgcopydb-helpers/env-template as the reference ~/.env. The user copies
it to ~/.env on the migration instance. The provisioning templates no longer
create that file.

The file cannot be named .env here: .gitignore blocks the name to keep
credentials out of git, and the templates deploy with
"cp -r pgcopydb-helpers/* /home/ubuntu/", where the shell glob does not
match dotfiles.

Move the remaining hardcoded tunables into ~/.env:

- OUTPUT_PLUGIN, new, default pgoutput. planetscale/pgcopydb#58 adds the
  pgoutput plugin and makes it the pgcopydb default. It is part of
  PostgreSQL core, so the source server needs no extension. Set
  OUTPUT_PLUGIN=wal2json to keep the previous plugin.
- SPLIT_TABLES_LARGER_THAN, default 50GB, was a literal in three scripts.
- FILTER_FILE, default ~/filters.ini, was a literal in five scripts.

run-migration.sh, resume-migration.sh and resume-cdc.sh now log the
effective plugin, jobs, split size and filter path to migration.log.

drop-replication-slots.sh also drops the source publication. pgcopydb
creates one named after the replication slot for pgoutput, so without this
it is left behind on the source after every migration. The drop needs
ownership of the publication, so the script warns and continues on failure.

Every script that sources ~/.env now checks the file exists first and
prints the cp command if it does not. Without a guard the scripts failed
with a raw "No such file or directory" from the shell, which is reachable
now that no template creates the file.

Checked with bash -n and shellcheck on the helper scripts and the terraform
templates, and cfn-lint on the CloudFormation template.
@teknogeek0 teknogeek0 changed the title Read TABLE_JOBS/INDEX_JOBS from ~/.env Move .env ownership to this repo and default CDC to pgoutput Aug 27, 2026
@teknogeek0
teknogeek0 marked this pull request as ready for review August 27, 2026 19:48
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.

2 participants