Skip to content

feat(cli): supabase migration#366

Open
calvinbrewer wants to merge 1 commit intomainfrom
supabase-migrations
Open

feat(cli): supabase migration#366
calvinbrewer wants to merge 1 commit intomainfrom
supabase-migrations

Conversation

@calvinbrewer
Copy link
Copy Markdown
Contributor

@calvinbrewer calvinbrewer commented Apr 28, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added --migration and --direct flags to db install command for selecting Supabase installation modes
    • Added --migrations-dir option to specify custom Supabase migrations directory path
    • Added automatic Supabase project detection based on configuration and directory structure
    • Enhanced installation flow with interactive prompting for migration vs direct install selection
  • Documentation

    • Updated db install help text to clarify new options and --force overwrite behavior
    • Improved next steps guidance for Supabase installations
  • Tests

    • Added comprehensive test coverage for Supabase installation modes and project detection

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

🦋 Changeset detected

Latest commit: 34432e9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cipherstash/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

📝 Walkthrough

Walkthrough

Adds Supabase-specific "migration mode" to the db install command, enabling users to choose between writing EQL SQL as a timestamped migration file or installing directly. Introduces project detection based on filesystem markers (supabase/config.toml and supabase/migrations/), validates new CLI flags, handles interactive prompting for TTY environments, and refactors permission SQL into a centralized constant.

Changes

Cohort / File(s) Summary
Migration Mode Implementation
packages/cli/src/commands/db/supabase-migration.ts, packages/cli/src/commands/db/detect.ts
New modules for detecting Supabase projects (filesystem checks) and writing EQL migrations with a zero-prefixed filename to ensure correct execution order. Exports detectSupabaseProject, writeSupabaseEqlMigration, and associated type/constant definitions.
Install Command Integration
packages/cli/src/commands/db/install.ts
Extended with migration mode selection logic: flag validation, interactive prompting for TTY, mode choice based on project detection, and migration file writing path. Adds validateInstallFlags, chooseSupabaseInstallMode, and resolveSupabaseInstallMode helpers. Extends InstallOptions with migration, direct, and migrationsDir fields.
CLI Surface & Help Text
packages/cli/src/bin/stash.ts
Updated db install help to document --migration, --direct, and --migrations-dir options; clarified --force behavior as "Reinstall / overwrite".
Permission SQL Refactor
packages/cli/src/installer/index.ts
Centralized Supabase role permission grants into a single exported SUPABASE_PERMISSIONS_SQL constant, replacing inline discrete SQL statements in grantSupabasePermissions().
User-Facing Guidance
packages/cli/src/commands/init/providers/supabase.ts
Updated getNextSteps to separate EQL installation from schema/migrations application with environment-specific commands and a hint about install mode prompting.
Tests
packages/cli/src/__tests__/supabase-migration.test.ts, packages/cli/src/__tests__/installer.test.ts
New comprehensive test file validating project detection (various config/migrations scenarios), flag validation logic, mode selection heuristics, and migration file writing (header/SQL inclusion, directory creation, overwrite behavior). Added Supabase permission SQL assertion to installer test.
Metadata
.changeset/all-frogs-give.md
Changeset recording @cipherstash/cli minor version bump and --migration/--direct flag additions.

Sequence Diagram(s)

sequenceDiagram
    participant User as User/CLI
    participant Install as Install Command
    participant Detect as Supabase Detector
    participant Choose as Mode Selector
    participant Write as Migration Writer
    participant Perms as Permissions Handler
    participant FS as Filesystem

    User->>Install: db install --supabase [--migration|--direct]
    Install->>Install: validateInstallFlags()
    Install->>Detect: detectSupabaseProject(cwd, migrationsDir?)
    Detect->>FS: Check config.toml, migrations/ exist
    FS-->>Detect: Filesystem state
    Detect-->>Install: SupabaseProjectInfo
    Install->>Choose: chooseSupabaseInstallMode(flags, projectInfo, isTTY)
    alt Explicit flag set
        Choose-->>Install: 'migration' or 'direct'
    else TTY & no flag
        Choose->>User: Interactive prompt
        User-->>Choose: User choice
        Choose-->>Install: Selected mode
    else Non-TTY & no flag
        Choose-->>Install: Default (migration if detected, else direct)
    end
    alt mode === 'migration'
        Install->>Write: writeSupabaseEqlMigration(options)
        Write->>FS: Create migrations dir if missing
        Write->>FS: Write migration file with header + EQL SQL + permissions
        FS-->>Write: File path & overwritten flag
        Write-->>Install: Success result
    else mode === 'direct'
        Install->>Perms: Run direct SQL install + permissions
        Perms->>FS: Execute SUPABASE_PERMISSIONS_SQL
        FS-->>Perms: Permissions applied
        Perms-->>Install: Install complete
    end
    Install-->>User: Next steps (environment-specific guidance)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • PR #317: Modifies bundled EQL loading and Supabase permission SQL/granting logic used by this PR's new migration and installer refactoring.
  • PR #349: Updates the same installer module (packages/cli/src/installer/index.ts) to change SQL-download APIs and superuser detection alongside this PR's permission SQL centralization.

