Skip to content

feat(setup): clone local SQLite database when creating new worktree - #1466

Merged
saddlepaddle merged 2 commits into
mainfrom
kitenite/setup-script-clone-db
Feb 14, 2026
Merged

saddlepaddle merged 2 commits into
mainfrom
kitenite/setup-script-clone-db

Conversation

@Kitenite

@Kitenite Kitenite commented Feb 13, 2026 •

Copy link
Copy Markdown
Member

Summary

  • When creating a new worktree, the setup script now copies ~/.superset/local.db to ~/.superset-<workspace>/local.db
  • New worktrees start with existing data (projects, settings, synced tables) instead of an empty database
  • Each dev worktree gets its own isolated SQLite home dir via SUPERSET_DIR_NAME (e.g., ~/.superset-my-branch/)

Changes

  • .superset/setup.sh: Added step_clone_local_db() function (new Step 4) that:
    • Sanitizes workspace name matching env.shared.ts getWorkspaceName() logic
    • Copies local.db + WAL/SHM files with secure permissions (700/600)
    • Skips if destination already exists, source is missing, or workspace is default
    • Renumbered subsequent steps (5-7)

Test Plan

  • Create a new workspace and verify ~/.superset-<name>/local.db is copied from ~/.superset/local.db
  • Verify existing worktrees with an existing local.db are not overwritten
  • Verify the default "superset" workspace skips the clone step

Summary by CodeRabbit

  • Chores
    • Setup now automatically clones a local SQLite database into each workspace during initialization, including handling of auxiliary DB files and secure permissions for created files/directories.
    • The setup sequence has been reordered so local DB cloning occurs earlier; subsequent setup steps (branch setup, service start, and environment file write) run after the clone.

@coderabbitai

coderabbitai Bot commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds step_clone_local_db() to .superset/setup.sh to clone a local SQLite DB into a workspace-scoped destination (sanitizes workspace name, skips default-workspace, copies WAL/SHM, enforces secure permissions). This step is executed before Neon branch setup, renumbering subsequent steps.

Changes

Cohort / File(s) Summary
Setup script — clone local DB & step reordering
.superset/setup.sh
Adds step_clone_local_db() which sanitizes workspace names, skips default-workspace, checks for existing destination, copies SQLite DB and WAL/SHM files, enforces secure dir/file permissions, and integrates this step before step_setup_neon_branch, shifting downstream step numbers.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as "User / CI"
  participant Setup as "setup.sh"
  participant FS as "Filesystem (workspace dirs)"
  participant Neon as "Neon (branches)"
  participant Electric as "Electric SQL"

  CLI->>Setup: run setup
  Setup->>FS: sanitize workspace name, check dest exists
  alt dest absent
    Setup->>FS: create dir, set secure permissions
    Setup->>FS: copy source DB file
    Setup->>FS: copy WAL/SHM if present
    FS-->>Setup: copy success
  else dest present
    FS-->>Setup: skip copy
  end
  Setup->>Neon: step_setup_neon_branch (create/use branch)
  Neon-->>Setup: branch info
  Setup->>Electric: start Electric SQL
  Electric-->>Setup: started
  Setup->>CLI: write .env and finish
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • AviPeltz

Poem

🐰 I hopped into setup, paws full of fluff,
I copied the DB — careful, not rough.
I scrubbed the name and locked the door tight,
Then nudged Neon and Electric to light.
A rabbit's small patch to make the workspace right! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (2 files):

