Ruby on Rails Integration
DevDb Pro provides zero-config database discovery for Ruby on Rails projects, automatically reading your config/database.yml to connect to your database.
Zero-Config Discovery
DevDb automatically detects Rails databases from your project configuration.
How It Works
- Open a Rails project in VS Code
- DevDb reads
config/database.yml - Extracts database config for current environment
- Auto-connects to your database
Requirements
- Rails project with
config/database.yml - Standard Rails database configuration
- Database server running and accessible
Supported Databases
DevDb works with these Rails database adapters:
- SQLite (
sqlite3) - MySQL (
mysql2) - PostgreSQL (
postgresql)
Configuration Examples
SQLite
config/database.yml:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000DevDb automatically connects to the SQLite file.
MySQL
config/database.yml:
development:
adapter: mysql2
encoding: utf8mb4
database: myapp_development
pool: 5
username: root
password: secret
host: 127.0.0.1
port: 3306DevDb reads credentials and connects to MySQL.
PostgreSQL
config/database.yml:
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: postgres
password: secret
host: localhost
port: 5432DevDb connects to PostgreSQL automatically.
Environment Detection
DevDb reads the Rails environment to select the right configuration:
Default Behavior
By default, DevDb uses the development environment:
development: # ← DevDb uses this
adapter: postgresql
database: myapp_development
test:
adapter: postgresql
database: myapp_test
production:
adapter: postgresql
database: myapp_productionEnvironment Variables
If RAILS_ENV is set, DevDb uses that environment:
export RAILS_ENV=test # DevDb uses 'test' configMultiple Databases
Rails 6+ supports multiple databases:
config/database.yml:
development:
primary:
adapter: postgresql
database: myapp_primary
username: postgres
password: secret
analytics:
adapter: mysql2
database: myapp_analytics
username: root
password: secretDevDb detects and lists both databases:
myapp_primary(PostgreSQL)myapp_analytics(MySQL)
Switch between them in the DevDb sidebar.
ERB Templates
DevDb supports ERB in database.yml:
config/database.yml:
development:
adapter: postgresql
database: <%= ENV['DB_NAME'] || 'myapp_development' %>
username: <%= ENV['DB_USER'] || 'postgres' %>
password: <%= ENV.fetch('DB_PASSWORD') %>
host: <%= ENV['DB_HOST'] || 'localhost' %>DevDb processes ERB and resolves environment variables.
Features
Database Client
Full Database Client features:
- Browse tables and data
- Inline editing
- Schema viewer
- JSON preview
Quick Table Access
Use Cmd+K Cmd+G (Mac) or Ctrl+K Ctrl+G (Windows/Linux):
- Quickly open any ActiveRecord model table
- Search across all databases
- Instant navigation
Context Menu
Right-click table/model names in code:
- "Open table at cursor" - View table in DevDb
- Works with model class names
- Works with custom table names
Example:
# Right-click "User" and select "DevDb > Open table at cursor"
class User < ApplicationRecord
# ...
end
# Also works with custom table names
class Product < ApplicationRecord
self.table_name = 'products'
endData Export
- JSON format - For seeds or testing
- SQL format - For migrations or backups
- Copy to clipboard or save to file
Workflow Examples
Example 1: Inspect Models
After creating models and running migrations:
- Run migrations:
rails db:migrate - Open DevDb (
Cmd+K Cmd+DorCtrl+K Ctrl+D) - Browse tables to verify schema
- Check indexes in Schema tab
- Add test data directly
Example 2: Debug Data Issues
When investigating data problems:
- Open relevant model in code
- Right-click model name → "Open table at cursor"
- Browse actual data in database
- Edit test records to reproduce issue
- Verify fix by refreshing data
Example 3: Create Seed Data
Generate seed data:
- Create test data in DevDb
- Export as SQL using Data Export
- Add to
db/seeds.rb:
# db/seeds.rb
ActiveRecord::Base.connection.execute(
File.read('path/to/export.sql')
)- Run:
rails db:seed
Example 4: Migration Verification
After writing migrations:
- Apply migration:
rails db:migrate - Refresh DevDb connection
- View schema changes in Schema tab
- Verify constraints and indexes
- Test with sample data
Rails-Specific Features
ActiveRecord Table Names
DevDb handles Rails table naming conventions:
Default naming (pluralized):
class Product < ApplicationRecord # Table: products
endCustom naming:
class Product < ApplicationRecord
self.table_name = 'inventory_items' # Table: inventory_items
endDevDb recognizes both patterns.
Schema Migrations
View migration history:
- Open
schema_migrationstable - See applied migrations
- Check versions
- Verify migration order
Rails Metadata Tables
DevDb shows all Rails metadata tables:
schema_migrationsar_internal_metadata- ActiveStorage tables (if used)
- ActionText tables (if used)
Troubleshooting
Database Not Detected
If DevDb doesn't find your Rails database:
- Check
config/database.ymlexists - Verify YAML syntax is valid
- Ensure database is running
- Reload VS Code window
Connection Fails
If connection doesn't work:
- Test Rails connection:
rails dbconsole - Check credentials in database.yml
- Verify database server is accessible
- Review environment variables
ERB Processing Errors
If ERB templates cause issues:
- Test ERB manually:
rails runner "puts Rails.configuration.database_configuration" - Check environment variables are set
- Verify ERB syntax in database.yml
Docker/Container Setup
For containerized Rails:
- Expose database port in docker-compose.yml:
services:
db:
ports:
- "5432:5432" # PostgreSQL- Use host port in database.yml:
development:
host: localhost
port: 5432- DevDb connects to exposed port
Best Practices
Development
- Use separate databases for dev and test
- Keep sensitive data out of database.yml (use ERB + env vars)
- Add database dumps to
.gitignore - Export fixtures for test data
Team Collaboration
- Document database setup in README
- Share sample .env file (
.env.example) - Use consistent database versions
- Export seed data for onboarding
Security
- Never commit credentials to git
- Use ERB + environment variables for sensitive data:
production:
password: <%= ENV['DATABASE_PASSWORD'] %>- Exclude
.devdbrcfrom version control - Sanitize exports before sharing
Integration with Other Tools
Rails Console
Use DevDb alongside Rails Console:
- DevDb for quick visual inspection
- Rails Console for complex queries
- Export from DevDb for scripting
ActiveAdmin
Combine with ActiveAdmin:
- DevDb for raw data access
- ActiveAdmin for admin interface
- Quick verification of admin changes
Testing
Use DevDb for test data:
- Create test data in DevDb
- Export as SQL
- Use in fixtures or factories:
# test/fixtures/users.yml
generated_from_devdb:
# ... data from DevDb exportDatabase Cleaner
Verify cleaning with DevDb:
- Run tests with DatabaseCleaner
- Check in DevDb that tables are clean
- Debug cleanup issues visually
Environment-Specific Tips
Development
- Use DevDb for quick data inspection
- Edit seed data directly
- Test associations by browsing relations
Test
- Verify test database schema matches development
- Check fixtures load correctly
- Debug test failures by inspecting data
Production (Local Mirror)
- Never connect DevDb to production directly
- Use database dump for local inspection:
pg_dump production_db | psql local_mirror- Browse mirror safely in DevDb
Next Steps
- Database Client - Master the interface
- Quick Table Access - Navigate efficiently
- Data Export - Export fixtures
- Configuration - Manual setup if needed