rails-postgres

Master PostgreSQL in Rails with native types (UUID, JSON/JSONB, arrays, enums), efficient queries, indexes, and optimization. Use when designing databases, writing complex queries, using PostgreSQL-specific features, optimizing performance, or working with specialized data types.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "rails-postgres" with this command: npx skills add shivamsinghchahar/rails-skills/shivamsinghchahar-rails-skills-rails-postgres

PostgreSQL in Rails

Comprehensive guide to using PostgreSQL's powerful features with Rails. Covers datatypes, queries, optimization, indexing, and advanced features for building robust, performant applications.

Quick Start

Enable extensions and create a table with PostgreSQL types:

class CreatePosts < ActiveRecord::Migration[7.1]
  def change
    enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto')
    
    create_table :posts, id: :uuid do |t|
      t.string :title, null: false
      t.text :content
      t.jsonb :metadata, default: {}, null: false
      t.string :tags, array: true, default: []
      t.enum :status, enum_type: :post_status, default: 'draft'
      t.timestamps
    end
    
    add_index :posts, :metadata, using: :gin
    add_index :posts, :tags, using: :gin
  end
end

Access data in models:

class Post < ApplicationRecord
  store_accessor :metadata, :author, :seo_keywords
  enum status: { draft: 'draft', published: 'published', archived: 'archived' }, prefix: true
end

# Usage
post = Post.create(title: "Hello", tags: ['rails'], metadata: { author: 'John' })
post.author # => 'John'
post.status_published! # => sets status to 'published'

Core Topics

Datatypes - UUID, JSON/JSONB, arrays, ranges, enums, and custom types. See references/datatypes/ for detailed guides on each type.

Queries - SQL patterns, joins, aggregations, subqueries, and raw SQL. See references/queries/ for query patterns and real-world examples.

Performance - Indexes, query plans, optimization, and N+1 resolution. See references/performance/ for strategies and best practices.

Advanced Features - Constraints, generated columns, full-text search, and database views. See references/advanced/ for specialized topics.

When to Use This Skill

  • Designing Rails database schemas with PostgreSQL datatypes
  • Writing complex SQL queries and optimizing performance
  • Setting up UUID primary keys and associations
  • Working with JSON, arrays, or enums in migrations
  • Debugging slow queries or creating indexes
  • Using PostgreSQL-specific features like constraints or views

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

rails-testing-rspec

No summary provided by upstream source.

Repository SourceNeeds Review
General

rails-active-job

No summary provided by upstream source.

Repository SourceNeeds Review
General

rails-action-cable

No summary provided by upstream source.

Repository SourceNeeds Review
General

rails-active-storage

No summary provided by upstream source.

Repository SourceNeeds Review