namespace :db do
  namespace :edge do

    desc 'Setup the EDGE database after fresh clone from PRODUCTION.'
    task :setup => :environment do
      require_edge

      # FIXME: for now this is hardcoded to the connect_demo
      master = Account.master
      # FIXME: since we're experiencing failures in AR, I'll skip it
      #master.domain = 'edge.3scale.net'
      #master.site_access_code = 'hypnotoad'
      Account.connection.execute "UPDATE accounts SET domain='master-monster.3scale.net', site_access_code='hypnotoad' WHERE id = #{master.id}"
      #master.save!

      admin = master.users.first
      # FIXME: this is not needed as it's being done in a migration
      #admin.update_attribute(:role, :admin)
      admin.update_password('hypnotoad', 'hypnotoad')
      admin.update_attribute(:username, '3scale_support')
    end


    def require_edge
      puts 'You can run this task only in `edge` environment' and return unless Rails.env == 'edge'
    end

  end
end
