Koskamo

Active Record migrations

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

Migrations evolve database schemas reproducibly via Ruby DSLs, ensuring database independence without manual SQL. Treat each migration as a database version; they modify tables, columns, or indexes to update the schema timeline. Active Record tracks this history, updating db/schema.rb to reflect the current structure. Define forward changes using change methods; for instance, create_table adds tables with implicit id primary keys. Use macros like string, text, and timestamps to define columns, noting that timestamps creates created_at and updated_at, which Active Record manages automatically. Consider reversibility, as Active Record can rollback changes to remove tables. For complex extensions, enable features like pg_catalog.plpgsql within the schema definition. This approach ensures schema changes are versioned, trackable, and reversible, maintaining consistency between the codebase and database structure. Scope: Rails. Reviewed October 4, 2026.

Source and provenance

Original source
guides.rubyonrails.org
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.