ferry 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +0 -1
- data/Gemfile +0 -1
- data/README.md +18 -36
- data/bin/ferry +51 -14
- data/doc/ferry_readme_icon.png +0 -0
- data/doc/ferry_readme_icon_2.png +0 -0
- data/ferry.gemspec +11 -11
- data/lib/ferry.rb +8 -266
- data/lib/ferry/exporter.rb +117 -0
- data/lib/ferry/importer.rb +57 -0
- data/lib/ferry/switcher.rb +21 -0
- data/lib/ferry/utilities.rb +42 -0
- data/lib/ferry/version.rb +1 -1
- data/spec/config/database.yml +20 -0
- data/spec/contexts.rb +20 -0
- data/spec/ferry_spec.rb +5 -0
- data/spec/models/cart.rb +10 -0
- data/spec/models/category.rb +7 -0
- data/spec/models/order.rb +7 -0
- data/spec/models/product.rb +9 -0
- data/spec/sets/cart_context.rb +57 -0
- data/spec/sets/category_context.rb +18 -0
- data/spec/sets/order_context.rb +56 -0
- data/spec/sets/product_context.rb +38 -0
- data/spec/spec_helper.rb +20 -5
- data/spec/support/categories_import.csv +1 -0
- data/spec/support/factories.rb +27 -0
- data/spec/support/schema.rb +28 -13
- data/spec/tests/exporter_tests.rb +105 -0
- data/spec/tests/importer_tests.rb +69 -0
- metadata +114 -45
- data/spec/ferry.sqlite3 +0 -0
- data/spec/lib/ferry_spec.rb +0 -9
- data/spec/support/data.rb +0 -11
- data/spec/support/models.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91d7f7634081a1b9e9e14f49f90406bb8b73b468
|
4
|
+
data.tar.gz: 06e43c90a6164a35d0550986938f341ced9057a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ff5c819939ec96fd0b950495611cda42ce84bcf98819510eb53490d660c052cac28e25ef3991c899e42fb31affcfd91f3b557b7e642304d5fb87a51bf506a35
|
7
|
+
data.tar.gz: d334eb819e200b038cc2fe252621c14ae0ca87c4766e0297b979398ab0f77032af4b54bb9172e792851c0ce6d5ed17077af599aa2ef4e07c6d9542ad56f2c2a6
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,44 +1,26 @@
|
|
1
|
-
![ferry](doc/
|
1
|
+
![ferry](doc/ferry_readme_icon_2.png)
|
2
|
+
|
3
|
+
<!-- ![Build Status](https://travis-ci.org/cmu-is-projects/ferry.png)(https://travis-ci.org/cmu-is-projects/ferry) -->
|
2
4
|
|
3
5
|
## What is Ferry?
|
4
|
-
Ferry is a data
|
6
|
+
Ferry is a command-line tool rubygem designed for for data migrations and manipulation, maintained as an open-source project by the students of [Carnegie Mellon's Information Systems department](http://www.cmu.edu/information-systems/) currently [Anthony Corletti](http://github.com/anthcor) and [Logan Watanabe](http://github.com/loganwatanabe). The inspiration for ferry was brought from collective internship experiences and from the growing prevalence of big data migration and manipulation challenges that companies, corporations, universities, and organizations face in today's information age.
|
5
7
|
|
6
|
-
## What can I use Ferry for?
|
7
|
-
See the [ferry_demo](http://github.com/cmu-is-projects/ferry_demo.com)
|
8
|
+
## What can I use Ferry for?
|
9
|
+
See the [ferry_demo](http://github.com/cmu-is-projects/ferry_demo.com) app or our [GitHub pages site](http://cmu-is-projects.github.com/ferry) for guidance on using Ferry!
|
8
10
|
|
9
|
-
Migration
|
10
|
-
- Exporting data to various file formats (.csv, .
|
11
|
+
Migration and Manipulation use cases
|
12
|
+
- Exporting data to various file formats (.csv, .yml, .sql)
|
11
13
|
- Importing data from various file formats
|
12
14
|
- Migrating data to third party hosts (Amazon S3, Oracle)
|
13
15
|
- Migrating data to a different database
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
## TO-DOs
|
23
|
-
- [ ] Refactoring before public release October 17th!!!
|
24
|
-
- [ ] TEST!!! EVERYTHING!!!
|
25
|
-
- [ ] Provide working example(s) of using ferry (see [ferry_demo](http://github.com/cmu-is-projects/ferry_demo.com) app)
|
26
|
-
- [x] ferry --help
|
27
|
-
- [x] CLI tool dev
|
28
|
-
- [x] Simple CSV/YAML export & import
|
29
|
-
- [x] using sqlite3
|
30
|
-
- [x] using psql
|
31
|
-
- [x] using MySQL
|
32
|
-
- [ ] using other dbs ...
|
33
|
-
- [ ] Forking processes to make them faster!
|
34
|
-
- [ ] RESTful column interaction
|
35
|
-
- [ ] db switcher
|
36
|
-
- [ ] handling dependency installation (db or gem dependencies)
|
37
|
-
- [ ] 3rd party connections (importing and exporting data to S3 or related services)
|
38
|
-
- [ ] Understanding relationships between generating migrations and migration files in place
|
39
|
-
- [ ] Rolling back on errors / mishaps during migrations and manipulations
|
40
|
-
- [ ] error catching and give proper clues to fix errors
|
41
|
-
- [ ] Host documentation site via GitHub pages (ferry.github.io)
|
17
|
+
## Some current development items
|
18
|
+
#### Please feel free to open an issue or pull request with your suggestions
|
19
|
+
- Database-switcher guide tool
|
20
|
+
- 3rd party connections
|
21
|
+
- Allowing user to write own rake tasks (e.g. importing and exporting data to S3 or related services)
|
22
|
+
- Rolling back on errors or mishaps during migrations and manipulations
|
23
|
+
- Host API and docs via GitHub pages
|
42
24
|
|
43
25
|
## Installation
|
44
26
|
Add this line to your application's Gemfile:
|
@@ -48,17 +30,17 @@ gem 'ferry'
|
|
48
30
|
|
49
31
|
And then execute:
|
50
32
|
``` sh
|
51
|
-
bundle
|
33
|
+
$ bundle
|
52
34
|
```
|
53
35
|
|
54
36
|
Or install it yourself as:
|
55
37
|
``` sh
|
56
|
-
gem install ferry
|
38
|
+
$ gem install ferry
|
57
39
|
```
|
58
40
|
|
59
41
|
To view what Ferry can do for you just run:
|
60
42
|
``` sh
|
61
|
-
ferry --help
|
43
|
+
$ ferry --help
|
62
44
|
```
|
63
45
|
|
64
46
|
## Contributing
|
data/bin/ferry
CHANGED
@@ -1,17 +1,54 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'ferry'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
4
|
+
OptionParser.new do |opts|
|
5
|
+
options = {}
|
6
|
+
opts.banner = "See full documentation at http://cmu-is-projects.github.io/ferry"
|
7
|
+
|
8
|
+
opts.on("--to_csv <env,table>", 'Exports table to csv file in db/ferry_to_csv_[your db environment]') do |opt|
|
9
|
+
list = opt.split(",")
|
10
|
+
raise "please enter a field for environment and table" unless list.length == 2
|
11
|
+
options[:input] = list
|
12
|
+
exporter = Ferry::Exporter.new
|
13
|
+
exporter.to_csv(options[:input][0], options[:input][1])
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on("--to_yaml <env,table>", 'Exports table to yaml file in db/ferry_to_csv_[your db environment]') do |opt|
|
17
|
+
list = opt.split(",")
|
18
|
+
raise "please enter a field for environment and table" unless list.length == 2
|
19
|
+
options[:input] = list
|
20
|
+
exporter = Ferry::Exporter.new
|
21
|
+
exporter.to_yaml(options[:input][0], options[:input][1])
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('--import <env,tablename,file>', 'Imports data from specified file into table and environment of your specification') do |opt|
|
25
|
+
list = opt.split(",")
|
26
|
+
raise "please enter a field for environment and table and filename" unless list.length == 3
|
27
|
+
options[:input] = list
|
28
|
+
importer = Ferry::Importer.new
|
29
|
+
importer.import(options[:input][0], options[:input][1], options[:input][2])
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('--db_switch <env,adapter>', 'Switches specified database env to a new adapter') do |opt|
|
33
|
+
list = opt.split(",")
|
34
|
+
raise "please enter a field for environment and table" unless list.length == 2
|
35
|
+
options[:input] = list
|
36
|
+
questionmaster = Ferry::Utilities.new
|
37
|
+
if questionmaster.continue?("Are you sure you want to switch to a #{options[:input][1]} database in your #{options[:input][0]} env? It could result in installing software that impacts your project.")
|
38
|
+
switcher = Ferry::Switcher.new
|
39
|
+
switcher.to_new_db_type(options[:input][0], options[:input][1])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on('--init', 'Initializes ferry.rb file in config directory') do |opt|
|
44
|
+
filemaker = Ferry::Utilities.new
|
45
|
+
filemaker.init
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on_tail('-h', '--help', 'Shows this message') do
|
49
|
+
puts opts
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
|
53
|
+
puts opts if ARGV[0] == nil
|
54
|
+
end.parse!
|
data/doc/ferry_readme_icon.png
CHANGED
Binary file
|
Binary file
|
data/ferry.gemspec
CHANGED
@@ -10,22 +10,22 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["anthcor@gmail.com", "loganwatanabe@gmail.com", "profh@cmu.edu"]
|
11
11
|
spec.summary = "Ferry is a data migration and data manipulation tool"
|
12
12
|
spec.description = "Ferry is a data migration and data manipulation tool that seeks to simplify the increasingly prevalent big data problems for developers"
|
13
|
-
spec.homepage = "https://
|
13
|
+
spec.homepage = "https://cmu-is-projects.github.io/ferry"
|
14
14
|
spec.license = "MIT"
|
15
|
-
|
16
15
|
spec.files = `git ls-files -z`.split("\x0")
|
17
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
|
-
spec.add_development_dependency "activerecord"
|
20
|
+
spec.add_development_dependency "activerecord", "~> 4.1.7"
|
22
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
-
spec.add_development_dependency "
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "
|
27
|
-
spec.add_development_dependency "
|
28
|
-
spec.add_development_dependency "
|
29
|
-
|
30
|
-
|
22
|
+
spec.add_development_dependency "rake", "~> 10.3.2"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.4.1"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.1.0"
|
25
|
+
spec.add_development_dependency "pg", "~> 0.17.1"
|
26
|
+
spec.add_development_dependency "sqlite3", "~> 1.3.10"
|
27
|
+
spec.add_development_dependency "mysql2", "~> 0.3.16"
|
28
|
+
spec.add_development_dependency "factory_girl", "~> 4.5.0"
|
29
|
+
spec.add_runtime_dependency "progressbar", "~> 0.21.0"
|
30
|
+
spec.add_runtime_dependency "highline", "~> 1.6.21"
|
31
31
|
end
|
data/lib/ferry.rb
CHANGED
@@ -1,274 +1,16 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'csv'
|
3
|
+
require 'enumerator'
|
4
|
+
require 'ferry/exporter'
|
5
|
+
require 'ferry/importer'
|
6
|
+
require 'ferry/utilities'
|
7
|
+
require 'ferry/switcher'
|
3
8
|
require 'ferry/version'
|
9
|
+
require 'highline/import'
|
4
10
|
require 'progressbar'
|
11
|
+
require 'optparse'
|
12
|
+
require 'pp'
|
5
13
|
require 'yaml'
|
6
14
|
|
7
15
|
module Ferry
|
8
|
-
class Exporter
|
9
|
-
|
10
|
-
def which_db_env
|
11
|
-
ARGV[1]
|
12
|
-
end
|
13
|
-
|
14
|
-
def switch_to_db_type
|
15
|
-
ARGV[2]
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
# test to_csv
|
20
|
-
# chekc that all files exist, first and last records match
|
21
|
-
|
22
|
-
def to_csv
|
23
|
-
info = YAML::load(IO.read("config/database.yml"))
|
24
|
-
db_type = info[which_db_env]["adapter"]
|
25
|
-
case db_type
|
26
|
-
when "sqlite3"
|
27
|
-
puts "operating with sqlite3"
|
28
|
-
homedir = "lib/ferry_to_csv_#{which_db_env}"
|
29
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: info[which_db_env]['database'])
|
30
|
-
puts "connected to #{which_db_env} env db"
|
31
|
-
FileUtils.mkdir homedir unless Dir[homedir].present?
|
32
|
-
puts "exporting tables to #{homedir}"
|
33
|
-
sqlite_pbar = ProgressBar.new("sqlite_to_csv", 100)
|
34
|
-
ActiveRecord::Base.connection.tables.each do |model|
|
35
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
36
|
-
if !full_table[0].nil?
|
37
|
-
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
38
|
-
size = full_table[0].length / 2
|
39
|
-
keys = full_table[0].keys.first(size)
|
40
|
-
csv << keys
|
41
|
-
full_table.each do |row|
|
42
|
-
csv << row.values_at(*keys)
|
43
|
-
sqlite_pbar.inc
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
when "postgresql"
|
49
|
-
puts "operating with postgres"
|
50
|
-
homedir = "lib/ferry_to_csv_#{which_db_env}"
|
51
|
-
ActiveRecord::Base.establish_connection(adapter: db_type, database: info[which_db_env]['database'])
|
52
|
-
puts "connected to #{which_db_env} env db"
|
53
|
-
FileUtils.mkdir homedir unless Dir[homedir].present?
|
54
|
-
puts "exporting tables to #{homedir}"
|
55
|
-
psql_pbar = ProgressBar.new("psql_to_csv", 100)
|
56
|
-
ActiveRecord::Base.connection.tables.each do |model|
|
57
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
58
|
-
if full_table.num_tuples > 0
|
59
|
-
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
60
|
-
keys = full_table[0].keys
|
61
|
-
csv << keys
|
62
|
-
full_table.each do |row|
|
63
|
-
csv << row.values_at(*keys)
|
64
|
-
psql_pbar.inc
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
when "mysql2"
|
70
|
-
puts "operating with mysql2"
|
71
|
-
homedir = "lib/ferry_to_csv_#{which_db_env}"
|
72
|
-
puts "connected to #{which_db_env} env db"
|
73
|
-
ActiveRecord::Base.establish_connection(adapter: db_type, database: info[which_db_env]['database'])
|
74
|
-
puts "connected to #{which_db_env} env db"
|
75
|
-
FileUtils.mkdir homedir unless Dir[homedir].present?
|
76
|
-
puts "exporting tables to #{homedir}"
|
77
|
-
mysql_bar = ProgressBar.new("psql_to_csv", 100)
|
78
|
-
ActiveRecord::Base.connection.tables.each do |model|
|
79
|
-
columns = ActiveRecord::Base.connection.execute(
|
80
|
-
"SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS`
|
81
|
-
WHERE `TABLE_SCHEMA`= '#{info[which_db_env]['database']}' AND `TABLE_NAME`='#{model}';")
|
82
|
-
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
83
|
-
col_names=[]
|
84
|
-
columns.each do |col|
|
85
|
-
col_names.append(col[0])
|
86
|
-
end
|
87
|
-
csv << col_names
|
88
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
89
|
-
full_table.each do |row|
|
90
|
-
csv << row
|
91
|
-
mysql_bar.inc
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
when "mongo"
|
96
|
-
puts "mongo is currently unsupported"
|
97
|
-
else
|
98
|
-
puts "Unknown db type or no database associated with this application."
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def to_new_db_type
|
103
|
-
info = YAML::load(IO.read("config/database.yml"))
|
104
|
-
current_db_type = info[which_db_env]["adapter"]
|
105
|
-
puts "switching the #{which_db_env} database's adapter"
|
106
|
-
puts "current_db_type: #{current_db_type}"
|
107
|
-
puts "to_new_db_type: #{switch_to_db_type}"
|
108
|
-
|
109
|
-
if ['sqlite', 'postgresql', 'mysql'].include?(switch_to_db_type)
|
110
|
-
info[which_db_env]["adapter"] = switch_to_db_type
|
111
|
-
puts "switching #{which_db_env} env to #{switch_to_db_type} ... "
|
112
|
-
File.open("config/database.yml", "w") {|f| f.write info.to_yaml}
|
113
|
-
puts "switched #{which_db_env} env to #{switch_to_db_type}"
|
114
|
-
else
|
115
|
-
puts "#{switch_to_db_type} is currently unsupported"
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
def import_csv
|
121
|
-
# importing for different cases
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
def to_yaml
|
126
|
-
info = YAML::load(IO.read("config/database.yml"))
|
127
|
-
db_type = info[which_db_env]["adapter"]
|
128
|
-
case db_type
|
129
|
-
when "sqlite3"
|
130
|
-
puts "operating with sqlite3"
|
131
|
-
homedir = "lib/ferry_to_yaml_#{which_db_env}"
|
132
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: info[which_db_env]['database'])
|
133
|
-
puts "connected to #{which_db_env} env db"
|
134
|
-
FileUtils.mkdir homedir unless Dir[homedir].present?
|
135
|
-
puts "exporting tables to #{homedir}"
|
136
|
-
sqlite_pbar = ProgressBar.new("sqlite_to_yaml", 100)
|
137
|
-
i = 0
|
138
|
-
ActiveRecord::Base.connection.tables.each do |model|
|
139
|
-
db_object = {}
|
140
|
-
db_output = {}
|
141
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
142
|
-
if !full_table[0].nil?
|
143
|
-
size = full_table[0].length / 2
|
144
|
-
keys = full_table[0].keys.first(size)
|
145
|
-
db_object["columns"] = keys
|
146
|
-
model_arr=[]
|
147
|
-
full_table.each do |row|
|
148
|
-
model_arr << row.values_at(*keys)
|
149
|
-
end
|
150
|
-
db_object["records"] = model_arr
|
151
|
-
db_output[model] = db_object
|
152
|
-
if i==0
|
153
|
-
File.open("#{homedir}/#{which_db_env}_data.yml",'w') do |file|
|
154
|
-
YAML::dump(db_output, file)
|
155
|
-
end
|
156
|
-
else
|
157
|
-
File.open("#{homedir}/#{which_db_env}_data.yml",'a') do |file|
|
158
|
-
YAML::dump(db_output, file)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
i+=1
|
162
|
-
end
|
163
|
-
end
|
164
|
-
sqlite_pbar.inc
|
165
|
-
sqlite_pbar.finish
|
166
|
-
|
167
|
-
when "postgresql"
|
168
|
-
puts "operating with postgres"
|
169
|
-
homedir = "lib/ferry_to_yaml_#{which_db_env}"
|
170
|
-
ActiveRecord::Base.establish_connection(adapter: db_type, database: info[which_db_env]['database'])
|
171
|
-
puts "connected to #{which_db_env} env db"
|
172
|
-
FileUtils.mkdir homedir unless Dir[homedir].present?
|
173
|
-
puts "exporting tables to #{homedir}"
|
174
|
-
psql_pbar = ProgressBar.new("psql_to_yaml", 100)
|
175
|
-
|
176
|
-
i = 0
|
177
|
-
ActiveRecord::Base.connection.tables.each do |model|
|
178
|
-
db_object = {}
|
179
|
-
db_output = {}
|
180
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
181
|
-
if !full_table[0].nil?
|
182
|
-
keys = full_table[0].keys
|
183
|
-
db_object["columns"] = keys
|
184
|
-
model_arr=[]
|
185
|
-
full_table.each do |row|
|
186
|
-
model_arr << row.values_at(*keys)
|
187
|
-
end
|
188
|
-
db_object["records"] = model_arr
|
189
|
-
db_output[model] = db_object
|
190
|
-
if i==0
|
191
|
-
File.open("#{homedir}/#{which_db_env}_data.yml",'w') do |file|
|
192
|
-
YAML::dump(db_output, file)
|
193
|
-
end
|
194
|
-
else
|
195
|
-
File.open("#{homedir}/#{which_db_env}_data.yml",'a') do |file|
|
196
|
-
YAML::dump(db_output, file)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
i+=1
|
200
|
-
end
|
201
|
-
end
|
202
|
-
psql_pbar.inc
|
203
|
-
psql_pbar.finish
|
204
|
-
|
205
|
-
when "mysql2"
|
206
|
-
puts "operating with mysql2"
|
207
|
-
homedir = "lib/ferry_to_yaml_#{which_db_env}"
|
208
|
-
puts "connected to #{which_db_env} env db"
|
209
|
-
ActiveRecord::Base.establish_connection(adapter: db_type, database: info[which_db_env]['database'])
|
210
|
-
puts "connected to #{which_db_env} env db"
|
211
|
-
FileUtils.mkdir homedir unless Dir[homedir].present?
|
212
|
-
puts "exporting tables to #{homedir}"
|
213
|
-
mysql_bar = ProgressBar.new("psql_to_yaml", 100)
|
214
|
-
i=0
|
215
|
-
ActiveRecord::Base.connection.tables.each do |model|
|
216
|
-
db_object = {}
|
217
|
-
columns = ActiveRecord::Base.connection.execute(
|
218
|
-
"SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS`
|
219
|
-
WHERE `TABLE_SCHEMA`= '#{info[which_db_env]['database']}' AND `TABLE_NAME`='#{model}';")
|
220
|
-
|
221
|
-
col_names=[]
|
222
|
-
columns.each do |col|
|
223
|
-
col_names.append(col[0])
|
224
|
-
end
|
225
|
-
db_object["columns"] = col_names
|
226
|
-
model_arr=[]
|
227
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
228
|
-
full_table.each do |row|
|
229
|
-
model_arr << row
|
230
|
-
end
|
231
|
-
db_object["records"] = model_arr
|
232
|
-
db_export = {}
|
233
|
-
db_export[model] = db_object
|
234
|
-
|
235
|
-
if i==0
|
236
|
-
File.open("#{homedir}/#{which_db_env}_data.yml",'w') do |file|
|
237
|
-
YAML::dump(db_export, file)
|
238
|
-
end
|
239
|
-
else
|
240
|
-
File.open("#{homedir}/#{which_db_env}_data.yml",'a') do |file|
|
241
|
-
YAML::dump(db_export, file)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
i+=1
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
mysql_bar.inc
|
249
|
-
mysql_bar.finish
|
250
|
-
|
251
|
-
when "mongo"
|
252
|
-
puts "mongo is currently not supported"
|
253
|
-
else
|
254
|
-
puts "Unknown db type or no database associated with this application."
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
def export_to_service(*args)
|
269
|
-
# exporting to services like AWS
|
270
|
-
end
|
271
|
-
|
272
|
-
|
273
|
-
end
|
274
16
|
end
|