alphagov/whitehall — pull request #244 by chrisroos (2013-02-19 17:30:37+00:00)
Title: Exclude title, summary and body from Edition#columns

This is related to a problem we had with deployment, that pull request #243
set out to fix.

Although we're not referencing these columns in our application, ActiveRecord
will automatically include them in certain queries it generates. By overriding
`Edition.columns` in this way, we're essentially telling ActiveRecord to
ignore these unused columns so that we can safely remove them from the
database in a subsequent commit/deploy.

Once deployed to production we should finally be in a position to remove the
title, summary and body fields from the editions table. The additions in this
commit should be removed at that time too.

You can replicate the error we were seeing in staging, on your development
machine, by removing a database column after the application has loaded. You
can do that by following these steps:

1. Import a relatively recent dump of the production data.

2. Start the Rails console

3. Run the following and observe that it doesn't cause any errors. *NOTE* It
doesn't matter if you don't get any results.

o = Organisation.find_by_slug!('attorney-generals-office')
o.featured_edition_organisations

4. Leaving the Rails console open, open a mysql session to your development
database.

5. Drop the title column from the editions table by running:

alter table editions drop column title;

6. Back in the Rails console, run the following command and observe that you
see an error similar to "ActiveRecord::StatementInvalid: Mysql2::Error:
Unknown column 'editions.title'".

o = Organisation.find_by_slug!('attorney-generals-office')
o.featured_edition_organisations