vanilla-rails-data-modeling

Enforce UUID primary keys, account_id multi-tenancy, and state-as-record patterns in Rails data modeling.

3|Updated Dec 25, 2025
One-click install
npx skills add https://github.com/ZempTime/zemptime-marketplace --skill vanilla-rails-data-modeling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vanilla-rails-data-modeling
Source: https://github.com/ZempTime/zemptime-marketplace/tree/main/vanilla-rails/skills/data-modeling
Command: npx skills add https://github.com/ZempTime/zemptime-marketplace --skill vanilla-rails-data-modeling

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill standardizes Rails data modeling by enforcing UUID primary keys, account_id based multi-tenancy, and state-as-record patterns, ensuring auditability and scalable design across teams.

Core Features & Use Cases

  • UUID primary keys: All tables use UUIDs to avoid ID enumeration and enable timestamp ordering.
  • Multi-tenancy via account_id: Every tenant-scoped table includes account_id for isolation.
  • State as records: Replace boolean flags with dedicated state tables to track who changed what and when.
  • Index and join patterns: Guidance on leading account_id in composite indexes and robust join table patterns.
  • Migration conventions: Reversible migrations with UUID references and explicit patterns for large tables.

Quick Start

Apply these conventions to your Rails schema to enforce UUIDs, account scoping, and state-tracking for auditable data.

Frequently Asked Questions about vanilla-rails-data-modeling

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

FAQPage Schema
How do I structure a Rails database for multi-tenancy?

To structure a Rails database for multi-tenancy, include an account_id column on every tenant-scoped table and ensure it leads in composite indexes. This enforces data isolation and scalable query performance across tenants.

Why use UUID primary keys instead of sequential IDs in Rails?

Using UUID primary keys instead of sequential IDs in Rails prevents ID enumeration and enables timestamp-based record ordering. This approach enhances security and supports distributed data generation without collisions.

What is the state-as-record pattern in Rails data modeling?

The state-as-record pattern in Rails data modeling replaces boolean flags with dedicated state tables. This tracks who changed what and when, providing full auditability for status transitions instead of overwriting previous values.

Should I use database-level foreign key constraints for multi-tenant Rails apps?

For multi-tenant Rails apps using this modeling convention, you should not use database-level foreign key constraints. Instead, enforce application-level validations and use reversible migrations with explicit UUID reference patterns.

How do I create reversible Rails migrations for large multi-tenant tables?

To create reversible Rails migrations for large multi-tenant tables, apply explicit schema conventions using UUID references. Ensure account_id leads in indexes and utilize robust join table patterns to maintain performance during schema changes.

How do I index multi-tenant tables for scalable Rails queries?

To index multi-tenant tables for scalable Rails queries, ensure account_id is the leading column in composite indexes. This allows the database to filter by tenant efficiently before applying additional query conditions.