You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:...>
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.
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
Before Migration
Run a migration to add name column to user model
After Migration
The text was updated successfully, but these errors were encountered: