collectiveidea / audited

Audited (formerly acts_as_audited) is an ORM extension that logs all changes to your Rails models.
MIT License
3.38k stars 662 forks source link

Adding column request_uuid impractical for tables with millions of rows? #205

Open pooch opened 9 years ago

pooch commented 9 years ago

We're trying to use version 4 of this gem along with our move from Rails 4.0 to Rails 4.1.

Migration works fine for our development DBs (MySQL) that have thousands of rows in audits, but when we try against one of our smaller production DBs (with 3 million rows; the largest has 27 million rows), we lose our SQL connection: “Mysql2::Error: Lost connection to MySQL server during query: ALTER TABLE audits ADD request_uuid varchar(255)”

Our ops guys say the entire table is being copied by this alter statement, driving disk IO to over 50% and locking the audits table from writes during the process.

Has anyone with a high volume of audits records been able to move to version 4 of this gem without halting production systems for many minutes?

danielmorrison commented 9 years ago

I don't know enough about how MySQL's alter statements work, but if anyone knows a way around this please submit a PR.

tiegz commented 9 years ago

I haven't run into the upgrade yet, but I'd recommend using the lhm gem to do online schema changes. We've been using it for years successfully to do migrations of large/busy tables.