Skip to content

DanielAF07/pb-admin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@pb-admin/cli

CLI tool for managing PocketBase collections, schema, and access rules. Keep your PocketBase configuration in version control and sync changes across environments.

Why?

  • Version control - Track schema and rules changes in git
  • Environment sync - Push same config to dev, staging, prod
  • Team collaboration - Review PocketBase changes in PRs
  • CI/CD ready - Automate deployments with diff checks

Installation

# npm
npm install -g @pb-admin/cli

# or run directly
npx @pb-admin/cli init

Quick Start

# 1. Initialize in your project
pb-admin init

# 2. Pull current schema and rules from PocketBase
pb-admin pull

# 3. Edit files locally
#    pb-admin/schema.json  - collection fields
#    pb-admin/rules.json   - access permissions

# 4. Preview changes
pb-admin diff

# 5. Apply to PocketBase
pb-admin push

Commands

Command Description
pb-admin init Setup project, login, and pull initial config
pb-admin login Login to PocketBase instance
pb-admin logout Clear saved credentials
pb-admin pull Download schema & rules from PocketBase
pb-admin push Upload local schema & rules to PocketBase
pb-admin diff Compare local files vs live PocketBase
pb-admin col List and inspect collections
pb-admin status Check login status

Options

Flag Description
--schema, -s Only operate on schema
--rules, -r Only operate on rules
--dry-run, -n Preview changes without applying
--debug Show detailed error information

Project Files

After pb-admin init:

your-project/
  pb-admin.json           # Config (PocketBase URL)
  pb-admin/
    schema.json           # Collection fields definition
    rules.json            # Access rules (list/view/create/update/delete)

Example: Updating Rules

// pb-admin/rules.json
{
  "posts": {
    "listRule": "",                           // public
    "viewRule": "",                           // public
    "createRule": "@request.auth.id != ''",   // authenticated users
    "updateRule": "@request.auth.id = owner", // owner only
    "deleteRule": null                        // admin only
  }
}
pb-admin diff   # see what changed
pb-admin push   # apply to PocketBase

CI/CD Integration

# GitHub Actions example
- name: Check PocketBase config
  env:
    PB_URL: ${{ secrets.PB_URL }}
    PB_EMAIL: ${{ secrets.PB_EMAIL }}
    PB_PASSWORD: ${{ secrets.PB_PASSWORD }}
  run: |
    npx @pb-admin/cli diff
# Shell script
export PB_URL=https://your-pocketbase.com
export PB_EMAIL=admin@example.com
export PB_PASSWORD=your-password

pb-admin diff || exit 1  # fail if config differs
pb-admin push            # or apply changes

Credentials

Credentials are stored per-project in ~/.config/pb-admin/projects/. Each project directory gets its own credentials file based on the project path.

License

MIT

About

CLI to manage PocketBase collections, rules, and schema

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors