-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
34 lines (29 loc) · 899 Bytes
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
ENV['DATABASE_URL'] ||= 'postgres://localhost/github-explorer'
namespace :db do
task :environment do
require 'logger'
require 'uri'
require 'active_record'
require 'pg'
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
end
desc "Migrate the database"
task(:migrate => :environment) do
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate("db/migrate")
end
desc "Seed the database"
task(:seed => :environment) do
require 'csv'
require './models/category'
require './models/route'
CSV.table("routes.csv").each do |row|
category = Category.find_or_create_by_name(row[:category])
route = Route.new(method: row[:method], name: row[:route])
route.category = category
route.save
puts "#{route.method} #{route.name}"
end
end
end