---
title: "How GitHub converts previously encrypted and unencrypted columns to ActiveRecord encrypted columns"
description: "GitHub migrated plaintext columns and columns encrypted with a deprecated internal library to ActiveRecord::Encryption."
url: "https://swe.quest/articles/how-github-converts-previously-encrypted-and-unencrypted-columns-to-7a6a32eb2ff23c82"
canonical: "https://github.blog/engineering/infrastructure/how-github-converts-previously-encrypted-and-unencrypted-columns-to-activerecord-encrypted-columns/"
source: "GitHub Engineering"
published: "2022-11-03"
difficulty: "medium"
kind: "Case study"
reading_minutes: 7
tags: ["ruby","cryptography","schema-migrations","security","deployment"]
---

# How GitHub converts previously encrypted and unencrypted columns to ActiveRecord encrypted columns

A post on [GitHub Engineering](https://swe.quest/sources/github.md), published 2022-11-03, 7 min read, Case study. Original: [https://github.blog/engineering/infrastructure/how-github-converts-previously-encrypted-and-unencrypted-columns-to-activerecord-encrypted-columns/](https://github.blog/engineering/infrastructure/how-github-converts-previously-encrypted-and-unencrypted-columns-to-activerecord-encrypted-columns/)

## Summary

GitHub migrated plaintext columns and columns encrypted with a deprecated internal library to ActiveRecord::Encryption. It used per-model previous encryptors instead of the global support\_unencrypted\_data option, and a custom ActiveModel type gated by an inverted, long-lived feature flag that acts as an on/off switch for each column. A changed\_in\_place? bug compared decrypted plaintext to stored ciphertext, which raised false 2FA recovery-code alerts in customer security logs; delegating the check to EncryptedAttributeType fixed it. A simplified recipe using a previous encryptor plus the MaintenanceTasks gem backfills existing records, and the same flow handles key rotation by adding a new key and re-running the task.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [Cryptography](https://swe.quest/tags/cryptography.md) (Security)
- [Schema migrations](https://swe.quest/tags/schema-migrations.md) (Data & databases)
- [Security](https://swe.quest/tags/security.md) (Security)
- [Deployment](https://swe.quest/tags/deployment.md) (Reliability & operations)

## Prerequisites

- Ruby on Rails ActiveRecord ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))
- Feature flags ([easy posts on Deployment](https://swe.quest/tags/deployment.md?difficulty=easy))
- Symmetric encryption basics ([easy posts on Cryptography](https://swe.quest/tags/cryptography.md?difficulty=easy))

## Keywords

ActiveRecord::Encryption, Rails, MaintenanceTasks, GitHub, key rotation

## Related posts

- [Why and how GitHub encrypts sensitive database columns using ActiveRecord::Encryption](https://swe.quest/articles/why-and-how-github-encrypts-sensitive-database-columns-using-activerecord-4abc36e2a491f04c.md): GitHub Engineering · 2022-10-26 · Medium · 5 min read · Cryptography, Ruby, Databases, Security
  GitHub replaced its internal Encrypted Attributes library with Rails' ActiveRecord::Encryption so developers can encrypt a sensitive column with a single familiar \`encrypts\` call, without hand-provisioning a key per column.
- [Making Open Source Safer for Everyone with Shopify’s Bug Bounty Program](https://swe.quest/articles/making-open-source-safer-for-everyone-with-shopify-s-bug-bounty-program-48c56c4f3d09ee13.md): Shopify Engineering · 2022-06-15 · Medium · 5 min read · Application security, Ruby, Open source
  A Shopify bug bounty report showed that a leaked Rails development secret could be escalated to remote code execution because ActiveSupport's MessageEncryptor deserialized data with Marshal by default.
- [How GitHub uses CodeQL to secure GitHub](https://swe.quest/articles/how-github-uses-codeql-to-secure-github-3ead357c38ddce28.md): GitHub Engineering · 2025-02-12 · Medium · 14 min read · Static analysis, Application security, Ruby, CI/CD
  GitHub's Product Security Engineering team runs CodeQL across more than 10,000 repositories, mostly with default setup and the security-extended suites.
- [Security Disclosure Recommendation: Rotate MySQL Database Credentials](https://swe.quest/articles/security-disclosure-recommendation-rotate-mysql-database-credentials-79450d4ad1284c9e.md): Railway · 2026-10-22 · Medium · 3 min read · MySQL, Security, Incidents & postmortems, Identity & auth
  Railway MySQL users whose password or MYSQL\_URL may have been exposed should rotate the credential with the Regenerate button in the Database View.
- [Track Schema Changes Automatically in Your Pull Requests](https://swe.quest/articles/track-schema-changes-automatically-in-your-pull-requests-a44727ec3dcc4112.md): Neon · 2024-11-28 · Medium · 5 min read · Schema migrations, CI/CD, PostgreSQL
  Neon's Schema Diff GitHub Action compares the schema of a pull request's Neon child branch against its parent (or a specified base\_branch) and posts the result as an SQL patch in a single PR comment.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
