Nx plugin for Supabase integration
Manage multiple Supabase projects and environments in your Nx monorepo with ease
β¨ Multi-Environment Support - Manage production, local, staging, and custom environments
π§ Convention Over Configuration - Automatic project detection via inferred tasks plugin
π Simple Workflows - Easy-to-use generators and executors for common Supabase operations
π¦ Monorepo Ready - Built specifically for Nx workspaces
π Environment Merging - Base configuration with environment-specific overrides
β‘ Fast Builds - Intelligent caching and optimized build process
# Add the plugin to your Nx workspace
npx nx add @gridatek/nx-supabaseThis command will:
- Install the
@gridatek/nx-supabasepackage - Add Supabase CLI to your devDependencies
- Register the plugin in your
nx.json
# Generate a new Supabase project (defaults to project name as directory in the root)
npx nx g @gridatek/nx-supabase:project my-supabase
# Creates at: my-supabase/ (in the root)
# Custom directory (project name β folder name)
npx nx g @gridatek/nx-supabase:project my-supabase --directory=apps/my-api/supabase
# Creates at: apps/my-api/supabase/
# Run with: nx run my-supabase:start
# Or match folder name to project name
npx nx g @gridatek/nx-supabase:project my-supabase --directory=apps/my-api/my-supabase
# Creates at: apps/my-api/my-supabase/This creates a project with:
- production/ - Your production configuration (base for all environments)
- local/ - Local development overrides
- .generated/ - Auto-generated build outputs
- project.json - Nx project configuration
# Build environment configurations
npx nx run my-supabase:build
# Start Supabase locally (defaults to 'local' environment)
npx nx run my-supabase:start
# Check status
npx nx run my-supabase:status
# Stop Supabase
npx nx run my-supabase:stopmy-supabase/
βββ production/ # Production environment (base configuration)
β βββ config.toml # Main Supabase configuration
βββ local/ # Local development overrides (empty by default)
βββ .generated/ # AUTO-GENERATED (do not edit)
β βββ local/ # Built local config (production + local overrides)
βββ .gitignore # Ignores .generated/
βββ README.md # Project documentation
βββ project.json # Nx targets (optional with inferred tasks)
Note: Create migrations/ and seeds/ directories in each environment as needed.
-
Production Directory: Serves as the base configuration for all environments.
-
Additional Environments: Each environment (local, staging, production, etc.) starts with the production config and merges in environment-specific overrides.
-
Build Process:
- All environments: Built to
.generated/<env>/supabaseby merging production + environment-specific files
- All environments: Built to
Projects are automatically detected when you have a production/config.toml file. The plugin extracts the project name from the project_id field in config.toml.
# Basic usage
npx nx g @gridatek/nx-supabase:project <name>
# With options
npx nx g @gridatek/nx-supabase:project my-supabase \
--directory=apps/my-api/supabase \
--environments=staging,qa
# Creates at: apps/my-api/supabase/Options:
--directory- Directory where the project will be created (defaults to project name)--environments- Comma-separated list of additional environments (beyond production and local)
Default Environments:
Production and local are always created. Use --environments to add more like staging, qa, dev, etc.
npx nx g @gridatek/nx-supabase:initnpx nx run <project>:buildMerges production config with environment-specific files and outputs to .generated/<env>/supabase/ for all environments.
# Default environment (local)
npx nx run <project>:start
# Specific environment
npx nx run <project>:start --env=productionAutomatically runs build before starting.
npx nx run <project>:stopStops the running Supabase instance.
The plugin provides convenient shortcuts for frequently used Supabase commands:
# Check status
npx nx run <project>:status
# Reset database
npx nx run <project>:db-reset
# Push migrations to remote
npx nx run <project>:db-push
# Pull schema from remote
npx nx run <project>:db-pull
# Generate TypeScript types (from local database)
npx nx run <project>:gen-types
# Generate types with custom output path
npx nx run <project>:gen-types --outputPath=libs/project-name/src/database.types.ts
# Generate types from remote project
npx nx run <project>:gen-types --projectId=your-project-id
# Create a new migration (pass name via command option)
npx nx run <project>:migration-new --command="supabase migration new my_table"
# Link to remote project
npx nx run <project>:link
# Show database diff
npx nx run <project>:db-diffAll targets (except link) automatically run build first to ensure configurations are up-to-date.
For commands not covered by the convenience targets:
# Run any Supabase command
npx nx run <project>:run-command --command="supabase functions new my-function"
# With specific environment
npx nx run <project>:run-command --env=staging --command="supabase db remote commit"npx nx g @gridatek/nx-supabase:project my-supabase \
--directory=apps/my-api/supabase \
--environments=staging,qa,dev
# Creates at: apps/my-api/supabase/This creates:
production/(base config, always created)local/(always created)staging/(additional)qa/(additional)dev/(additional)
# Build all environments
npx nx run my-api:build
# Start with staging environment
npx nx run my-api:start --env=staging
# Run command in QA environment
npx nx run my-api:run-command --env=qa --command="supabase status"- Start with production config as base
- Override with environment-specific files
- Files in environment directories take precedence
Example:
production/config.toml- Base config for all environmentsstaging/config.toml- Overrides only the settings different in staging- Result:
.generated/staging/contains merged configuration
The plugin automatically infers targets for Supabase projects based on the presence of production/config.toml. The project name is read from project.json.
The plugin infers these targets:
build- Build environment configurationsstart- Start Supabasestop- Stop Supabasestatus- Check Supabase statusdb-reset- Reset the databasedb-push- Push migrations to remotedb-pull- Pull schema from remotegen-types- Generate TypeScript typesmigration-new- Create a new migrationlink- Link to remote projectdb-diff- Show database diffrun-command- Run any Supabase command
# 1. Generate project
npx nx g @gridatek/nx-supabase:project my-app
# 2. Start locally
npx nx run my-app:start
# 3. Check it's running
npx nx run my-app:status
# 4. Create a migration
npx nx run my-app:migration-new --command="supabase migration new create_users_table"
# 5. Stop when done
npx nx run my-app:stop# Start multiple projects in parallel
npx nx run-many --target=start --projects=api,admin
# Build all Supabase projects
npx nx run-many --target=build --all
# Stop all
npx nx run-many --target=stop --all# Local-only test migration
# 1. Create in local/migrations/
# 2. Build to apply
npx nx run my-app:build
# 3. Start with local environment (default)
npx nx run my-app:startYou can customize target names and configure global defaults:
{
"plugins": [
{
"plugin": "@gridatek/nx-supabase",
"options": {
"buildTargetName": "build",
"startTargetName": "start",
"stopTargetName": "stop",
"statusTargetName": "status",
"dbResetTargetName": "db-reset",
"dbPushTargetName": "db-push",
"dbPullTargetName": "db-pull",
"genTypesTargetName": "gen-types",
"genTypesOutputPath": "database.types.ts",
"migrationNewTargetName": "migration-new",
"linkTargetName": "link",
"dbDiffTargetName": "db-diff",
"runCommandTargetName": "run-command"
}
}
]
}You can configure different genTypesOutputPath for each project in your monorepo:
{
"plugins": [
{
"plugin": "@gridatek/nx-supabase",
"options": {
"genTypesOutputPath": "database.types.ts",
"projects": {
"my-api": {
"genTypesOutputPath": "libs/api-types/src/database.types.ts"
},
"admin": {
"genTypesOutputPath": "libs/admin-types/src/database.types.ts"
}
}
}
}
]
}Configuration Priority:
- Project-specific configuration in
options.projects[projectName] - Global configuration in
options.genTypesOutputPath - Default:
database.types.ts
Example:
# Generate types for my-api (uses libs/api-types/src/database.types.ts)
npx nx run my-api:gen-types
# Generate types for admin (uses libs/admin-types/src/database.types.ts)
npx nx run admin:gen-types
# Override at runtime
npx nx run my-api:gen-types --outputPath=custom/path.tsEdit production/config.toml for base configuration. See Supabase CLI documentation for available options.
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build Supabase projects
run: npx nx run-many --target=build --all
- name: Start Supabase
run: npx nx run my-app:start
- name: Run migrations
run: npx nx run my-app:run-command --command="supabase db reset"
- name: Run tests
run: npm test
- name: Stop Supabase
run: npx nx run my-app:stop- π API Reference - Detailed API documentation
- π― Best Practices - Recommended patterns and workflows
- π§ Advanced Usage - Complex scenarios and customization
- π Migration Guide - Migrating existing Supabase projects
- Node.js 18+
- Nx 22+
- Docker (for running Supabase locally)
Contributions are welcome! Please read our contributing guidelines before submitting a PR.
# Clone the repository
git clone https://github.com/gridatek/nx-supabase.git
cd nx-supabase
# Install dependencies
npm install
# Run tests
npx nx test nx-supabase
# Build the plugin
npx nx build nx-supabase
# Run e2e tests
npx nx e2e e2eMIT Β© GridaTek
- π Report Issues
- π¬ Discussions
- π§ Email Support
Made with β€οΈ by GridaTek
