-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathRakefile
49 lines (41 loc) · 1.47 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'rake'
require 'rspec/core/rake_task'
require_relative 'db/config'
require_relative 'lib/students_importer'
require_relative 'app/models/teacher'
desc "create the database"
task "db:create" do
touch 'db/ar-students.sqlite3'
touch 'db/ar-students_test.sqlite3'
end
desc "drop the database"
task "db:drop" do
rm_f 'db/ar-students.sqlite3'
rm_f 'db/ar-students_test.sqlite3'
end
desc "migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
task "db:migrate" do
Dir[File.join('db', '*.sqlite3')].each do |db_path|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => "#{File.dirname(__FILE__)}/#{db_path}")
ActiveRecord::Migrator.migrations_paths << File.dirname(__FILE__) + 'db/migrate'
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).migrate do |migration|
ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
end
end
end
desc "populate the students database with sample data"
task "db:populate" do
StudentsImporter.import
end
desc "populate the teachers database with sample data"
task "db:populate_teacher" do
# Create some teachers for your teachers table in database
end
desc 'Retrieves the current schema version number'
task "db:version" do
puts "Current version: #{ActiveRecord::Migrator.current_version}"
end
desc "Run the specs"
RSpec::Core::RakeTask.new(:specs)
task :default => :specs