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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: prevent shell and provisioning paths from changing database mode (#8804)
[._.]/ Adam Eivy621b701857a5
diff --git a/docs/BACKUP.md b/docs/BACKUP.mdindex d903b2ebcb..6f2f93a265 100644--- a/docs/BACKUP.md+++ b/docs/BACKUP.md@@ -14,7 +14,8 @@ Implementation: `server/services/backup.js` (snapshot/dump/restore), `server/ser## Database backend migrationMigration and switching between Docker and native PostgreSQL are temporarily-unavailable in Settings. `scripts/db.sh migrate` also refuses. Copying a live database and switching+unavailable in Settings. `scripts/db.sh migrate`, `use-native`, and `use-docker`+also refuse. Native setup provisions without selecting a backend. Copying a live database and switchingmode can strand writes accepted after the snapshot. Backups and standaloneexports remain available; they do not make a new backend authoritative.diff --git a/docs/STORAGE.md b/docs/STORAGE.mdindex a2bb0e7816..2d6e33fb80 100644--- a/docs/STORAGE.md+++ b/docs/STORAGE.md@@ -204,8 +204,8 @@ The escape hatch is **guarded from bitrot by the test suite** (tests boot with `### Moving between Docker and nativeAutomatic backend migration and switching are temporarily unavailable.-The Settings switch/migration requests and `scripts/db.sh migrate` refuse before copying data or-changing mode. The former path could accept writes after its dump snapshot+The Settings switch/migration requests and `scripts/db.sh migrate`,+`use-native`, and `use-docker` refuse before copying data or changing mode. The former path could accept writes after its dump snapshotand strand them on the source; changing `.env` also leaves the running serverconnected to its original pool.@@ -216,8 +216,8 @@ that the restarted server actually uses the target. A server-only restart ora saved-mode change is not that verification. Do not use Sync followed by Switchas a migration workaround.-`scripts/db.sh setup-native` selects native mode after provisioning; it does-not copy Docker data. Preserve the backend holding your records. If an earlier+`scripts/db.sh setup-native` provisions native PostgreSQL without selecting it+or copying Docker data. Fresh-install setup still selects its configured mode. Preserve the backend holding your records. If an earliermigration already ran, keep both databases and its dump intact: the old sourcemay contain writes missing from the target. Do not destroy either backend orreverse the migration before comparing and recovering those records.diff --git a/scripts/db-migrate.test.js b/scripts/db-migrate.test.jsindex 6cfffa3692..c7131eea81 100644--- a/scripts/db-migrate.test.js+++ b/scripts/db-migrate.test.js@@ -68,6 +68,7 @@ describe.skipIf(process.platform === 'win32')('scripts/db.sh export + migrate',writeStub(binDir, 'pg_isready', '#!/bin/sh\nexit 0\n');// Not Darwin, so db.sh skips prepending Homebrew's real Postgres to PATH.writeStub(binDir, 'uname', '#!/bin/sh\necho Linux\n');+ writeStub(binDir, 'whoami', '#!/bin/sh\necho example_user\n');stubLog = join(root, 'stub.log');importLog = join(root, 'import.log');envFile = join(root, '.env');@@ -133,16 +134,28 @@ describe.skipIf(process.platform === 'win32')('scripts/db.sh export + migrate',expect(tempArtifacts()).toEqual([]);});- it.each(['docker', 'native'])('refuses repeated %s migrations before any database command', (mode) => {+ it.each(['docker', 'native'])('refuses all cutover commands in %s mode before any database command', (mode) => {writeFileSync(envFile, `PGMODE=${mode}\n`);for (let attempt = 0; attempt < 2; attempt++) {- const result = run(['migrate'], 'ok');- expect(result.status).not.toBe(0);- expect(result.stderr).toMatch(/migration is temporarily unavailable/);- expect(readFileSync(stubLog, 'utf8')).toBe('');- expect(existsSync(importLog)).toBe(false);- expect(existsSync(dumpDir)).toBe(false);- expect(readFileSync(envFile, 'utf8')).toBe(`PGMODE=${mode}\n`);+ for (const command of ['migrate', 'use-native', 'use-docker']) {+ const result = run([command], 'ok');+ expect(result.status).not.toBe(0);+ expect(result.stderr).toMatch(/migration and switching are temporarily unavailable/);+ expect(readFileSync(stubLog, 'utf8')).toBe('');+ expect(existsSync(importLog)).toBe(false);+ expect(existsSync(dumpDir)).toBe(false);+ expect(readFileSync(envFile, 'utf8')).toBe(`PGMODE=${mode}\n`);+ }}});++ it('provisions native PostgreSQL without selecting it or stopping Docker', () => {+ const result = run(['setup-native'], 'ok');+ expect(result.status).toBe(0);+ expect(readFileSync(envFile, 'utf8')).toBe('PGMODE=docker\n');+ const log = readFileSync(stubLog, 'utf8');+ expect(log).toContain('--single-transaction');+ expect(log).not.toMatch(/SOURCE_STOP|docker compose stop/);+ expect(result.stdout).toContain('selected mode is unchanged');+ });});diff --git a/scripts/db.sh b/scripts/db.shindex a0956f84a0..cf0ce00729 100755--- a/scripts/db.sh+++ b/scripts/db.sh@@ -15,8 +15,8 @@# stop Stop the database# fix Fix common issues (stale pid files, etc.)# setup-native Install and configure native PostgreSQL via Homebrew-# use-docker Switch to Docker mode-# use-native Switch to native mode+# use-docker Unavailable pending coordinated offline cutover+# use-native Unavailable pending coordinated offline cutover# migrate Unavailable pending coordinated offline cutover# export Export database to a SQL dump file# import Import a SQL dump file into the database@@ -45,16 +45,6 @@ warn() { echo -e "${YELLOW}⚠️ $1${NC}"; }err() { echo -e "${RED}❌ $1${NC}"; }info() { echo -e "${BLUE}🗄️ $1${NC}"; }-# Portable in-place sed helper (works with BSD and GNU sed)-inplace_sed() {- local script="$1"- local file="$2"- local tmp- tmp="$(mktemp "${file}.XXXXXX")" || return 1- sed "$script" "$file" >"$tmp"- mv "$tmp" "$file"-}-# Detect current mode from .env or default to dockerget_mode() {if [ -f "$ENV_FILE" ]; then@@ -79,23 +69,6 @@ get_port() {PGPORT=$(get_port)-# Set mode in .env-set_mode() {- local mode="$1"- if [ -f "$ENV_FILE" ]; then- if grep -q '^PGMODE=' "$ENV_FILE"; then- inplace_sed "s/^PGMODE=.*/PGMODE=$mode/" "$ENV_FILE"- else- echo "PGMODE=$mode" >> "$ENV_FILE"- fi- else- echo "PGMODE=$mode" > "$ENV_FILE"- fi- # Update PGPORT to match mode- PGPORT=$([ "$mode" = "native" ] && echo "5432" || echo "5561")- log "Mode set to: $mode (port $PGPORT)"-}-# Check if Docker PostgreSQL is runningdocker_running() {docker ps --filter name=portos-db --format '{{.Status}}' 2>/dev/null | grep -qi "up"@@ -504,16 +477,12 @@ cmd_setup_native() {PGPASSWORD="$PGPASSWORD" psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDATABASE" -v ON_ERROR_STOP=1 --single-transaction -f "$ROOT_DIR/server/scripts/init-db.sql"log "Schema applied"- # Step 6: Switch mode to native- set_mode native-echo ""log "Native PostgreSQL is ready!"info "Using system PostgreSQL on port $PGPORT"info "Database: $PGDATABASE (user: $PGUSER)"- info "Setup selected native mode; Docker data has not been migrated."- warn "Running 'scripts/db.sh migrate' now would copy native data OVER Docker data."- info "Before moving Docker data to native, see docs/STORAGE.md#moving-between-docker-and-native."+ info "Provisioning only: the selected mode is unchanged; Docker data has not been migrated."+ info "Coordinated backend migration is not yet available. Keep using the current backend."}# Run psql command, using Docker exec in Docker mode if host psql is unavailable@@ -611,39 +580,11 @@ cmd_import() {# A process-list probe is not a writer fence. The recoverable coordinator in# #8805 must own admission, explicit endpoints and verified restart first.cmd_migrate() {- err "Database migration is temporarily unavailable: coordinated shutdown and restart are required to preserve writes." >&2+ err "Database migration and switching are temporarily unavailable: coordinated shutdown and restart are required to preserve writes." >&2echo "Keep using the current backend. Backups remain available via scripts/db.sh export." >&2return 1}-# Use Docker mode-cmd_use_docker() {- set_mode docker- info "Switched to Docker mode (port 5561). Run 'scripts/db.sh start' to start."-}--# Use native mode-cmd_use_native() {- if ! has_native_pg; then- err "Native PostgreSQL not installed. Run: scripts/db.sh setup-native"- exit 1- fi- # Verify system pg is reachable- if ! pg_isready -h "$PGHOST" -p 5432 >/dev/null 2>&1; then- warn "System PostgreSQL not running on port 5432"- echo " Start it: brew services start postgresql@17"- fi- # Best-effort stop of Docker DB container- if command -v docker >/dev/null 2>&1 && docker info >/dev/null 2>&1; then- (- cd "$ROOT_DIR"- docker compose stop db >/dev/null 2>&1 || true- )- fi- set_mode native- info "Switched to native mode (port 5432). Run 'scripts/db.sh start' to start."-}-# Show logscmd_logs() {local mode@@ -682,8 +623,8 @@ Commands:logs Tail database logssetup-native Detect/install PostgreSQL, create portos database- use-docker Switch to Docker mode (port 5561)- use-native Switch to native/system mode (port 5432)+ use-docker Unavailable pending coordinated offline cutover+ use-native Unavailable pending coordinated offline cutovermigrate Unavailable pending coordinated offline cutoverexport [label] Export database to data/db-dumps/@@ -703,8 +644,8 @@ case "${1:-help}" instop) cmd_stop ;;fix) cmd_fix ;;setup-native) cmd_setup_native ;;- use-docker) cmd_use_docker ;;- use-native) cmd_use_native ;;+ use-docker) cmd_migrate ;;+ use-native) cmd_migrate ;;migrate) cmd_migrate ;;export) cmd_export "${2:-}" ;;import) cmd_import "${2:?Usage: scripts/db.sh import <file>}" ;;