Skip to content

chore: dev from dump improvement#1131

Open
chedieck wants to merge 6 commits into
masterfrom
chore/dev-from-dump-improvement
Open

chore: dev from dump improvement#1131
chedieck wants to merge 6 commits into
masterfrom
chore/dev-from-dump-improvement

Conversation

@chedieck
Copy link
Copy Markdown
Collaborator

@chedieck chedieck commented Jun 2, 2026

Description

  • Fix make dev-from-dump workflow to spin up a local dev env with a prod database dump
  • Named Docker volume for DB so the long import only happens once
  • pv progress bar during dump import
  • Skips prisma migrations (uses migrate deploy since dump already has schema + migration history)
  • Skips cache rebuild in dev-from-dump (prevents MariaDB I/O saturation)
  • Pages load in seconds instead of hanging for minutes with prod-sized data

New make targets

  • make stop-dev-from-dump — stop without losing DB
  • make reset-dev-from-dump — full restart
  • make reset-dev-from-dump-keep-db — restart dev container only, DB stays
  • make nuke-dev-from-dump — destroy everything including DB volume

Remarks

  • Requires a dump.sql in the repo root (from mariadb-dump on prod)
  • First run takes 15-30 min (importing 2.6GB dump). Subsequent runs are instant

Test Plan

  1. Place a prod dump.sql in root
  2. make dev-from-dump — watch db logs for pv progress
  3. Once done, navigate to localhost:3000 — dashboard, payments, buttons, wallets should all load within seconds
  4. make stop-dev-from-dump && make dev-from-dump — should skip import (instant start)
  5. make nuke-dev-from-dump && make dev-from-dump — should reimport from scratch

Summary by CodeRabbit

Release Notes

  • Chores

    • Added development infrastructure and commands to support database dump-based development workflows with new Docker Compose configuration
    • Enhanced database import process with progress tracking and optimized file handling
    • Updated build dependencies
  • Performance

    • Optimized cache rebuild behavior to reduce unnecessary cache initialization when loading from database dumps

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

Warning

Review limit reached

@chedieck, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 59 minutes and 2 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2eb65ce5-0fa3-47f8-8c67-722cb0242f37

📥 Commits

Reviewing files that changed from the base of the PR and between 18879a6 and 85a2ba2.

📒 Files selected for processing (8)
  • .env.from-dump
  • .gitignore
  • Makefile
  • docker-compose-from-dump.yml
  • redis/paymentCache.ts
  • scripts/db-entrypoint.sh
  • scripts/db/Dockerfile
  • scripts/paybutton-server-start.sh
📝 Walkthrough

Walkthrough

This PR introduces a new development workflow mode called "dev-from-dump" that allows developers to initialize the application state from database dumps rather than running seeds. It includes orchestration targets, dump-aware database import logic with progress tracking, and application behavior that adapts to skip cache rebuilds and run production-style migrations.

Changes

Dev-from-dump Development Workflow

Layer / File(s) Summary
Environment and orchestration setup
.env.from-dump, Makefile, docker-compose-from-dump.yml, .gitignore
Defines FROM_DUMP=true and SKIP_CACHE_REBUILD=true environment variables. Adds stop-dev-from-dump, reset-dev-from-dump, reset-dev-from-dump-keep-db, and nuke-dev-from-dump Make targets that orchestrate Docker Compose runs using docker-compose-from-dump.yml. Docker Compose now defines a named volume paybutton-dump-db-data and mounts it to persist /var/lib/mysql across container lifecycle. Adds .forever to .gitignore.
Database dump import infrastructure
scripts/db/Dockerfile, scripts/db-entrypoint.sh
Installs pv tool in database image. Entrypoint script separates handling of dump vs. non-dump SQL files: dumps are symlinked without variable substitution, while regular SQL files are processed with envsubst. During import, dump files are streamed through pv with size reporting via stat and numfmt for progress visibility; non-dump files use direct input redirection.
Application behavior for FROM_DUMP mode
scripts/paybutton-server-start.sh, redis/paymentCache.ts
Prisma setup treats FROM_DUMP=true like production: runs prisma migrate deploy and prisma generate instead of prisma migrate dev and seed. Refactors pm2 startup so jobs and WSServer always start after Prisma, with only next selection dependent on ENVIRONMENT. Payment cache rebuild is conditionally skipped when SKIP_CACHE_REBUILD is set: getPaymentList, initPaymentCache, and getPaymentStream all guard rebuild logic behind process.env.SKIP_CACHE_REBUILD === undefined.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • PayButton/paybutton-server#1111: Both PRs modify scripts/paybutton-server-start.sh to update Prisma migration behavior by running prisma migrate deploy followed by prisma generate in the production/from-dump path.