⚔️ .superset/setup.sh (content)
⚔️ apps/desktop/src/shared/tabs-types.ts (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a feature to clone a local SQLite database when creating a new worktree, which directly matches the implementation in the summary.
Description check ✅ Passed The description covers all required sections: Summary explains the feature clearly, Changes details the implementation in setup.sh, and Test Plan outlines verification steps. Structure aligns well with the template requirements.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/setup-script-clone-db
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch kitenite/setup-script-clone-db
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.superset/setup.sh:
- Around line 196-200: Remove the unsupported flag from the neonctl invocation:
the branch creation call using "neonctl branches create" (which assigns output
to the neon_output variable) should not pass "--schema-only false"; edit the
code that builds the command (the if ! neon_output=$(neonctl branches create ...
) then block) to drop the "--schema-only false" argument and rely on the default
behavior that includes schema and data when creating a branch from the parent
(references: neonctl branches create, neon_output, WORKSPACE_NAME,
NEON_PROJECT_ID).

Comment thread .superset/setup.sh
Comment on lines 196 to 200
if ! neon_output=$(neonctl branches create \
--project-id "$NEON_PROJECT_ID" \
--name "$WORKSPACE_NAME" \
--schema-only false \
--output json); then

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 | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

neonctl branches create --schema-only flag documentation

💡 Result:

The --schema-only flag is documented under Neon CLI → branches create:

  • Command: neon branches create --schema-only (works the same with the neonctl alias)
  • What it does: creates a schema-only branch (schema copied, no data).
  • Constraint: it “requires exactly one read-write compute.” [1]
  • Context: neon is the CLI command name, with neonctl as an alias. [2]

Sources:
[1] Neon Docs — Neon CLI commands — branches (create options, --schema-only) (neon.com)
[2] Neon Docs — Neon CLI (Overview) (shows neon usage and neonctl alias) (neon.com)

Citations:


🌐 Web query:

neonctl --schema-only false syntax examples

💡 Result:

As of the Neon docs update April 17, 2025, schema-only branches were not yet supported in neonctl (“Support for the Neon CLI will come in a future release”). [1] So neonctl ... --schema-only false is likely not a valid flag (at least per the published docs).

Boolean false syntax in neonctl (working pattern)

neonctl boolean options accept either:

  • --flag false
  • --no-flag

Example from the CLI docs (analytics is true by default): [2]

neonctl projects list --no-analytics
neonctl projects list --analytics false

If your goal is “schema-only = false” (i.e., include data)

Neon branches created via CLI are schema+data by default (so you typically don’t need to pass anything to mean “false”). Example: [3]

neonctl branches create --project-id=<your_project_id>

If your goal is “schema-only = true” (schema-only branch)

Use the Neon API with init_source: "schema-only" (example from docs): [4]

curl --request POST \
  --url https://console.neon.tech/api/v2/projects/<project_id>/branches \
  --header 'accept: application/json' \
  --header "authorization: Bearer $NEON_API_KEY" \
  --header 'content-type: application/json' \
  --data '{
    "branch": {
      "parent_id": "<parent_branch_id>",
      "name": "my_schema_only_branch",
      "init_source": "schema-only"
    }
  }'

If you tell me which neonctl command you’re running (e.g., branches create, some dump/export command, etc.) and your neonctl --version, I can confirm whether --schema-only exists in that specific version and the exact accepted syntax.


🏁 Script executed:

cd .superset && grep -r "neonctl" . --include="*.json" --include="*.txt" --include="*.md" | head -20

Repository: superset-sh/superset

Length of output: 46


Remove the --schema-only false flag—it is not a documented neonctl option and will likely cause the command to fail.

The --schema-only flag is not supported in neonctl as of the current Neon CLI documentation (April 2025). More importantly, the default behavior of neonctl branches create already includes both schema and data from the parent branch, making this flag unnecessary. To simplify, remove --schema-only false from line 199 and rely on the default branch creation behavior.

🤖 Prompt for AI Agents
In @.superset/setup.sh around lines 196 - 200, Remove the unsupported flag from
the neonctl invocation: the branch creation call using "neonctl branches create"
(which assigns output to the neon_output variable) should not pass
"--schema-only false"; edit the code that builds the command (the if !
neon_output=$(neonctl branches create ... ) then block) to drop the
"--schema-only false" argument and rely on the default behavior that includes
schema and data when creating a branch from the parent (references: neonctl
branches create, neon_output, WORKSPACE_NAME, NEON_PROJECT_ID).

@github-actions

github-actions Bot commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch
  • ✅ Electric Fly.io app
  • ✅ Streams Fly.io app

Thank you for your contribution! 🎉

Copy ~/.superset/local.db to ~/.superset-<workspace>/local.db during
workspace setup so new worktrees start with existing data (projects,
settings, synced tables) instead of an empty database.

