vanilla-rails-data-modeling
Use when designing database schema, writing migrations, or making data storage decisions - enforces UUIDs, account_id multi-tenancy, no foreign keys, and proper index patterns
What this skill does
# Vanilla Rails Data Modeling
Database schema conventions from production 37signals patterns.
**For state-as-records pattern details, see vanilla-rails-models.**
## UUID Primary Keys
All tables use UUIDs. No auto-incrementing integers.
```ruby
create_table :cards, id: :uuid do |t|
t.uuid :account_id, null: false
t.string :title
t.timestamps
end
```
UUIDv7 (timestamp-ordered), base36 encoded as 25-character strings. No ID enumeration, merge-safe, no sequence contention.
## Multi-Tenancy via account_id
Every tenant-scoped table has `account_id`. No exceptions for user data.
**Tables WITHOUT account_id** (global/cross-tenant): `identities`, `sessions`, `magic_links`
Scope queries via `Current.account`:
```ruby
class ApplicationRecord < ActiveRecord::Base
def self.default_scope
where(account_id: Current.account.id) if Current.account
end
end
```
Don't forget `account_id` on join tables.
## No Foreign Key Constraints
Use application-level integrity, not database constraints.
```ruby
# Bad
t.references :card, foreign_key: true
# Good
t.uuid :card_id, null: false
add_index :table, :card_id
```
Prevents deadlocks during bulk operations. Maintain integrity via `dependent: :destroy`.
## Index Strategy
| Pattern | Rule |
|---------|------|
| Composite indexes | Lead with `account_id` |
| Polymorphic | Always `[type, id]` |
| Binary state | `unique: true` on parent_id |
| Per-user state | `unique: [parent_id, user_id]` |
| Tenant uniqueness | `[:account_id, :field]` |
```ruby
add_index :cards, [:account_id, :status]
add_index :events, [:eventable_type, :eventable_id]
add_index :closures, :card_id, unique: true
add_index :pins, [:card_id, :user_id], unique: true
```
## Join Table Patterns
| Need | Pattern | Has ID? | Has account_id? |
|------|---------|---------|-----------------|
| Just link two things | HABTM (`id: false`) | No | No |
| Track when/who linked | `has_many :through` | Yes (`id: :uuid`) | Yes |
**HABTM naming:** `plural_plural` alphabetically (`boards_filters`)
**Through naming:** Singular noun (`taggings`, `assignments`)
```ruby
# HABTM - no metadata needed
create_table :boards_filters, id: false do |t|
t.uuid :board_id, null: false
t.uuid :filter_id, null: false
end
# Through - timestamps, account scoping
create_table :taggings, id: :uuid do |t|
t.uuid :account_id, null: false
t.uuid :card_id, null: false
t.uuid :tag_id, null: false
t.timestamps
end
```
## Polymorphic Associations
Use semantic names describing the relationship:
| Name | Meaning |
|------|---------|
| `eventable` | thing the event is about |
| `source` | where it came from |
| `container` | what holds it |
| `searchable` | what is searchable |
| `recordable` | what it's attached to |
## Counter Caches
Manual `increment!`/`decrement!`, not Rails `counter_cache:` option:
```ruby
after_create :increment_account_counter
private
def increment_account_counter
account.increment!(:cards_count)
end
```
## Settings Tables
Polymorphic config with inheritance fallback:
```ruby
class Board < ApplicationRecord
def auto_postpone_period
entropy&.auto_postpone_period || account.auto_postpone_period
end
end
```
## Migration Conventions
| Rule | Example |
|------|---------|
| Prefer `change` | `def change; add_column ...; end` |
| Explicit UUID refs | `t.uuid :card_id` not `t.references :card` |
| Large table indexes | `add_index :table, :col, algorithm: :concurrently` |
| `up/down` only when irreversible | `remove_column` in `up` |
## Quick Reference
| Decision | Pattern |
|----------|---------|
| Primary key | `id: :uuid` always |
| Tenant column | `account_id` on all tenant tables |
| Foreign keys | None — app-level integrity |
| Simple join | `id: false`, no account_id |
| Rich join | `id: :uuid`, with account_id |
| Polymorphic index | `[type, id]` compound |
| Query index | Lead with `account_id` |
| Counter cache | Manual `increment!` |
## Sharding (Advanced)
For large tables, shard by account using CRC32:
```ruby
def shard_for(account_id)
Zlib.crc32(account_id.to_s) % 16
end
```
16 identical tables, MySQL native fulltext across shards.
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.