-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathRakefile
56 lines (48 loc) · 1.77 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
52
53
54
55
56
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new :spec
task default: :spec
rescue LoadError
end
task :environment do
require File.expand_path('../config/environment', __FILE__)
end
namespace :api_key do
desc 'Creates a new api key'
task generate: :environment do
puts ApiKey.create(expires_at: Time.now + 100.years).access_token
end
end
namespace :db do
desc 'Migrate the database through scripts in db/migrate'
task(migrate: :environment) do
ActiveRecord::Migrator.migrate('db/migrate', ENV['VERSION'] ? ENV['VERSION'].to_i : nil)
Rake::Task['db:schema:dump'].invoke if ActiveRecord::Base.schema_format == :ruby
end
namespace :migrate do
desc 'Runs the "down" for a given migration VERSION'
task(down: :environment) do
ActiveRecord::Migrator.down('db/migrate', ENV['VERSION'] ? ENV['VERSION'].to_i : nil)
Rake::Task['db:schema:dump'].invoke if ActiveRecord::Base.schema_format == :ruby
end
desc 'Runs the "up" for a given migration VERSION'
task(up: :environment) do
ActiveRecord::Migrator.up('db/migrate', ENV['VERSION'] ? ENV['VERSION'].to_i : nil)
Rake::Task['db:schema:dump'].invoke if ActiveRecord::Base.schema_format == :ruby
end
desc 'Rollbacks the database one migration and re migrate up'
task(redo: :environment) do
ActiveRecord::Migrator.rollback('db/migrate', 1)
ActiveRecord::Migrator.up('db/migrate', nil)
Rake::Task['db:schema:dump'].invoke if ActiveRecord::Base.schema_format == :ruby
end
end
namespace :schema do
task dump: :environment do
require 'active_record/schema_dumper'
File.open(ENV['SCHEMA'] || 'db/schema.rb', 'w') do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
end
end
end