rails_db_dump_restore 0.0.3 → 0.0.4.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bddd9b241052ea794ff118995ccd96bd42ddf39d
4
- data.tar.gz: bb4cd0803311b54c5685333028c3314781c8880d
3
+ metadata.gz: 38154d3e6cba7ea2b1d6c06b8fbb4489364fda7d
4
+ data.tar.gz: 8343112d203e28f1de417746b31f730cbd03f751
5
5
  SHA512:
6
- metadata.gz: e971e094c2497a3bfa38f6076cb118bca26e32db664bee15cf57ce4537ceb9a724aef393a4b87b18f0210b6d1a3d15666e7b8e4e26fbe590a3b6fcf50f65e5e8
7
- data.tar.gz: 36b37c95c8712df3f41a2688161affff239a6bf94b7be3d40c9d125d1dda211293f0b07f580d8f326d384460d78627037e6b7c537e0ee699955d334a0e72fe12
6
+ metadata.gz: 5c2df3a02ba1e0da1a932f7405e265811e6947373bbd449debfc5f89be79b0c04fa4f2b13e20890141bef1a75c458f497cc15e2d51cd07ca1f973eca18112f54
7
+ data.tar.gz: c5ae19aee2797fc6caa24aef27754691cd4f79de3366933eec7f4fec74a5b4ac247b8399550ab1fa8e6e2a0e81c87506cb08624b661a61f52207be8ac5671131
@@ -0,0 +1,92 @@
1
+ module RailsDbDumpRestore
2
+ class Database
3
+ def dump
4
+ system "mkdir -p $(dirname #{dumpfile})"
5
+ path = "#{Rails.root}/#{dumpfile}"
6
+ case ActiveRecord::Base.connection_config[:adapter]
7
+ when "postgresql"
8
+ args = "--clean --no-owner --no-privileges"
9
+
10
+ run """
11
+ PGPASSWORD=#{password}
12
+ pg_dump #{args}
13
+ --host=#{host}
14
+ --username=#{username}
15
+ --dbname=#{database}
16
+ --file=#{path}
17
+ """
18
+ when "mysql2"
19
+ run """
20
+ MYSQL_PWD=#{password}
21
+ mysqldump
22
+ --host=#{host}
23
+ --user=#{username}
24
+ #{database} > #{path}
25
+ """
26
+ end
27
+
28
+ puts "#{Rails.env.to_s} database dumped to #{dumpfile}"
29
+ end
30
+
31
+ def restore
32
+ path = "#{Rails.root}/#{dumpfile}"
33
+ case ActiveRecord::Base.connection_config[:adapter]
34
+ when "postgresql"
35
+ run """
36
+ PGPASSWORD=#{password}
37
+ psql
38
+ --host=#{host}
39
+ --username=#{username}
40
+ --dbname=#{database}
41
+ --file=#{path}
42
+ """
43
+ when "mysql2"
44
+ run """
45
+ MYSQL_PWD=#{password}
46
+ mysql
47
+ --host=#{host}
48
+ --user=#{username}
49
+ #{database} < #{path}
50
+ """
51
+ end
52
+
53
+ puts "#{Rails.env.to_s} database replaced with contents of #{dumpfile}"
54
+ end
55
+
56
+ private
57
+
58
+ def dumpfile
59
+ RailsDbDumpRestore::DUMPFILE
60
+ end
61
+
62
+ def run(multiline_command)
63
+ command = squeeze_into_one_line(multiline_command)
64
+
65
+ if ENV["DEBUG"]
66
+ puts command
67
+ else
68
+ system command
69
+ end
70
+ end
71
+
72
+ def host
73
+ ActiveRecord::Base.connection_config[:host]
74
+ end
75
+
76
+ def username
77
+ ActiveRecord::Base.connection_config[:username] || ENV["USER"]
78
+ end
79
+
80
+ def password
81
+ ActiveRecord::Base.connection_config[:password]
82
+ end
83
+
84
+ def database
85
+ ActiveRecord::Base.connection_config[:database]
86
+ end
87
+
88
+ def squeeze_into_one_line(multiline_string)
89
+ multiline_string.strip.gsub("\n", " ").squeeze(" ")
90
+ end
91
+ end
92
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsDbDumpRestore
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4-alpha"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[rails_db_dump_restore railtie]) if defined?(::Rails::Railtie)
2
2
  require File.join(File.dirname(__FILE__), *%w[rails_db_dump_restore dumpfile])
3
+ require File.join(File.dirname(__FILE__), *%w[rails_db_dump_restore database])
3
4
 
4
5
  module RailsDbDumpRestore
5
6
  end
data/lib/tasks/db.rake CHANGED
@@ -1,94 +1,11 @@
1
1
  namespace :db do
2
- def self.dumpfile
3
- RailsDbDumpRestore::DUMPFILE
4
- end
5
-
6
- def dumpfile
7
- self.class.dumpfile
8
- end
9
-
10
- desc "Dump database to #{dumpfile}"
2
+ desc "Dump database to #{RailsDbDumpRestore::DUMPFILE}"
11
3
  task dump: [:environment] do
12
- system "mkdir -p $(dirname #{dumpfile})"
13
- path = "#{Rails.root}/#{dumpfile}"
14
- case ActiveRecord::Base.connection_config[:adapter]
15
- when "postgresql"
16
- args = "--clean --no-owner --no-privileges"
17
-
18
- run """
19
- PGPASSWORD=#{password}
20
- pg_dump #{args}
21
- --host=#{host}
22
- --username=#{username}
23
- --dbname=#{database}
24
- --file=#{path}
25
- """
26
- when "mysql2"
27
- run """
28
- MYSQL_PWD=#{password}
29
- mysqldump
30
- --host=#{host}
31
- --user=#{username}
32
- #{database} > #{path}
33
- """
34
- end
35
-
36
- puts "#{Rails.env.to_s} database dumped to #{dumpfile}"
4
+ RailsDbDumpRestore::Database.new.dump
37
5
  end
38
6
 
39
- desc "Replace database with contents of #{dumpfile}"
7
+ desc "Replace database with contents of #{RailsDbDumpRestore::DUMPFILE}"
40
8
  task restore: [:environment] do
41
- path = "#{Rails.root}/#{dumpfile}"
42
- case ActiveRecord::Base.connection_config[:adapter]
43
- when "postgresql"
44
- run """
45
- PGPASSWORD=#{password}
46
- psql
47
- --host=#{host}
48
- --username=#{username}
49
- --dbname=#{database}
50
- --file=#{path}
51
- """
52
- when "mysql2"
53
- run """
54
- MYSQL_PWD=#{password}
55
- mysql
56
- --host=#{host}
57
- --user=#{username}
58
- #{database} < #{path}
59
- """
60
- end
61
-
62
- puts "#{Rails.env.to_s} database replaced with contents of #{dumpfile}"
63
- end
64
-
65
- def run(multiline_command)
66
- command = squeeze_into_one_line(multiline_command)
67
-
68
- if ENV["DEBUG"]
69
- puts command
70
- else
71
- system command
72
- end
73
- end
74
-
75
- def host
76
- ActiveRecord::Base.connection_config[:host]
77
- end
78
-
79
- def username
80
- ActiveRecord::Base.connection_config[:username] || ENV["USER"]
81
- end
82
-
83
- def password
84
- ActiveRecord::Base.connection_config[:password]
85
- end
86
-
87
- def database
88
- ActiveRecord::Base.connection_config[:database]
89
- end
90
-
91
- def squeeze_into_one_line(multiline_string)
92
- multiline_string.strip.gsub("\n", " ").squeeze(" ")
9
+ RailsDbDumpRestore::Database.new.restore
93
10
  end
94
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_db_dump_restore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Arvidsson
@@ -62,6 +62,7 @@ files:
62
62
  - lib/capistrano/rails_db_dump_restore.rb
63
63
  - lib/capistrano/tasks/db.rake
64
64
  - lib/rails_db_dump_restore.rb
65
+ - lib/rails_db_dump_restore/database.rb
65
66
  - lib/rails_db_dump_restore/dumpfile.rb
66
67
  - lib/rails_db_dump_restore/railtie.rb
67
68
  - lib/rails_db_dump_restore/version.rb
@@ -84,9 +85,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
85
  version: '0'
85
86
  required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  requirements:
87
- - - ">="
88
+ - - ">"
88
89
  - !ruby/object:Gem::Version
89
- version: '0'
90
+ version: 1.3.1
90
91
  requirements: []
91
92
  rubyforge_project:
92
93
  rubygems_version: 2.2.2