Suggested reviewers

  • coderdan
  • auxesis

Poem

🐰 A hop towards Supabase clarity, where frogs now choose their path with care—
Migration or direct, the decision blooms fair,
Detection reveals what was hidden in files,
Permissions bundled tight, the installer smiles! 🌿✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(cli): supabase migration' clearly and concisely summarizes the main change—adding Supabase migration support to the CLI with new flags and workflows.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch supabase-migrations

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/cli/src/commands/db/supabase-migration.ts (1)

102-105: Simplify the always-true excludeOperatorFamily assignment.

excludeOperatorFamily || true always resolves to true, so this reads like conditional behavior but isn’t. Making it explicit improves readability.

Proposed diff
-  const eqlSql = loadBundledEqlSql({
-    supabase: true,
-    excludeOperatorFamily: excludeOperatorFamily || true,
-  })
+  const eqlSql = loadBundledEqlSql({
+    supabase: true,
+    excludeOperatorFamily: true,
+  })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/src/commands/db/supabase-migration.ts` around lines 102 - 105,
The call to loadBundledEqlSql passes excludeOperatorFamily || true which always
evaluates to true; update the call to pass a clear boolean value or the actual
variable so intent is explicit (e.g., pass excludeOperatorFamily if you want the
variable honored, or pass true directly if it should always be true). Locate the
loadBundledEqlSql invocation and replace the ternary/OR expression with the
chosen explicit boolean or the variable name (function: loadBundledEqlSql;
identifier: excludeOperatorFamily).
packages/cli/src/commands/init/providers/supabase.ts (1)

19-20: Wording currently implies a prompt is always shown.

In non-interactive execution, mode may be auto-selected. Consider neutral wording so this step stays accurate across environments.

Proposed text tweak
-        'Install EQL: npx `@cipherstash/cli` db install --supabase (prompts for migration vs direct)',
+        'Install EQL: npx `@cipherstash/cli` db install --supabase (choose migration vs direct mode)',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/src/commands/init/providers/supabase.ts` around lines 19 - 20,
The help text strings currently read "'Install EQL: npx `@cipherstash/cli` db
install --supabase (prompts for migration vs direct)'" and imply a prompt will
always appear; update these messages in
packages/cli/src/commands/init/providers/supabase.ts (the two literal string
entries shown) to neutral wording that covers both interactive and
non-interactive runs—for example, replace the parenthetical with "(prompts for
migration vs direct when interactive)" or "(interactive prompt or auto-selected
in non-interactive mode)" so the message is accurate regardless of execution
mode.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/cli/src/commands/db/supabase-migration.ts`:
- Around line 102-105: The call to loadBundledEqlSql passes
excludeOperatorFamily || true which always evaluates to true; update the call to
pass a clear boolean value or the actual variable so intent is explicit (e.g.,
pass excludeOperatorFamily if you want the variable honored, or pass true
directly if it should always be true). Locate the loadBundledEqlSql invocation
and replace the ternary/OR expression with the chosen explicit boolean or the
variable name (function: loadBundledEqlSql; identifier: excludeOperatorFamily).

In `@packages/cli/src/commands/init/providers/supabase.ts`:
- Around line 19-20: The help text strings currently read "'Install EQL: npx
`@cipherstash/cli` db install --supabase (prompts for migration vs direct)'" and
imply a prompt will always appear; update these messages in
packages/cli/src/commands/init/providers/supabase.ts (the two literal string
entries shown) to neutral wording that covers both interactive and
non-interactive runs—for example, replace the parenthetical with "(prompts for
migration vs direct when interactive)" or "(interactive prompt or auto-selected
in non-interactive mode)" so the message is accurate regardless of execution
mode.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3153e6a7-d201-4651-bf26-ac4d31b42dc3

📥 Commits

Reviewing files that changed from the base of the PR and between dd59a9e and 34432e9.

📒 Files selected for processing (9)
  • .changeset/all-frogs-give.md
  • packages/cli/src/__tests__/installer.test.ts
  • packages/cli/src/__tests__/supabase-migration.test.ts
  • packages/cli/src/bin/stash.ts
  • packages/cli/src/commands/db/detect.ts
  • packages/cli/src/commands/db/install.ts
  • packages/cli/src/commands/db/supabase-migration.ts
  • packages/cli/src/commands/init/providers/supabase.ts
  • packages/cli/src/installer/index.ts

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.

1 participant