CLI Workflows
This guide covers common workflows for developing and deploying with the Fluxbase CLI.
Project Structure
Section titled “Project Structure”Organize your Fluxbase project with this recommended structure:
my-project/├── fluxbase/│ ├── functions/│ │ ├── _shared/│ │ │ ├── utils.ts│ │ │ └── auth.ts│ │ ├── api-handler.ts│ │ └── webhook.ts│ ├── jobs/│ │ ├── _shared/│ │ │ └── helpers.ts│ │ ├── process-data.ts│ │ └── send-emails.ts│ ├── rpc/│ │ ├── calculate_totals.sql│ │ └── cleanup_old_records.sql│ ├── migrations/│ │ ├── 001_create_users.up.sql│ │ ├── 001_create_users.down.sql│ │ ├── 002_add_profiles.up.sql│ │ └── 002_add_profiles.down.sql│ └── chatbots/│ └── support-bot.yaml├── .fluxbase/│ └── config.yaml└── package.jsonLocal Development Workflow
Section titled “Local Development Workflow”Initial Setup
Section titled “Initial Setup”-
Install the CLI (see Installation)
-
Authenticate with your server:
# Development serverfluxbase auth login --profile dev --server http://localhost:8080
# Production serverfluxbase auth login --profile prod --server https://api.example.com- Verify authentication:
fluxbase auth statusfluxbase auth whoamiDevelopment Cycle
Section titled “Development Cycle”Deploy changes with sync:
# Preview what would changefluxbase sync --dry-run
# Deploy all resourcesfluxbase sync
# Deploy specific resource typesfluxbase functions sync --dir ./fluxbase/functionsfluxbase jobs sync --dir ./fluxbase/jobsTest functions locally:
# Invoke a functionfluxbase functions invoke my-function --data '{"test": true}'
# View logsfluxbase functions logs my-function --followDebug issues:
# Enable debug outputfluxbase --debug functions invoke my-function
# Stream all logsfluxbase logs tail --level error
# View execution logsfluxbase logs execution <execution-id>Multi-Environment Management
Section titled “Multi-Environment Management”Setting Up Profiles
Section titled “Setting Up Profiles”Create profiles for each environment:
# Local developmentfluxbase auth login \ --profile dev \ --server http://localhost:8080 \ --email admin@localhost.local \ --password admin
# Stagingfluxbase auth login \ --profile staging \ --server https://staging.example.com \ --token "$STAGING_TOKEN"
# Productionfluxbase auth login \ --profile prod \ --server https://api.example.com \ --token "$PROD_TOKEN" \ --use-keychainSwitching Environments
Section titled “Switching Environments”# Switch default profilefluxbase auth switch prod
# Use specific profile for a commandfluxbase --profile staging functions list
# Check which profile is activefluxbase auth statusEnvironment-Specific Namespaces
Section titled “Environment-Specific Namespaces”Use namespaces to isolate resources within an environment:
# Deploy to staging namespacefluxbase sync --namespace staging
# Deploy to production namespacefluxbase sync --namespace productionCI/CD Integration
Section titled “CI/CD Integration”Environment Variables
Section titled “Environment Variables”Configure authentication using environment variables:
export FLUXBASE_SERVER="https://api.example.com"export FLUXBASE_TOKEN="your-api-token"GitHub Actions
Section titled “GitHub Actions”name: Deploy to Fluxbase
on: push: branches: [main] paths: - 'fluxbase/**'
jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Install Fluxbase CLI run: | curl -fsSL https://raw.githubusercontent.com/fluxbase-eu/fluxbase/main/install-cli.sh | bash echo "/usr/local/bin" >> $GITHUB_PATH
- name: Deploy to production env: FLUXBASE_SERVER: ${{ secrets.FLUXBASE_SERVER }} FLUXBASE_TOKEN: ${{ secrets.FLUXBASE_TOKEN }} run: | fluxbase sync --namespace productionGitLab CI
Section titled “GitLab CI”stages: - deploy
deploy: stage: deploy image: ubuntu:latest before_script: - apt-get update && apt-get install -y curl - curl -fsSL https://raw.githubusercontent.com/fluxbase-eu/fluxbase/main/install-cli.sh | bash script: - fluxbase sync --namespace production variables: FLUXBASE_SERVER: $FLUXBASE_SERVER FLUXBASE_TOKEN: $FLUXBASE_TOKEN only: - main changes: - fluxbase/**Deployment Previews
Section titled “Deployment Previews”For pull request previews, deploy to a unique namespace:
# GitHub Actions example- name: Deploy preview if: github.event_name == 'pull_request' run: | fluxbase sync --namespace "pr-${{ github.event.number }}"Common Tasks
Section titled “Common Tasks”Deploy a Function End-to-End
Section titled “Deploy a Function End-to-End”- Create the function file:
export default async function handler(req: Request): Promise<Response> { const { name } = await req.json(); return new Response(JSON.stringify({ message: `Hello, ${name}!` }));}- Set required secrets:
fluxbase secrets set API_KEY "your-api-key"- Deploy:
fluxbase functions sync- Test:
fluxbase functions invoke hello --data '{"name": "World"}'- Monitor:
fluxbase functions logs hello --followRun a One-Off Job
Section titled “Run a One-Off Job”# Submit job with payloadfluxbase jobs submit process-data --payload '{"batch_id": 123}'
# Check statusfluxbase jobs status <job-id>
# View logsfluxbase logs execution <job-id>Manage Secrets Across Environments
Section titled “Manage Secrets Across Environments”# Set secrets for each environmentfluxbase --profile dev secrets set API_KEY "dev-key"fluxbase --profile staging secrets set API_KEY "staging-key"fluxbase --profile prod secrets set API_KEY "prod-key"
# Namespace-scoped secretsfluxbase secrets set DB_PASSWORD "secret" --scope namespace --namespace productionDebug Failing Functions
Section titled “Debug Failing Functions”- Check recent logs:
fluxbase logs list --category execution --level error --since 1h- Get execution details:
fluxbase logs execution <execution-id>- Test with debug output:
fluxbase --debug functions invoke my-function --data '{"test": true}'- Tail logs in real-time:
fluxbase logs tail --category execution --component my-functionDatabase Operations
Section titled “Database Operations”# List tablesfluxbase tables list
# Query datafluxbase tables query users --select "id,email" --where "role=eq.admin" --limit 10
# Export as JSONfluxbase tables query users -o json > users.json
# Run migrationsfluxbase migrations apply-pendingBest Practices
Section titled “Best Practices”Use Dry Run Before Deploying
Section titled “Use Dry Run Before Deploying”Always preview changes before applying:
fluxbase sync --dry-runStore Credentials Securely
Section titled “Store Credentials Securely”- Use
--use-keychainfor local development - Use environment variables in CI/CD
- Never commit tokens to version control
Organize with Namespaces
Section titled “Organize with Namespaces”- Use namespaces to separate concerns (e.g.,
default,internal,webhooks) - Use environment-specific namespaces in production
Version Control Your Resources
Section titled “Version Control Your Resources”- Keep all Fluxbase resources in version control
- Use meaningful migration names (e.g.,
003_add_user_roles) - Review sync diffs in pull requests
Monitor Deployments
Section titled “Monitor Deployments”# After deploying, verify resourcesfluxbase functions listfluxbase jobs list
# Watch for errorsfluxbase logs tail --level errorDatabase Branching Workflow
Section titled “Database Branching Workflow”Database branches provide isolated environments for development and testing. See the Database Branching Guide for full documentation.
Feature Development with Branches
Section titled “Feature Development with Branches”Use branches to safely develop and test database changes:
# 1. Create a branch for your featurefluxbase branch create my-feature
# 2. Test your migrations on the branchfluxbase migrations sync --dir ./fluxbase/migrations
# 3. Deploy functions to the branchfluxbase functions sync
# 4. Test your changescurl http://localhost:8080/api/v1/tables/users \ -H "X-Fluxbase-Branch: my-feature"
# 5. When ready, apply migrations to productionfluxbase --profile prod migrations apply-pending
# 6. Delete the branchfluxbase branch delete my-featurePR Preview Branches
Section titled “PR Preview Branches”Create isolated environments for each pull request:
# Create a preview branch linked to a PRfluxbase branch create pr-123 \ --pr 123 \ --repo owner/repo \ --expires-in 24h
# Deploy your changesfluxbase sync
# The branch auto-deletes when the PR closes (with GitHub integration)# or after 24 hours if using --expires-inGitHub Actions with Branching
Section titled “GitHub Actions with Branching”name: PR Preview
on: pull_request: types: [opened, synchronize]
jobs: preview: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Install Fluxbase CLI run: | curl -fsSL https://raw.githubusercontent.com/fluxbase-eu/fluxbase/main/install-cli.sh | bash echo "/usr/local/bin" >> $GITHUB_PATH
- name: Create preview branch env: FLUXBASE_SERVER: ${{ secrets.FLUXBASE_SERVER }} FLUXBASE_TOKEN: ${{ secrets.FLUXBASE_TOKEN }} run: | # Create or reset the branch fluxbase branch create "pr-${{ github.event.number }}" \ --pr ${{ github.event.number }} \ --repo ${{ github.repository }} \ --expires-in 7d || \ fluxbase branch reset "pr-${{ github.event.number }}" --force
# Deploy to the branch fluxbase sync
- name: Comment preview URL uses: actions/github-script@v7 with: script: | github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: '🚀 Preview deployed! Use branch: `pr-${{ github.event.number }}`' })Branch Connection Methods
Section titled “Branch Connection Methods”Connect to a branch using any of these methods:
# HTTP Headercurl http://localhost:8080/api/v1/tables/users \ -H "X-Fluxbase-Branch: my-feature"
# Query Parametercurl "http://localhost:8080/api/v1/tables/users?branch=my-feature"
# SDK Configurationconst fluxbase = createClient(url, key, { branch: 'my-feature' })Branch Management Commands
Section titled “Branch Management Commands”# List all branchesfluxbase branch list
# Get branch detailsfluxbase branch get my-feature
# Check branch statusfluxbase branch status my-feature
# View activity logfluxbase branch activity my-feature
# Reset to parent statefluxbase branch reset my-feature
# Delete when donefluxbase branch delete my-feature