forked from posty/posty_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
50 lines (43 loc) · 1.69 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
task :environment do
env = ENV["RACK_ENV"] ? ENV["RACK_ENV"] : "development"
require File.expand_path('../config/environment', __FILE__)
end
namespace :api_key do
desc "Creates a new api key"
task :generate => :environment do
ApiKey.create
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