-
Notifications
You must be signed in to change notification settings - Fork 10
fix: pushkin-prep should gracefully handle containers already existing and non-Pushkin templates #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix: pushkin-prep should gracefully handle containers already existing and non-Pushkin templates #372
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7465a5f
Fix: Auto-cleanup existing database containers before running prep
claude b46d185
log the warning if this check fails for a reason other than grep find…
becky-gilbert 0bc9e5f
fix undefined var e in catch block (pre-existing bug)
becky-gilbert 55c4cb3
switch from compose stop/rm to down - same thing but also removes nam…
becky-gilbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -336,18 +336,70 @@ export async function migrateTransactionsDB(coreDBs, verbose) { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures a clean state by detecting and removing existing database containers | ||
| * This prevents issues with stale containers that may have different credentials | ||
| * @param {boolean} verbose Output extra debugging info | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async function ensureCleanState(verbose) { | ||
| if (verbose) console.log("--verbose flag set inside ensureCleanState()"); | ||
|
|
||
| try { | ||
| // Check if database containers are running or stopped | ||
| const { stdout } = await exec( | ||
| `docker ps -a --format "{{.Names}}" | grep -E "pushkin[-_](test_db|test_transaction_db)[-_]"` | ||
| ); | ||
|
|
||
| if (stdout.trim()) { | ||
| // Found existing containers - clean them up | ||
| console.log('⚠️ Found existing database containers. Cleaning up...'); | ||
|
|
||
| const dockerPath = path.join(process.cwd(), "pushkin"); | ||
| const dockerConfig = "docker-compose.dev.yml"; | ||
|
|
||
| try { | ||
| // Remove containers and named volumes so new containers start with fresh credentials | ||
| await compose.down({ | ||
| cwd: dockerPath, | ||
| config: dockerConfig, | ||
| commandOptions: ["--volumes"], // removes named volumes (e.g. test_transaction_db_volume) | ||
| }); | ||
| } catch (err) { | ||
| if (verbose) console.warn("Warning removing containers:", err.message); | ||
| } | ||
|
|
||
| console.log('✓ Cleanup complete. Starting fresh databases...'); | ||
| } else { | ||
| if (verbose) console.log("No existing database containers found. Proceeding with fresh setup."); | ||
| } | ||
| } catch (e) { | ||
| // If grep finds nothing, it returns exit code 1, which throws an error | ||
| // This is expected when no containers exist, so we can safely ignore it | ||
| if (e.code === 1 && e.stderr === '') { | ||
| if (verbose) console.log("No existing database containers found (grep returned no matches)."); | ||
| } else { | ||
| // Actual error - log it but don't fail the entire setup | ||
| console.warn("Warning: Could not check for existing containers:", e.message); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export async function setupdb(coreDBs, mainExpDir, verbose) { | ||
| if (verbose) console.log("--verbose flag set inside setupdb()"); | ||
| // load up all migrations for same dbs to be run at same time (knex requires this) | ||
|
|
||
| // Ensure clean state before starting databases | ||
| await ensureCleanState(verbose); | ||
|
|
||
| let dbPromise; | ||
| if (verbose) console.log("Spooling up databases."); | ||
| try { | ||
| dbPromise = compose.upMany(["test_db", "test_transaction_db"], { | ||
| cwd: path.join(process.cwd(), "pushkin"), | ||
| config: "docker-compose.dev.yml", | ||
| }); | ||
| } catch { | ||
| } catch (e) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bug wasn't introduced here, just cleaning it up anyway! |
||
| console.error("something went wrong starting database containers."); | ||
| throw e; | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -v flag on


compose.rmonly removes anonymous volumes, so I switched fromcompose.stop/compose.rmtocompose.downin order to also remove named volumes:pushkin_test_db_volume,pushkin_test_transaction_db_volume. I ran into the same "password authentication failed" error with the original fix on this branch, which was because my test volumes survived the slate-cleaning process. The new container mounted the the old volume, which contained the PostgreSQL data directory with the old password.The original fix did work for me before, but that was probably because either those named volumes hadn't been created yet or I'd cleared them.
Volume auth error before this change:
After: