Updated for nself v1.0.12
One of the most features of ɳSelf's database management is its integration with dbdiagram.io, a popular visual database design tool. This integration enables a complete visual-to-code workflow, allowing you to design your database schema visually and synchronize it with your ɳSelf project.
dbdiagram.io is a free, simple tool to draw entity-relationship (ER) diagrams by just writing code. Created by Holistics (the same team behind DBML), it provides:
The ɳSelf + dbdiagram.io integration provides:
Design your schema visually at dbdiagram.io, then create a migration:
# Create a named migration from your DBML design
nself db migrate create imported_schema
# Edit the generated migration file with your SQL, then apply:
nself db migrate up
# This creates:
# - nself/migrations/20260122_imported_schema.up.sql
# - nself/migrations/20260122_imported_schema.down.sqlGenerate DBML from your existing database:
# Export current database schema to DBML
nself db schema diagram > schema.dbml
# Open the generated file at dbdiagram.io to visualize# Step 1: Create migration from your DBML design
nself db migrate create my_schema
# Step 2: Apply pending migrations
nself db migrate up
# Step 3: Run seeds and mock data (local/staging only)
nself db seed
nself db mock autonself v1.0.12 provides pre-built migration templates to get started quickly. Create a named migration and fill it with your schema SQL:
# Create a new migration for your schema
nself db migrate create basic_schema # Users, profiles, posts
nself db migrate create ecommerce_schema # Products, orders, cart
nself db migrate create saas_schema # Organizations, members, projects
nself db migrate create blog_schema # Posts, categories, comments
# Edit the generated .up.sql file, then apply:
nself db migrate upnself db migrate create my_schema then fill the SQL filenself db migrate upnself db schema diagram > schema.dbmlCompare your local schema with another environment:
nself db schema diff staging
# Example output:
# Schema Differences (local vs staging)
# ────────────────────────────────────
# + Table: user_preferences (missing in staging)
# ~ Column: users.last_login (different type)
# - Index: idx_orders_date (missing in local)Get index suggestions based on your schema:
nself db schema indexes
# Example output:
# Index Recommendations
# ─────────────────────
# [HIGH] orders.user_id - Frequently joined, no index
# [MEDIUM] products.category_id - Used in WHERE clauses
# [LOW] users.created_at - Occasional range queriesKeep your visual designs versioned alongside your code:
# Export and commit diagram snapshots
nself db schema diagram > schema.dbml
git add schema.dbml
git commit -m "Update schema diagram"# Problem: Import fails with parse error
# Solution: Check DBML syntax:
# - Column names must be valid identifiers
# - Types must be supported
# - Brackets must be balanced
# Tip: Validate at dbdiagram.io before importing# Check status and repair if needed
nself db migrate status
nself db migrate repair # Fix tracking table# Migration commands (v1.0.0)
nself db migrate create NAME # Create new migration file
nself db migrate up # Apply pending migrations
nself db migrate down # Rollback last migration
nself db migrate status # Check migration status
nself db schema diagram # Database to DBML (reverse engineer)
# After changes in dbdiagram.io:
# 1. Export DBML from dbdiagram.io
# 2. nself db migrate create my_changes
# 3. Fill the .up.sql with your SQL, then: nself db migrate upNow that you understand dbdiagram.io integration:
The dbdiagram.io integration makes database design a collaborative, visual process while maintaining all the benefits of code-based schema management.