Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ apps/streams/data/

# Generated by setup.sh
Caddyfile
superset-dev-data/
103 changes: 100 additions & 3 deletions .superset/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,44 @@ NC='\033[0m'
# Step tracking
declare -a FAILED_STEPS=()
declare -a SKIPPED_STEPS=()
FORCE_OVERWRITE_DATA=0

error() { echo -e "${RED}✗${NC} $1"; }
success() { echo -e "${GREEN}✓${NC} $1"; }
warn() { echo -e "${YELLOW}!${NC} $1"; }

print_usage() {
cat <<EOF
Usage: .superset/setup.sh [options]

Options:
-f, --force Reset superset-dev-data/ before seeding local DB
-h, --help Show this help message
EOF
}

parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
-f|--force)
FORCE_OVERWRITE_DATA=1
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
error "Unknown argument: $1"
print_usage
return 1
;;
esac
done

return 0
}

# Track step failure
step_failed() {
FAILED_STEPS+=("$1")
Expand Down Expand Up @@ -332,6 +365,7 @@ step_write_env() {
echo ""
echo "# Workspace Identity"
echo "SUPERSET_WORKSPACE_NAME=${WORKSPACE_NAME:-$(basename "$PWD")}"
echo "SUPERSET_HOME_DIR=$PWD/superset-dev-data"
echo ""
echo "# Workspace Database (Neon Branch)"
if [ -n "${BRANCH_ID:-}" ]; then
Expand Down Expand Up @@ -476,7 +510,65 @@ PORTSJSON
return 0
}

step_seed_local_db() {
echo "💾 Seeding local DB into superset-dev-data/..."

local source_db="$HOME/.superset/local.db"
local dev_data_dir="superset-dev-data"
local dest_db="$dev_data_dir/local.db"
local force_overwrite="$FORCE_OVERWRITE_DATA"

if [ "$force_overwrite" = "1" ] && [ -d "$dev_data_dir" ]; then
warn "Force overwrite enabled — removing existing $dev_data_dir/"
if ! rm -rf "$dev_data_dir"; then
error "Failed to remove existing $dev_data_dir/"
return 1
fi
fi

if [ ! -f "$source_db" ]; then
warn "No source local.db found at $source_db — skipping (app will create a fresh one)"
step_skipped "Seed local DB (no source DB)"
return 0
fi

if [ -f "$dest_db" ] && [ "$force_overwrite" != "1" ]; then
warn "Destination DB already exists at $dest_db — skipping seed (use -f/--force)"
step_skipped "Seed local DB (already exists)"
return 0
fi

mkdir -p "$dev_data_dir"
chmod 700 "$dev_data_dir"

# Copy all SQLite files so WAL data isn't lost when source is held open.
for ext in "" "-shm" "-wal"; do
local source_file="${source_db}${ext}"
local dest_file="${dest_db}${ext}"

if [ -f "$source_file" ]; then
if ! cp "$source_file" "$dest_file"; then
error "Failed to copy $source_file to $dest_file"
return 1
fi
chmod 600 "$dest_file"
fi
done

# Checkpoint the copy's WAL (no lock contention since nothing else has it open).
if command -v sqlite3 &> /dev/null; then
sqlite3 "$dest_db" "PRAGMA wal_checkpoint(TRUNCATE);" &> /dev/null || true
fi
Comment on lines +559 to +561
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 | 🟡 Minor

No feedback when sqlite3 is unavailable — DB may be left with stale WAL and wrong schema.

When sqlite3 is not found, both the WAL checkpoint and migration re-application are silently skipped. The seeded DB could contain uncommitted WAL data and a schema that doesn't match the current branch, which is exactly the scenario the migration loop is meant to fix. A warn here would save debugging time.

Proposed fix
   # Checkpoint the copy's WAL (no lock contention since nothing else has it open)
   if command -v sqlite3 &> /dev/null; then
     sqlite3 "$dest_db" "PRAGMA wal_checkpoint(TRUNCATE);" &> /dev/null || true
 
     # Source DB may be from a different branch with divergent migrations.
     # Re-apply all migration files so the schema matches this branch.
     local migrations_dir="packages/local-db/drizzle"
     if [ -d "$migrations_dir" ]; then
       for migration in "$migrations_dir"/0*.sql; do
         sqlite3 "$dest_db" < "$migration" 2>/dev/null || true
       done
     fi
+  else
+    warn "sqlite3 not found — skipping WAL checkpoint and migration replay on seeded DB"
   fi
🤖 Prompt for AI Agents
In @.superset/setup.sh around lines 515 - 526, The script silently skips WAL
checkpointing and migration re-application when sqlite3 is missing; add an else
branch to the existing if command -v sqlite3 check so that when sqlite3 is not
found it emits a clear warning referencing the variables dest_db and
migrations_dir (e.g., "warning: sqlite3 not installed; cannot checkpoint
$dest_db or apply migrations in $migrations_dir"), so callers know the DB may
have stale WAL or an out-of-date schema; keep current behavior otherwise (do not
change the existing sqlite3 commands or their || true handling).


success "Local DB seeded from $source_db"
return 0
}

main() {
if ! parse_args "$@"; then
return 1
fi

echo "🚀 Setting up Superset workspace..."
echo ""

Expand All @@ -495,17 +587,22 @@ main() {
step_failed "Install dependencies"
fi

# Step 4: Setup Neon branch
# Step 4: Seed local DB into superset-dev-data/
if ! step_seed_local_db; then
step_failed "Seed local DB"
fi

# Step 5: Setup Neon branch
if ! step_setup_neon_branch; then
step_failed "Setup Neon branch"
fi

# Step 5: Start Electric SQL
# Step 6: Start Electric SQL
if ! step_start_electric; then
step_failed "Start Electric SQL"
fi

# Step 6: Write .env file
# Step 7: Write .env file
if ! step_write_env; then
step_failed "Write .env file"
fi
Expand Down
67 changes: 67 additions & 0 deletions .superset/teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,44 @@ NC='\033[0m'
# Step tracking
declare -a FAILED_STEPS=()
declare -a SKIPPED_STEPS=()
REMOVE_DEV_DATA=0

error() { echo -e "${RED}✗${NC} $1"; }
success() { echo -e "${GREEN}✓${NC} $1"; }
warn() { echo -e "${YELLOW}!${NC} $1"; }

print_usage() {
cat <<EOF
Usage: .superset/teardown.sh [options]

Options:
-f, --force Remove superset-dev-data/ in current workspace
-h, --help Show this help message
EOF
}

parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
-f|--force)
REMOVE_DEV_DATA=1
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
error "Unknown argument: $1"
print_usage
return 1
;;
esac
done

return 0
}

# Track step failure
step_failed() {
FAILED_STEPS+=("$1")
Expand Down Expand Up @@ -209,7 +242,36 @@ step_delete_neon_branch() {
return 0
}

step_remove_dev_data() {
local dev_data_dir="superset-dev-data"

if [ "$REMOVE_DEV_DATA" != "1" ]; then
step_skipped "Remove superset-dev-data (flag not set)"
return 0
fi

echo "🗑️ Removing $dev_data_dir/..."

if [ ! -d "$dev_data_dir" ]; then
warn "$dev_data_dir/ not found, skipping"
step_skipped "Remove superset-dev-data (not found)"
return 0
fi

if ! rm -rf "$dev_data_dir"; then
error "Failed to remove $dev_data_dir/"
return 1
fi

success "Removed $dev_data_dir/"
return 0
}

main() {
if ! parse_args "$@"; then
return 1
fi

echo "🧹 Tearing down Superset workspace..."
echo ""

Expand All @@ -236,6 +298,11 @@ main() {
step_failed "Delete Neon branch"
fi

# Step 6: Remove superset-dev-data (optional)
if ! step_remove_dev_data; then
step_failed "Remove superset-dev-data"
fi

# Print summary and exit with appropriate code
print_summary
}
Expand Down
6 changes: 5 additions & 1 deletion apps/desktop/src/main/lib/app-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { homedir } from "node:os";
import { join } from "node:path";
import { SUPERSET_DIR_NAME } from "shared/constants";

export const SUPERSET_HOME_DIR = join(homedir(), SUPERSET_DIR_NAME);
const SUPERSET_HOME_DIR_ENV = "SUPERSET_HOME_DIR";

export const SUPERSET_HOME_DIR =
process.env[SUPERSET_HOME_DIR_ENV] || join(homedir(), SUPERSET_DIR_NAME);
process.env[SUPERSET_HOME_DIR_ENV] = SUPERSET_HOME_DIR;

export const SUPERSET_HOME_DIR_MODE = 0o700;
export const SUPERSET_SENSITIVE_FILE_MODE = 0o600;
Expand Down
Loading