activerecord-db-tasks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/activerecord-db/tasks.rb +76 -0
- metadata +63 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
db_namespace = namespace :db do
|
5
|
+
task :environment do
|
6
|
+
@db_config = YAML.load_file('config/database.yml')
|
7
|
+
@version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
8
|
+
@step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
9
|
+
end
|
10
|
+
|
11
|
+
task :establish_connection => :environment do
|
12
|
+
ActiveRecord::Base.establish_connection @db_config
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Create the database in config/database.yml'
|
16
|
+
task :create => :environment do
|
17
|
+
ActiveRecord::Base.establish_connection @db_config.merge('database' => nil)
|
18
|
+
ActiveRecord::Base.connection.create_database @db_config['database']
|
19
|
+
db_namespace[:establish_connection].invoke
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Drops the database in config/database.yml'
|
23
|
+
task :drop => :environment do
|
24
|
+
ActiveRecord::Base.establish_connection @db_config.merge('database' => nil)
|
25
|
+
ActiveRecord::Base.connection.drop_database @db_config['database']
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Migrate the database (target specific version with VERSION=x)."
|
29
|
+
task :migrate => :establish_connection do
|
30
|
+
ActiveRecord::Migration.verbose = true
|
31
|
+
ActiveRecord::Migrator.migrate ActiveRecord::Migrator.migrations_paths, @version
|
32
|
+
end
|
33
|
+
|
34
|
+
namespace :migrate do
|
35
|
+
desc 'Runs the "up" for a given migration VERSION.'
|
36
|
+
task :up => :environment do
|
37
|
+
raise 'VERSION is required' unless @version
|
38
|
+
ActiveRecord::Migrator.run :up, ActiveRecord::Migrator.migrations_paths, @version
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Runs the "down" for a given migration VERSION.'
|
42
|
+
task :down => :environment do
|
43
|
+
raise 'VERSION is required' unless @version
|
44
|
+
ActiveRecord::Migrator.run :down, ActiveRecord::Migrator.migrations_paths, @version
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'Rollback the database one migration and re migrate up (options: STEP=x, VERSION=x).'
|
48
|
+
task :redo => :environment do
|
49
|
+
if @version
|
50
|
+
db_namespace['migrate:down'].invoke
|
51
|
+
db_namespace['migrate:up'].invoke
|
52
|
+
else
|
53
|
+
db_namespace['rollback'].invoke
|
54
|
+
db_namespace['migrate'].invoke
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Resets your database using your migrations.'
|
60
|
+
task :reset => ['db:drop', 'db:create', 'db:migrate']
|
61
|
+
|
62
|
+
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
63
|
+
task :rollback => :establish_connection do
|
64
|
+
ActiveRecord::Migrator.rollback ActiveRecord::Migrator.migrations_paths, @step
|
65
|
+
end
|
66
|
+
|
67
|
+
desc 'Pushes the schema to the next version (specify steps w/ STEP=n).'
|
68
|
+
task :forward => :establish_connection do
|
69
|
+
ActiveRecord::Migrator.forward ActiveRecord::Migrator.migrations_paths, @step
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "Retrieves the current schema version number."
|
73
|
+
task :version => :establish_connection do
|
74
|
+
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-db-tasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gabe Smith
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: activerecord-db-tasks provides rake db tasks for ActiveRecord without
|
31
|
+
Rails
|
32
|
+
email:
|
33
|
+
- sgt.floydpepper@gmail.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- lib/activerecord-db/tasks.rb
|
39
|
+
homepage: https://github.com/sgtFloyd/activerecord-db-tasks
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.24
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Rake db tasks for ActiveRecord sans Rails
|
63
|
+
test_files: []
|