-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
51 lines (43 loc) · 1.38 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
50
51
require 'rake'
require './app/models/migration'
task 'db:migrate', :db_migrate do |tsk, args|
raise 'no environment specfied' unless ARGV[1]
environment = ARGV[1].split('=')[1]
if ['test', 'development'].include?(environment)
ENV['RACK_ENV'] = environment
else
raise 'Wrong environment specified'
end
puts "running #{tsk} in #{ENV['RACK_ENV']} mode"
Dir.glob("db/migrations/**").sort.each do |path|
file = path.split('/')[-1]
puts "Attempting migration: #{file}..."
migration = Migration.find_by(file: file)
if migration.nil?
migration = Migration.create(file: path)
print "Migrating..."
migration.run!
puts "Migrated"
else
puts "Skipped."
end
end
end
task 'db:setup', :db_setup do |tsk, args|
raise 'no environment specfied' unless ARGV[1]
environment = ARGV[1].split('=')[1]
if ['test', 'development'].include?(environment)
ENV['RACK_ENV'] = environment
else
raise 'Wrong environment specified'
end
puts "running #{tsk} in #{ENV['RACK_ENV']} mode"
migrations_file = "00_create_table_migrations_with_file.rb"
print 'setting up the migrations table..'
system("ruby db/migrations/#{migrations_file} RACK_ENV=#{ENV['RACK_ENV']}")
puts 'Created.'
print "creating initial migration..."
migration = Migration.create(file: migrations_file)
puts 'Created.'
puts 'Database ready to migrate.'
end