/db/migrations/201205222133_add_slugs.rb
Ruby | 23 lines | 16 code | 6 blank | 1 comment | 2 complexity | 24d2661e214c015052b4c3d7c7759550 MD5 | raw file
1# encoding: UTF-8
2
3db = URI.parse(ENV['MONGOHQ_URL'])
4db_name = db.path.gsub(/^\//, '')
5
6db_connection = Mongo::Connection.new(db.host, db.port).db(db_name)
7db_connection.authenticate(db.user, db.password) unless (db.user.nil? || db.user.nil?)
8
9migrations = db_connection['migrations']
10
11if migrations.find_one({file: __FILE__})
12 puts "Skipping: #{__FILE__}"
13else
14 puts "Migrating: #{__FILE__}"
15 puts 'adding slug'
16
17 Club.all.each do |club|
18 puts club.generate_slug
19 end
20
21 migrations.insert({file: __FILE__})
22 puts "\tDone!"
23end