database

rubys's avatarfrom rubys

Database management commands and the bin/run utility for executing Ruby scripts against specific event databases. Use when the user needs to query, manipulate, or run scripts against existing databases without starting a Rails server.

⭐34stars🔀6forks📁View on GitHub🕐Updated Dec 24, 2025

When & Why to Use This Skill

This Claude skill provides a robust suite of database management utilities and a specialized CLI tool for executing Ruby scripts against specific databases. It streamlines backend workflows by allowing developers to perform migrations, seed data, and execute ad-hoc Ruby code without the overhead of starting a full Rails server, making it an essential tool for rapid database manipulation and environment setup.

Use Cases

  • Database Schema Management: Efficiently run migrations, prepare databases, and load seed data using standard commands like db:migrate and db:prepare.
  • Direct Data Manipulation: Use the bin/run utility to execute Ruby scripts or one-liners against specific SQLite3 database files for quick data updates or fixes.
  • Automated Testing Support: Quickly load fixtures and run scripts against test databases to validate application logic in a controlled environment.
  • Ad-hoc Data Extraction: Perform rapid queries to pluck specific data points, such as counting records or listing model attributes, directly from the command line.
namedatabase
descriptionDatabase management commands and the bin/run utility for executing Ruby scripts against specific event databases. Use when the user needs to query, manipulate, or run scripts against existing databases without starting a Rails server.

Database Management

Standard Database Commands

# Prepare database (creates and runs migrations)
bin/rails db:prepare

# Run migrations
bin/rails db:migrate

# Load seed data
bin/rails db:seed

# Load fixtures (for test data)
bin/rails db:fixtures:load

Running Scripts Against Existing Databases

The bin/run command allows you to execute Ruby scripts against any database in the project.

Basic Usage

# Run a script file against a specific database
bin/run db/2025-boston.sqlite3 path/to/script.rb

# Evaluate Ruby code directly against a database
bin/run db/2025-boston.sqlite3 -e "puts Event.current.name"

# Run against test database (automatically loads fixtures)
bin/run test -e "puts Person.count"

Common Query Examples

# Count heats
bin/run db/2025-boston.sqlite3 -e "Heat.count"

# Get all student names
bin/run db/2025-boston.sqlite3 -e "Person.where(type: 'Student').pluck(:name)"

# List studios with person counts
bin/run db/2025-boston.sqlite3 -e "Studio.all.map { |s| [s.name, s.people.count] }"

How bin/run Works

The script automatically sets up:

  • RAILS_APP_DB environment variable from database filename
  • RAILS_STORAGE path for Active Storage files
  • For test database: runs db:prepare and loads fixtures

This allows you to query and manipulate any event database without starting a full Rails server.