Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: forward SQL to Docker-only database imports

[._.]/ Adam Eivybd37e7bba4c2
diff --git a/scripts/db-migrate.test.js b/scripts/db-migrate.test.js
index 298a6b449f..51b6e123b8 100644
--- a/scripts/db-migrate.test.js
+++ b/scripts/db-migrate.test.js
@@ -32,7 +32,11 @@ case "$1" in
empty) exit 1 ;;
*) printf '%s' "$FULL_DUMP"; exit 0 ;;
esac ;;
- *psql*) echo IMPORT >> "$STUB_LOG"; cat >> "$IMPORT_LOG"; exit 0 ;;
+ *psql*)
+ echo IMPORT >> "$STUB_LOG"
+ # docker exec forwards stdin only when interactive mode is enabled.
+ case " $* " in *" -i "*) cat >> "$IMPORT_LOG" ;; esac
+ exit 0 ;;
esac ;;
esac
exit 0
@@ -248,6 +252,26 @@ describe.skipIf(process.platform === 'win32')('scripts/db.sh export + migrate',
expect(existsSync(importLog)).toBe(false);
});
+ it('forwards the complete staged replay through Docker when host psql is absent', () => {
+ const isolated = join(root, 'docker-only-bin');
+ mkdirSync(isolated);
+ for (const name of ['bash', 'cat', 'dirname', 'mktemp', 'rm', 'grep', 'cut', 'tr']) {
+ const binary = ['/usr/bin', '/bin'].map(dir => join(dir, name)).find(existsSync);
+ symlinkSync(binary, join(isolated, name));
+ }
+ for (const name of ['node', 'docker', 'uname']) {
+ symlinkSync(join(root, 'bin', name), join(isolated, name));
+ }
+ const dump = join(root, 'docker-import.sql');
+ writeFileSync(dump, FULL_DUMP);
+ const result = run(['import', dump], 'ok', { PATH: isolated });
+ expect(result.status, result.stderr).toBe(0);
+ expect(existsSync(importLog), 'Docker must receive SQL on stdin').toBe(true);
+ expect(readFileSync(importLog, 'utf8')).toBe(FULL_DUMP);
+ expect(result.stdout).toContain('Import complete');
+ expect(readFileSync(dump, 'utf8')).toBe(FULL_DUMP);
+ });
+
it('rejects incomplete endpoints and connection-string database overrides before any database command', () => {
for (const args of [
['--endpoint', 'example.invalid', '6543'],
diff --git a/scripts/db.sh b/scripts/db.sh
index 0f5bda6550..fc68daac77 100755
--- a/scripts/db.sh
+++ b/scripts/db.sh
@@ -579,7 +579,7 @@ run_psql() {
if command -v psql >/dev/null 2>&1; then
PGPASSWORD="$PGPASSWORD" psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDATABASE" "$@"
elif [ "$mode" = "docker" ] && docker_running; then
- docker exec -e PGPASSWORD="$PGPASSWORD" portos-db psql -U "$PGUSER" -d "$PGDATABASE" "$@"
+ docker exec -i -e PGPASSWORD="$PGPASSWORD" portos-db psql -U "$PGUSER" -d "$PGDATABASE" "$@"
else
err "psql not found on host and Docker DB is not running"
exit 1