Suggested labels

enhancement (development)

Suggested reviewers

  • Fabcien

Poem

🐰 A rabbit now dumps and restarts with flair,
No seeds, just snapshots—the data's all there!
Cache rebuilds pause when the dump flag appears,
And pv streams proudly with progress that cheers! 📊

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'chore: dev from dump improvement' is vague and generic, using non-descriptive phrasing that doesn't convey the specific nature of the changes (workflow fix, Docker volume, cache skip, performance improvement). Consider a more specific title such as 'chore: optimize dev-from-dump workflow with persistent DB volume and cache skip' to better describe the primary improvements.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description comprehensively covers the PR intent, changes, new make targets, requirements, and test plan, closely following the repository template structure with clear sections for Description, Test Plan, and Remarks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/dev-from-dump-improvement

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docker-compose-from-dump.yml (1)

10-11: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Include the base .env/.env.local in paybutton (or ensure prod loads dotenv)

  • docker-compose-from-dump.yml sets paybutton to only env_file: - .env.from-dump, while scripts/paybutton-server-start.sh sources .env / .env.local in sh.
  • .env uses plain KEY=... assignments (no export), so those values aren’t reliably inherited by PM2 child processes.
  • yarn prisma and the dev/init scripts load .env via dotenv-cli, but ENVIRONMENT=production runs yarn prod, which does not load dotenv; .env.local overrides also won’t be applied to those children.
Suggested fix
   env_file:
+    - .env
+    - .env.local
     - .env.from-dump
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker-compose-from-dump.yml` around lines 10 - 11, The paybutton service
only references .env.from-dump which causes production children (PM2 / yarn prod
started by scripts/paybutton-server-start.sh) to miss variables from
.env/.env.local; update the paybutton docker-compose service to include the base
env files (add .env and .env.local to env_file alongside .env.from-dump) or
ensure the startup script/supervisor (scripts/paybutton-server-start.sh / the
PM2 start command invoked) explicitly loads dotenv before launching yarn prod so
that non-exported KEY= values are available to child processes; locate the
paybutton service block in docker-compose-from-dump.yml and the startup in
scripts/paybutton-server-start.sh to apply the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@redis/paymentCache.ts`:
- Around line 33-40: The current guard around cache warmup in getPaymentList
prevents the per-address lazy initialization when SKIP_CACHE_REBUILD is set,
causing a first-run cache miss to return an empty payment list; change the logic
so SKIP_CACHE_REBUILD only disables the bulk/warmup path but still iterates
getUserUncachedAddresses and calls CacheSet.addressCreation for each address (so
the DB-backed lazy path runs), updating the same behavior in the corresponding
getPaymentStream area (the code referencing getUserUncachedAddresses,
CacheSet.addressCreation, getCachedPaymentsForUser/getPaymentStream) to ensure
uncached addresses fallback to MariaDB rather than producing an empty result.

In `@scripts/db/Dockerfile`:
- Around line 5-6: The Dockerfile's RUN line uses "apt-get update || echo" and
"apt-get install -y gettext pv || echo" which hides failures and lets the image
build without envsubst/pv causing runtime errors in scripts/db-entrypoint.sh;
remove the "|| echo" fallbacks and make the RUN step fail on error (so apt-get
update and apt-get install return non-zero on failure), ensuring missing
packages like gettext (envsubst) and pv cause the build to fail early and
visibly.

---

Outside diff comments:
In `@docker-compose-from-dump.yml`:
- Around line 10-11: The paybutton service only references .env.from-dump which
causes production children (PM2 / yarn prod started by
scripts/paybutton-server-start.sh) to miss variables from .env/.env.local;
update the paybutton docker-compose service to include the base env files (add
.env and .env.local to env_file alongside .env.from-dump) or ensure the startup
script/supervisor (scripts/paybutton-server-start.sh / the PM2 start command
invoked) explicitly loads dotenv before launching yarn prod so that non-exported
KEY= values are available to child processes; locate the paybutton service block
in docker-compose-from-dump.yml and the startup in
scripts/paybutton-server-start.sh to apply the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2ab7adb4-4c1c-4e91-a31f-c56f99442413

📥 Commits

Reviewing files that changed from the base of the PR and between 7d4e91d and 18879a6.

📒 Files selected for processing (8)
  • .env.from-dump
  • .gitignore
  • Makefile
  • docker-compose-from-dump.yml
  • redis/paymentCache.ts
  • scripts/db-entrypoint.sh
  • scripts/db/Dockerfile
  • scripts/paybutton-server-start.sh

Comment thread redis/paymentCache.ts
Comment on lines 33 to 40
export const getPaymentList = async (userId: string): Promise<Payment[]> => {
const uncachedAddressStream = getUserUncachedAddresses(userId)
for await (const address of uncachedAddressStream) {
void await CacheSet.addressCreation(address)
if (process.env.SKIP_CACHE_REBUILD === undefined) {
const uncachedAddressStream = getUserUncachedAddresses(userId)
for await (const address of uncachedAddressStream) {
void await CacheSet.addressCreation(address)
}
}
return await getCachedPaymentsForUser(userId)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Don't turn first-run cache misses into empty payment history.

With SKIP_CACHE_REBUILD=true in .env.from-dump and a fresh Redis container in docker-compose-from-dump.yml, the first dev-from-dump boot has no payment cache yet. These guards now skip both the eager rebuild and the per-address lazy init, so getPaymentList / getPaymentStream can return zero payments for real production data instead of falling back to MariaDB.

Keep the bulk warmup disabled if needed, but uncached addresses still need a lazy DB-backed path.

Also applies to: 309-323

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@redis/paymentCache.ts` around lines 33 - 40, The current guard around cache
warmup in getPaymentList prevents the per-address lazy initialization when
SKIP_CACHE_REBUILD is set, causing a first-run cache miss to return an empty
payment list; change the logic so SKIP_CACHE_REBUILD only disables the
bulk/warmup path but still iterates getUserUncachedAddresses and calls
CacheSet.addressCreation for each address (so the DB-backed lazy path runs),
updating the same behavior in the corresponding getPaymentStream area (the code
referencing getUserUncachedAddresses, CacheSet.addressCreation,
getCachedPaymentsForUser/getPaymentStream) to ensure uncached addresses fallback
to MariaDB rather than producing an empty result.

Comment thread scripts/db/Dockerfile
Comment on lines 5 to +6
RUN apt-get update || echo && \
apt-get install -y gettext || echo
apt-get install -y gettext pv || echo
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail the image build when gettext/pv installation fails.

The || echo clauses swallow apt-get failures, so this image can build without envsubst or pv and then fail much later inside scripts/db-entrypoint.sh. That makes the dump workflow flaky and much harder to diagnose.

Suggested fix
-RUN apt-get update || echo && \
-      apt-get install -y gettext pv || echo
+RUN apt-get update && \
+      apt-get install -y --no-install-recommends gettext pv && \
+      rm -rf /var/lib/apt/lists/*
🧰 Tools
🪛 Trivy (0.69.3)

[error] 5-6: 'apt-get' missing '--no-install-recommends'

'--no-install-recommends' flag is missed: 'apt-get update || echo && apt-get install -y gettext pv || echo'

Rule: DS-0029

Learn more

(IaC/Dockerfile)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/db/Dockerfile` around lines 5 - 6, The Dockerfile's RUN line uses
"apt-get update || echo" and "apt-get install -y gettext pv || echo" which hides
failures and lets the image build without envsubst/pv causing runtime errors in
scripts/db-entrypoint.sh; remove the "|| echo" fallbacks and make the RUN step
fail on error (so apt-get update and apt-get install return non-zero on
failure), ensuring missing packages like gettext (envsubst) and pv cause the
build to fail early and visibly.

@Klakurka Klakurka requested a review from Fabcien June 2, 2026 13:11
Comment thread scripts/db/Dockerfile
@@ -3,7 +3,7 @@ FROM mariadb:latest
RUN mkhomedir_helper mysql

RUN apt-get update || echo && \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand the use of || echo here, if the goal is to avoid failures then || true seems more appropriated

Comment thread scripts/db-entrypoint.sh Outdated
for file in *.sql; do
mariadb -u root -p"$MYSQL_ROOT_PASSWORD" < "$file"
if [[ "$file" == *dump* ]]; then
filesize=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file" 2>/dev/null)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the second part of the subcommand stat -f%z, what does this do ?

Comment thread scripts/paybutton-server-start.sh Outdated
if [ "$ENVIRONMENT" = "production" ]; then
pm2 start yarn --time --interpreter ash --name next --output logs/next.log --error logs/next.log -- prod || exit 1
else
pm2 start yarn --time --interpreter ash --name next --output logs/next.log --error logs/next.log -- dev || exit 1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unreachable, you're already in a if [ "$ENVIRONMENT" = "production" ]; branch
Edit: I see this is fixed in the follow up commit. Better squash in this case to make the review easier

Comment thread .gitignore
paybutton-config.json

dump.sql*
.forever
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, what is this?

@chedieck chedieck force-pushed the chore/dev-from-dump-improvement branch from 18879a6 to 85a2ba2 Compare June 2, 2026 18:50
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