Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: After an LHM migration does rails require a restart? #74

Closed
shaley91 opened this issue Oct 1, 2014 · 2 comments
Closed

Question: After an LHM migration does rails require a restart? #74

shaley91 opened this issue Oct 1, 2014 · 2 comments

Comments

@shaley91
Copy link

shaley91 commented Oct 1, 2014

This is a question not an issue, but I wasn't sure the best place to ask.

After a migration (using lhm) has run does the rails server require a restart to clear the ActiveRecord Cache? I originally thought it did but I ran a few quick tests and am now not sure.

Example

User model

class User < ActiveRecord::Base
 ...
  def get_name
    "TEST - #{self.name}"
  end
end

Before Migration

> User.first
#<User id: 1>
> User.first.name
undefined method `name' for #<User:...>
> User.first.get_name
undefined method `name' for #<User:...>

Run a migration to add name column to user model

After Migration

> User.first
#<User id: 1>
> User.first.name
nil
> User.first.get_name
=> "TEST - "
@grobie
Copy link
Contributor

grobie commented Oct 4, 2014

I can only speak for Rails 2.3 (I haven't worked with rails anymore in the last few years), but the ActiveRecord cache needs to be reloaded there. Did you start your console in production environment? I don't think that caching is activate in development.

The only time it gets really critical is when a migration drops columns though, as ActiveRecord will spit out exceptions in this case. Back in the days when I worked on a bigger rails service using LHM, we came up with something which would wrap the ActiveRecord::Base#create method, rescue ActiveRecord::StatementInvalid exceptions matching /Mysql::Error: Unknown column '(\w+)' in 'field list'/ and calling <Model>.reset_column_information.

Besides that edge case where ARs caching mechanism gets in the way, I'd recommend to write code in a way that it can deal with pre- and post-migration SQL tables. Then it doesn't matter when instances get restarted and migration can happen at any point.

Does this help?

@shaley91
Copy link
Author

Yeah. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants