v0.4.4 - nself-org/cli GitHub Wiki
Release Date: January 20, 2026 Focus: Database Tools
Comprehensive database management release introducing the unified nself db command with all database operations consolidated under one clean interface.
- DBML Schema Workflow: Design at dbdiagram.io, import to SQL, seed automatically
-
Schema Templates: Start with
basic,ecommerce,saas, orblogtemplates -
One-Command Setup:
nself db schema applydoes import โ migrate โ mock โ seed - Environment-Aware Safety: Production-safe operations with automatic guards
- Mock Data Generation: Deterministic, shareable mock data with configurable seeds
- Type Generation: Generate TypeScript, Go, Python types from your schema
-
Database Inspection: Performance analysis tools like Supabase's
inspect db
All database operations are now consolidated under a single command with intuitive subcommands:
nself db <subcommand> [options]| Subcommand | Description |
|---|---|
migrate |
Database migrations (up, down, create, status, fresh, repair) |
seed |
Environment-aware data seeding |
mock |
Deterministic mock data generation |
backup |
Backup management and scheduling |
restore |
Restore from backups |
schema |
Schema tools (diff, diagram, indexes) |
types |
Generate TypeScript/Go/Python types |
shell |
Interactive PostgreSQL shell |
query |
Execute SQL queries |
inspect |
Database analysis and performance insights |
data |
Data export/import/anonymize |
optimize |
Database maintenance (vacuum, analyze) |
reset |
Reset database to clean state |
The recommended way to design your database:
nself db schema scaffold basic # Users, profiles, posts
nself db schema scaffold ecommerce # Products, orders, cart
nself db schema scaffold saas # Organizations, members, projects
nself db schema scaffold blog # Posts, categories, commentsEdit schema.dbml directly or design visually at dbdiagram.io:
Table users {
id serial [pk]
email varchar(255) [not null, unique]
display_name varchar(100)
role varchar(20) [default: 'user']
created_at timestamptz [default: `NOW()`]
}
nself db schema apply schema.dbmlThis single command:
- Imports DBML โ Creates SQL migration
- Runs migration โ Creates tables
- Generates mock data โ Populates tables (local/staging)
- Seeds users โ Creates sample accounts
-
[email protected](admin role) -
[email protected](user role) -
[email protected](viewer role)
nself db schema import schema.dbml # DBML โ SQL migration
nself db migrate up # Run migrations
nself db mock auto # Auto-generate mock data
nself db seed users # Seed usersFull migration lifecycle with rollback support:
nself db migrate status # Check migration status
nself db migrate up # Run pending migrations
nself db migrate down # Rollback last migration
nself db migrate create NAME # Create new migration
nself db migrate fresh # Drop all & re-run (non-prod only)Different behavior based on environment:
| Environment | Behavior |
|---|---|
| Local | 20 mock users, password "password123" |
| Staging | 100 mock users for load testing |
| Production | Only explicit users from config |
nself db seed users # Seed users for current environmentConfigure production users via environment variable:
NSELF_PROD_USERS='[email protected]:Admin User:admin'Same seed produces identical data across your entire team:
nself db mock --seed 12345 # Reproducible data
nself db mock preview # Preview before generating
nself db mock config # Show configurationPerformance analysis tools (like Supabase inspect db):
nself db inspect # Overview of all tables
nself db inspect size # Table sizes
nself db inspect cache # Cache hit ratios
nself db inspect index # Index usage analysis
nself db inspect bloat # Table bloat analysis
nself db inspect slow # Slow query analysis# Design & Import (NEW)
nself db schema scaffold basic # Create schema from template
nself db schema import file.dbml # Convert DBML to SQL migration
nself db schema apply file.dbml # Full workflow in one command
# Inspect & Export
nself db schema # Show current schema
nself db schema diff staging # Compare with another environment
nself db schema diagram # Generate DBML from database
nself db schema export # Export as SQL
# Optimization
nself db schema indexes # Analyze and suggest indexesGenerate typed interfaces from your database:
nself db types typescript # Generate TypeScript interfaces
nself db types go # Generate Go structs
nself db types python # Generate Python dataclassesnself db backup # Create full backup
nself db backup --compress # Compressed backup
nself db backup list # List all backups
nself db backup schedule # Schedule automated backups
nself db restore # Restore latest backup
nself db restore backup.sql # Restore specific backupnself db data export users # Export table as CSV
nself db data import users.csv # Import data
nself db data anonymize # Anonymize PII dataDestructive operations are blocked in production:
nself db migrate freshnself db mocknself db reset
Operations requiring confirmation in production:
nself db restorenself db migrate down
Set environment via:
ENV=production nself db migrate up
# or in .env file-
src/cli/db.sh- Comprehensive database command (1688 lines)
-
src/lib/database/core.sh- Shared database utilities
-
docs/commands/DB.md- Complete documentation
| Variable | Default | Description |
|---|---|---|
NSELF_MIGRATIONS_DIR |
nself/migrations |
Migrations directory |
NSELF_SEEDS_DIR |
nself/seeds |
Seeds directory |
NSELF_BACKUPS_DIR |
_backups |
Backup storage |
NSELF_MOCK_SEED |
Random | Mock data seed |
NSELF_MOCK_COUNT |
100 |
Default row count |
NSELF_TYPES_DIR |
types |
Generated types output |
NSELF_PROD_USERS |
- | Production users config |
After running nself db commands:
nself/
โโโ migrations/ # SQL migration files
โโโ seeds/
โ โโโ common/ # Always runs
โ โโโ local/ # Development only
โ โโโ staging/ # Staging only
โ โโโ production/ # Production only
โโโ mock/
โ โโโ config.json # Mock data configuration
โโโ config/
โโโ prod-users.json # Production users (optional)
_backups/ # Database backups
types/ # Generated type files
No breaking changes. The new nself db command is additive.
If you were using standalone backup/restore scripts, they still work but we recommend migrating to:
-
nself db backupinstead ofnself backup -
nself db restoreinstead ofnself restore
# Create and apply schema in one workflow
nself db schema scaffold basic # Create schema.dbml
nself db schema apply schema.dbml # Import โ migrate โ mock โ seed
# You're done! Database is ready with:
# - Your schema
# - Mock data
# - Sample users ([email protected], [email protected])# Migrations
nself db migrate up # Run pending migrations
nself db migrate create NAME # Create new migration
# Mock Data
nself db mock auto # Auto-generate from schema
nself db mock --seed 12345 # Reproducible data
# Types
nself db types # Generate TypeScript types
# Backup
nself db backup # Create backup
nself db backup --compress # Compressed backup
# Shell
nself db shell # Interactive psql
nself db shell --readonly # Read-only shell
# Inspection
nself db inspect # Overview
nself db inspect size # Table sizesv0.4.5 - Provider Support
- Deploy to AWS, GCP, Azure, DigitalOcean, Hetzner, and more
- One-command provisioning:
nself provision hetzner - Cost estimation and comparison
Full Changelog: v0.4.3...v0.4.4