Open Source Rails Engine

👁️ DBViewer

The fastest way to visualize and explore your database

DBViewer is a powerful Rails engine that provides a comprehensive interface to view, explore, and manage database tables, records, and schema. It's designed for development, debugging, and database analysis, offering a clean and intuitive way to interact with your application's database.

10+
Key Features
Full
CRUD Operations
Multiple
Databases

✨ Key Features

Interactive Dashboard

Comprehensive overview with database statistics, analytics, and quick access to all tables and relationships.

SQL Query Editor

Write and execute SQL queries with syntax highlighting, auto-completion, and paginated results display.

Schema Browser

Navigate your database schema visually. Explore tables, columns, relationships, and indexes without writing SQL.

Entity Relationship Diagrams

Interactive ERD visualization showing table relationships, foreign keys, and database structure at a glance.

Data Management

Full CRUD operations (Create, Read, Update, Delete) for database records with intuitive interfaces and validation.

Access Control

Table and column-level access restrictions, authentication, and configurable security features for production safety.

PII Data Masking

Protect sensitive data with configurable masking rules. Automatically mask emails, phone numbers, SSNs, and custom fields while preserving data structure.

Multiple Database Support

Connect to multiple databases simultaneously, switch between connections, and manage different database environments.

🚀 Quick Installation

Get DBViewer up and running in your Rails application in just a few steps.

1

Add to Gemfile

Add DBViewer to your application's Gemfile:

ruby
gem "dbviewer"
2

Install Dependencies

Run bundle to install the gem:

bash
bundle install
3

Mount the Engine

Add the engine to your routes file:

ruby
Rails.application.routes.draw do
  # Your application routes...

  # Mount the DBViewer engine
  mount Dbviewer::Engine, at: "/dbviewer"
end
4

Configure (Optional)

Generate configuration file for customization:

bash
rails generate dbviewer:install
5

API-only Applications

For Rails API-only applications, add Flash middleware:

ruby
# config/application.rb
module YourApp
  class Application < Rails::Application
    # ... existing configuration

    # Required for DBViewer flash messages
    config.middleware.use ActionDispatch::Flash
  end
end

🔧 Configuration Options

Customize DBViewer with the generated configuration file:

ruby
# config/initializers/dbviewer.rb
Dbviewer.configure do |config|
  # Datatable Pagination Settings
  config.per_page_options = [10, 20, 50, 100, 250]   # Default pagination options
  config.default_per_page = 20                        # Default records per page

  # SQL Query Settings
  config.max_query_length = 10000                     # Maximum SQL query length
  config.cache_expiry = 300                           # Cache expiration in seconds
  config.max_records = 10000                          # Maximum records to return in any query
  config.query_timeout = 30                           # SQL query timeout in seconds

  # Data Management Options
  config.enable_data_export = false                   # Whether to allow data exporting
  config.enable_record_deletion = true                # Whether to allow record deletion
  config.enable_record_editing = true                 # Whether to allow record editing

  # Query Logging Options
  config.enable_query_logging = false                 # Enable or disable query logging completely
  config.query_logging_mode = :memory                 # Storage mode for SQL queries (:memory or :file)
  config.query_log_path = "log/dbviewer.log"          # Path for query log file when in :file mode
  config.max_memory_queries = 1000                    # Maximum number of queries to store in memory

  # Authentication Options
  # config.admin_credentials = { username: "admin", password: "your_secure_password" }

  # Table and Column Access Control
  # config.access_control_mode = :whitelist           # :whitelist, :blacklist, or :none (default)
  # config.allowed_tables = ['users', 'orders', 'products']  # Only these tables accessible
  # config.blocked_tables = ['admin_users', 'sensitive_data'] # These tables blocked
  # config.blocked_columns = {                        # Hide sensitive columns from specific tables
  #   'users' => ['password_digest', 'api_key', 'secret_token'],
  #   'orders' => ['internal_notes']
  # }

  # Multiple Database Support
  config.database_connections = {
    primary: {
      connection_class: "ActiveRecord::Base",
      name: "Primary Database"
    },
    secondary: {
      connection_class: "SecondaryDatabase",
      name: "Blog Database"
    }
  }
  config.current_connection = :primary

  # Disable DBViewer completely in production
  # config.disabled = Rails.env.production?
end

🔐 PII Data Masking Configuration

Protect sensitive data with configurable masking rules:

ruby
# config/initializers/dbviewer.rb
Dbviewer.configure do |config|
  config.enable_pii_masking = true                   # Enable PII masking (default: true)
end

# Define PII masking rules
Dbviewer.configure_pii do |pii|
  # Built-in masking types
  pii.mask 'users.email', with: :email              # john@example.com → jo***@example.com
  pii.mask 'users.phone', with: :phone              # +1234567890 → +1***90
  pii.mask 'users.ssn', with: :ssn                  # 123456789 → ***-**-6789
  pii.mask 'payments.card_number', with: :credit_card # 1234567890123456 → ****-****-****-3456
  pii.mask 'users.api_key', with: :full_redact      # any_value → ***REDACTED***

  # Custom masking with lambda
  pii.mask 'users.salary', with: ->(value) { value ? '$***,***' : value }

  # Define reusable custom masks
  pii.custom_mask :ip_mask, ->(value) {
    return value if value.nil?
    parts = value.split('.')
    "#{parts[0]}.#{parts[1]}.***.***.***"
  }
  pii.mask 'logs.ip_address', with: :ip_mask
end

🔒 Security Features

Protect your database with comprehensive security features:

  • Data Management Security: Create and modify operations with proper validation
  • SQL Validation: Prevents potentially harmful operations with comprehensive validation
  • Query Limits: Automatic LIMIT clause to prevent excessive data retrieval
  • Authentication: HTTP Basic Authentication with username/password protection
  • Access Control: Whitelist/blacklist specific tables or columns
  • Production Safety: Option to completely disable in production environments

🔄 Data Management Features

DBViewer provides a complete set of CRUD operations for your database records:

Create: Add new records via a user-friendly modal form with field validation
Read: Browse and view detailed record information with relationship navigation
Update: Edit existing records through an intuitive form interface
Delete: Remove records with confirmation dialogs to prevent accidental deletion

All data management features can be individually enabled or disabled through configuration options.

✨ Try the Live Demo

Experience DBViewer's full capabilities with our interactive demo featuring real sample data.

Dashboard Overview

Visualize your database structure and access key statistics at a glance

Table Management

Browse, edit, and manage database records with full CRUD operations

Interactive Schema

Explore database relationships through visual diagrams

📖 Open Source & Documentation

DBViewer is completely open source. Explore the code, contribute to the project, or deploy it in your own applications with full documentation and examples.

MIT Licensed
🚀 Production Ready
🔒 Security Focused
✏️ Full CRUD