Skips the clone if the destination already exists, the source database
is missing, or the workspace is the default "superset" instance.
Also copies WAL/SHM files for consistency.
@Kitenite
Kitenite force-pushed the kitenite/setup-script-clone-db branch from b5da1f1 to f289cc2 Compare February 13, 2026 20:51
@Kitenite Kitenite changed the title fix(setup): ensure Neon branch clones data, not just schema feat(setup): clone local SQLite database when creating new worktree Feb 13, 2026
The dev workspace (~/.superset-dev/) is the correct source for cloning
the local SQLite database to new worktrees. Also skip the clone when
running in the dev workspace itself.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.superset/setup.sh:
- Around line 189-202: Replace the raw cp of the SQLite file and the manual
WAL/SHM copy loop with a single sqlite3 backup invocation to produce a
consistent snapshot: call sqlite3 against the source DB with the .backup command
to create the destination DB, check the sqlite3 exit status and log/return an
error on failure, then set permissions on the resulting dest file; also add a
check in step_check_dependencies to ensure sqlite3 is available before
attempting the backup. Ensure you update the logic that currently references
copying WAL/SHM (the cp + for-suffix loop) and the chmod calls to instead run
only after a successful sqlite3 .backup.

Comment thread .superset/setup.sh
Comment on lines +189 to +202
# Copy the database file (and WAL/SHM files if they exist)
if ! cp "$source_db" "$dest_db"; then
error "Failed to copy local database"
return 1
fi
chmod 600 "$dest_db"

# Copy WAL and SHM files if present for consistency
for suffix in "-wal" "-shm"; do
if [ -f "${source_db}${suffix}" ]; then
cp "${source_db}${suffix}" "${dest_db}${suffix}" 2>/dev/null || true
chmod 600 "${dest_db}${suffix}" 2>/dev/null || true
fi
done

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

Prefer sqlite3 .backup over raw file copy to avoid a corrupt clone.

Copying a SQLite database and its WAL/SHM files with separate cp commands is not atomic. If the source database is open in WAL mode and another process checkpoints or writes between the copies, the destination can end up with an inconsistent (corrupt) database. The SQLite documentation explicitly warns against this.

Using the built-in backup API via the sqlite3 CLI produces a consistent snapshot in a single step and eliminates the need to handle WAL/SHM files separately.

Proposed fix using sqlite3 .backup
-  # Copy the database file (and WAL/SHM files if they exist)
-  if ! cp "$source_db" "$dest_db"; then
-    error "Failed to copy local database"
-    return 1
-  fi
-  chmod 600 "$dest_db"
-
-  # Copy WAL and SHM files if present for consistency
-  for suffix in "-wal" "-shm"; do
-    if [ -f "${source_db}${suffix}" ]; then
-      cp "${source_db}${suffix}" "${dest_db}${suffix}" 2>/dev/null || true
-      chmod 600 "${dest_db}${suffix}" 2>/dev/null || true
-    fi
-  done
+  # Use sqlite3 backup API for a consistent snapshot (safe even if source is in WAL mode)
+  if ! sqlite3 "$source_db" ".backup '$dest_db'"; then
+    error "Failed to clone local database"
+    return 1
+  fi
+  chmod 600 "$dest_db"

You may also want to add sqlite3 to the dependency check in step_check_dependencies (it's usually pre-installed on macOS/Linux but worth verifying):

+  if ! command -v sqlite3 &> /dev/null; then
+    missing+=("sqlite3 (usually pre-installed; Run: brew install sqlite)")
+  fi
🤖 Prompt for AI Agents
In @.superset/setup.sh around lines 189 - 202, Replace the raw cp of the SQLite
file and the manual WAL/SHM copy loop with a single sqlite3 backup invocation to
produce a consistent snapshot: call sqlite3 against the source DB with the
.backup command to create the destination DB, check the sqlite3 exit status and
log/return an error on failure, then set permissions on the resulting dest file;
also add a check in step_check_dependencies to ensure sqlite3 is available
before attempting the backup. Ensure you update the logic that currently
references copying WAL/SHM (the cp + for-suffix loop) and the chmod calls to
instead run only after a successful sqlite3 .backup.

@saddlepaddle
saddlepaddle merged commit 112daad into main Feb 14, 2026
14 of 15 checks passed
Kitenite added a commit that referenced this pull request Feb 14, 2026
Kitenite added a commit that referenced this pull request Feb 14, 2026
@Kitenite
Kitenite deleted the kitenite/setup-script-clone-db branch February 16, 2026 00:04

This branch was previously deployed

1 inactive deployment
preview — bee562f6 Deployed Feb 13, 2026 by Kitenite via Deploy Docs #1893
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