rails-migration

Standardize Rails migrations with UUID primary keys and explicit indexes.

Updated Oct 12, 2024
One-click install
npx skills add https://github.com/samrocks03/shuttle-office-service --skill rails-migration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-migration
Source: https://github.com/samrocks03/shuttle-office-service/tree/main/.claude/skills/rails-migration
Command: npx skills add https://github.com/samrocks03/shuttle-office-service --skill rails-migration

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Standardizes Rails migrations by enforcing UUID primary keys, a gen_random_uuid() default, and explicit, consistently named indexes across tables.

Core Features & Use Cases

  • UUID Primary Keys with pgcrypto and a uid column defaulting to gen_random_uuid()
  • Explicitly named indexes for all critical columns (e.g., index_<table>on<column>)
  • Foreign keys as UUIDs using *_uid suffix; avoid t.references for UUID tables
  • Array columns with default [] for PostgreSQL denormalized lists
  • Boolean columns with explicit defaults and timestamps included
  • Bulk table creation via create_table bulk: true for performance
  • Guidance for common migration tasks: add_column, create_table, add_index

Quick Start

Enable the pgcrypto extension and create new tables with a uid primary key defaulting to gen_random_uuid(), plus a unique index on uid.

Frequently Asked Questions about rails-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use UUID primary keys in Rails migrations with PostgreSQL?

To use UUID primary keys in Rails migrations, enable the pgcrypto extension and define a uid column defaulting to gen_random_uuid(). This ensures your PostgreSQL tables generate secure, unique identifiers automatically.

What is the correct way to index UUID foreign keys in ActiveRecord migrations?

Indexing UUID foreign keys in ActiveRecord requires explicitly naming indexes using the index_<table>_on_<column> convention. Avoid t.references for UUID tables and instead use *_uid suffixes for foreign key columns.

Do I need pgcrypto to generate UUID defaults in Rails?

Yes, pgcrypto is required to generate UUID defaults in Rails on PostgreSQL. The extension provides the gen_random_uuid() function, which must be enabled before creating tables with UUID primary keys.

What's the best way to standardize Rails migration naming conventions for indexes and foreign keys?

The best way to standardize Rails migration naming is to enforce explicit, consistent names like index_<table>_on_<column> for indexes and *_uid suffixes for foreign keys, ensuring predictable schema management.

How do I create tables in Rails migrations with bulk performance and UUID defaults?

Create tables in Rails migrations with bulk performance by using create_table bulk: true, defining a uid primary key with gen_random_uuid() default, and adding a unique index on the uid column.

Can PostgreSQL array and boolean columns have explicit defaults in Rails migrations?

Yes, PostgreSQL array columns can default to an empty array [], and boolean columns should have explicit defaults in Rails migrations. This prevents null values and ensures consistent data states.