bard-rake 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bard-rake.gemspec +3 -3
- data/lib/bard/rake/db.rb +58 -16
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/bard-rake.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "bard-rake"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Micah Geisel"]
|
12
|
-
s.date = "2011-12-
|
12
|
+
s.date = "2011-12-12"
|
13
13
|
s.description = "Rake tasks for all bard projects.\n* Bootstrap projects\n* Database backup"
|
14
14
|
s.email = "micah@botandrose.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
]
|
36
36
|
s.homepage = "http://github.com/botandrose/bard-rake"
|
37
37
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = "1.8.
|
38
|
+
s.rubygems_version = "1.8.12"
|
39
39
|
s.summary = "Rake tasks for all bard projects."
|
40
40
|
|
41
41
|
if s.respond_to? :specification_version then
|
data/lib/bard/rake/db.rb
CHANGED
@@ -1,30 +1,72 @@
|
|
1
1
|
namespace :db do
|
2
2
|
desc "Dump the current database to db/data.sql"
|
3
3
|
task :dump => :environment do
|
4
|
-
|
5
|
-
|
6
|
-
sh "#{mysqldump} -e #{mysql_options} > #{file_path}"
|
4
|
+
klass = adapter_from_config BardRake.database_config
|
5
|
+
klass.dump
|
7
6
|
end
|
8
7
|
|
9
8
|
desc "Load the db/data.sql data into the current database."
|
10
9
|
task :load => ["db:drop", "db:create"] do
|
11
|
-
|
12
|
-
|
13
|
-
sh "#{mysql} #{mysql_options} < #{file_path}"
|
10
|
+
klass = adapter_from_config BardRake.database_config
|
11
|
+
klass.load
|
14
12
|
end
|
15
13
|
|
16
|
-
def
|
17
|
-
"
|
14
|
+
def adapter_from_config config
|
15
|
+
"BardRake::#{config["adapter"].camelize}".constantize
|
18
16
|
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module BardRake
|
20
|
+
FILE_PATH = "db/data.sql"
|
21
|
+
|
22
|
+
def self.database_config
|
23
|
+
@config ||= ActiveRecord::Base.configurations[Rails.env || "development"]
|
24
|
+
end
|
25
|
+
|
26
|
+
class Postgresql
|
27
|
+
def self.dump
|
28
|
+
pg_dump = `which pg_dump`.strip
|
29
|
+
raise RuntimeError, "Cannot find pg_dump." if pg_dump.blank?
|
30
|
+
sh "#{pg_dump} -f#{FILE_PATH} #{database}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.load
|
34
|
+
psql = `which psql`.strip
|
35
|
+
raise RuntimeError, "Cannot find psql." if psql.blank?
|
36
|
+
sh "#{psql} -q -d#{database} -f#{FILE_PATH}"
|
37
|
+
end
|
19
38
|
|
20
|
-
|
21
|
-
config = ActiveRecord::Base.configurations[Rails.env || "development"]
|
22
|
-
raise RuntimeError, "I only work with mysql." unless config["adapter"].starts_with? "mysql"
|
39
|
+
private
|
23
40
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
options += " -S #{config["socket"]}" if config["socket"]
|
28
|
-
options += " '#{config["database"]}'"
|
41
|
+
def self.database
|
42
|
+
BardRake.database_config["database"]
|
43
|
+
end
|
29
44
|
end
|
45
|
+
|
46
|
+
class Mysql
|
47
|
+
def self.dump
|
48
|
+
mysqldump = `which mysqldump`.strip
|
49
|
+
raise RuntimeError, "Cannot find mysqldump." if mysqldump.blank?
|
50
|
+
sh "#{mysqldump} -e #{mysql_options} > #{FILE_PATH}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.load
|
54
|
+
mysql = `which mysql`.strip
|
55
|
+
raise RuntimeError, "Cannot find mysql." if mysql.blank?
|
56
|
+
sh "#{mysql} #{mysql_options} < #{FILE_PATH}"
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def self.mysql_options
|
62
|
+
config = BardRake.database_config
|
63
|
+
options = " -u #{config["username"]}"
|
64
|
+
options += " -p'#{config["password"]}'" if config["password"]
|
65
|
+
options += " -h #{config["host"]}" if config["host"]
|
66
|
+
options += " -S #{config["socket"]}" if config["socket"]
|
67
|
+
options += " '#{config["database"]}'"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
Mysql2 = Mysql
|
30
72
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bard-rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 3
|
9
8
|
- 4
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Micah Geisel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
18
|
+
date: 2011-12-12 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
requirements: []
|
91
91
|
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 1.8.
|
93
|
+
rubygems_version: 1.8.12
|
94
94
|
signing_key:
|
95
95
|
specification_version: 3
|
96
96
|
summary: Rake tasks for all bard projects.
|