Wow, another railsconf has come and gone and I’m back home in Victoria.
I’ll be posting some detailed info on some of the most interesting stuff I saw while I was there but I wanted to do a quick summary post of my overall impressions.
First things first, the keynotes where great I think that for me they were worth the effort of coming down for the conference alone.
His last slide left me and a couple of the other VicRuby guys wondering if he had made a subtle reference to the over-hype that has seemed to have exploded around rails over the last couple of years.
David addressed the need for all of us as developers and professionals to both work on our own personal development and also to not worry so much about what technology we are using. Even more importantly he emphasized the importance of not coding and having other interests, other passions and expanding our horizons.
I 100% agree with him, and it left me feeling energized in a new way. The most telling thing for me was that he intentionally said not to worry about whether rails is or will be the best thing to use, but to focus on developing great general skills.
Ok I’m done for now, but more to come on some interesting topics that came out the conference.
Ok so of course the second I posted my rake task I found an excellent blog article talking about rake tasks that has a better implementation of my own task :) Err the blog has an excellent article on rake and his own creation sake (used to access rake tasks at a system level so that they need not be copied into each rails project independently) here.
(for anyone wanting the quick answer here is the much more elegant impl. of the db version task which is now in rails trunk and has been since about June of last summer)
desc "Returns the current schema version"
task :version => :environment do
puts "Current version: " +
ActiveRecord::Migrator.current_version.to_s
end
Not to be out done I have a new rake task for you that I am finding useful, along with the annotate_models plugin this one allows a quick view of a table structure without firing up your mysql client.
desc – Describe the table listing column name and type
desc "Describe database table structure"
task :describe => :environment do
unless ENV.include?('table') && !ENV['table'].blank?
raise "usage: rake db:desc table=table_name"
end
table = ENV['table']
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
result = ActiveRecord::Base.connection.execute("describe #{table}")
puts "table #{table}"
result.each do |row|
puts "#{row[0]} - #{row[1]}"
end
end
Usage: rake db:desc table=table_name
One other useful tidbit contained in this task is the parameter passed into the task, I picked this up from a Jay Field’s article here.
The key is that the parameters to the rake task are passed in the ENV hash and have to be accessed accordingly. I’ve also taken Jay’s approach of verifying the parameter and raising an exception if it is not provided to give the user usage info.
Some useful rake tasks…
I wrote a couple handy rake tasks the other day and thought I’d post them for anyone else who might be interested.
DB Version – this one is handy when you are trying to get into sync with some new migrations, especially if any of the migrations have errors (I know…that should never happen :) )
desc "Get the current schema version"
task :version => :environment do
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
result = ActiveRecord::Base.connection.execute("select * from schema_info")
version = result.fetch_hash['version']
puts "Current Database Schema Version: #{version}"
end
Just add that code to your databases.rake and then you can rake db:version away.