rails-backup-migrate 0.0.10 → 0.0.11
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/lib/rails-backup-migrate.rb
CHANGED
@@ -34,7 +34,7 @@ module RailsBackupMigrate
|
|
34
34
|
# list the tables we should backup, excluding ones we can ignore
|
35
35
|
def interesting_tables
|
36
36
|
ActiveRecord::Base.connection.tables.sort.reject do |tbl|
|
37
|
-
|
37
|
+
%w(schema_migrations sessions public_exceptions).include?(tbl)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -77,10 +77,10 @@ module RailsBackupMigrate
|
|
77
77
|
@temp_dir = nil
|
78
78
|
@files_to_delete_on_cleanup ||= []
|
79
79
|
@files_to_delete_on_cleanup.each do |f|
|
80
|
-
|
81
|
-
FileUtils.rm f
|
82
|
-
else
|
80
|
+
if File::directory? f
|
83
81
|
FileUtils.rm_r f
|
82
|
+
else
|
83
|
+
FileUtils.rm f
|
84
84
|
end
|
85
85
|
end
|
86
86
|
@files_to_delete_on_cleanup = []
|
@@ -102,10 +102,30 @@ module RailsBackupMigrate
|
|
102
102
|
FileUtils.chdir 'db/backup'
|
103
103
|
|
104
104
|
@files_to_delete_on_cleanup ||= []
|
105
|
-
|
105
|
+
|
106
|
+
@mysql = ActiveRecord::Base.connection.class.to_s =~ /mysql/i
|
107
|
+
|
106
108
|
interesting_tables.each do |tbl|
|
107
109
|
puts "Writing #{tbl}..." if VERBOSE
|
108
|
-
File.open("#{tbl}.yml", 'w+')
|
110
|
+
File.open("#{tbl}.yml", 'w+') do |f|
|
111
|
+
records = ActiveRecord::Base.connection.select_all("SELECT * FROM #{tbl}")
|
112
|
+
if @mysql
|
113
|
+
# we need to convert Mysql::Time objects into standard ruby time objects because they do not serialise
|
114
|
+
# into YAML on their own at all, let alone in a way that would be compatible with other databases
|
115
|
+
records.map! do |record|
|
116
|
+
record.inject({}) do |memo, (k,v)|
|
117
|
+
memo[k] = case v
|
118
|
+
when Mysql::Time
|
119
|
+
datetime_from_mysql_time v
|
120
|
+
else
|
121
|
+
v
|
122
|
+
end
|
123
|
+
memo
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
f << YAML.dump(records)
|
128
|
+
end
|
109
129
|
@files_to_delete_on_cleanup << File::expand_path("#{tbl}.yml")
|
110
130
|
end
|
111
131
|
|
@@ -135,6 +155,16 @@ module RailsBackupMigrate
|
|
135
155
|
# so we'll ensure we have a string
|
136
156
|
Rails.root.to_s
|
137
157
|
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def datetime_from_mysql_time(mysql_time)
|
162
|
+
year = mysql_time.year
|
163
|
+
month = [1,mysql_time.month].max
|
164
|
+
day = [1,mysql_time.day].max
|
165
|
+
DateTime.new year, month, day, mysql_time.hour, mysql_time.minute, mysql_time.second
|
166
|
+
end
|
167
|
+
|
138
168
|
end
|
139
169
|
end
|
140
170
|
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = RailsBackupMigrate::VERSION
|
8
8
|
s.authors = ["Matt Connolly"]
|
9
9
|
s.email = ["matt@soundevolution.com.au"]
|
10
|
-
s.homepage = ""
|
10
|
+
s.homepage = "http://github.com/mattconnolly/rails-backup-migrate"
|
11
11
|
s.summary = %q{Backup and restore a rails application including database data and files}
|
12
12
|
s.description = %q{Creates a directory db/backup in the rails app and creates / loads YML files from there.
|
13
13
|
After a backup, the db/backups directory is archived into a .tgz file and then deleted.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-backup-migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70221255923620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '2.3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70221255923620
|
25
25
|
description: ! "Creates a directory db/backup in the rails app and creates / loads
|
26
26
|
YML files from there. \n After a backup, the db/backups directory is archived
|
27
27
|
into a .tgz file and then deleted.\n When restoring, the db/backup directory
|
@@ -50,7 +50,7 @@ files:
|
|
50
50
|
- lib/rails-backup-migrate/version.rb
|
51
51
|
- lib/tasks/rails-backup-migrate.rake
|
52
52
|
- rails-backup-migrate.gemspec
|
53
|
-
homepage:
|
53
|
+
homepage: http://github.com/mattconnolly/rails-backup-migrate
|
54
54
|
licenses: []
|
55
55
|
post_install_message:
|
56
56
|
rdoc_options: []
|
@@ -70,9 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project: rails-backup-migrate
|
73
|
-
rubygems_version: 1.8.
|
73
|
+
rubygems_version: 1.8.17
|
74
74
|
signing_key:
|
75
75
|
specification_version: 3
|
76
76
|
summary: Backup and restore a rails application including database data and files
|
77
77
|
test_files: []
|
78
|
-
has_rdoc:
|