ActiveRecord: Cleaning up your database with ignored_colums

Posted . Visible to the public.

Leaving old unused DB columns around after a migration is confusing for other developers. However, dropping columns too eagerly might also cause problems and extra work. If you want to mark columns for future deletion, but are unsure, whether you can simply drop them right now, use these tools:

Add a comment to your DB schema

With schema comments you can add a comment like LEGACY as of yyyy-mm-dd to your DB schema.

Ignore the column

With ignored_columns Show archive.org snapshot you can prevent your Rails models from generating accessor methods for these columns:

class User < ApplicationRecord
  self.ignored_columns += [:legacy_field] # LEGACY as of yyyy-mm-dd
end

If the column was still in use, your test suite should hopefully catch that.

Drop old columns

If the data in that column wasn't needed for a sufficiently long period of time, drop it for real.

Profile picture of Klaus Weidinger
Klaus Weidinger
Last edit
Klaus Weidinger
Keywords
rails
License
Source code in this card is licensed under the MIT License.
Posted by Klaus Weidinger to makandra dev (2026-01-30 13:12)