ferry 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/README.md +20 -14
- data/Rakefile +0 -3
- data/doc/ferry_readme_icon.png +0 -0
- data/ferry.gemspec +1 -1
- data/lib/ferry.rb +64 -203
- data/lib/ferry/version.rb +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 634ec552fec9ef82ef5cb4b7b73f11c1155c9377
|
4
|
+
data.tar.gz: 6fd552539d14caed7f34924511f7dfa9c75eeb4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 453943fab59526c5b1a36f7704a5f6a1f54df57b324558c766c2416e42baa3fcb300c03628a1d84e014b1e23dfceb9a6f4b576fe23151162ab6ca70b9d4d81ad
|
7
|
+
data.tar.gz: 786dbff062dacd6ce0a9366458c7933378d026237b84973319f789deee0b54cd2914a972d239827196f05da1c81136b4e7af95b9cdc9b2fe5f006f9c24072fe8
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
![ferry](doc/ferry_readme_icon.png)
|
2
2
|
|
3
3
|
## What is Ferry?
|
4
4
|
Ferry is a data migration and data manipulation tool that seeks to quickly and easily reduce overhead when dealing with big data problems.
|
@@ -15,32 +15,38 @@ Migration
|
|
15
15
|
- Migrating data to third party hosts (Amazon S3, Oracle)
|
16
16
|
- Migrating data to a different database
|
17
17
|
|
18
|
+
### Datebase to CSV
|
19
|
+
Currently, Ferry supports SQLite, PosgreSQL, and MySQL database connections ...
|
20
|
+
Making a simple call like ```ferry to_csv yourdbenvironment``` in any Rails app and Ferry will place a folder in your lib directory with a folder titled ferry_to_csv_yourdbenvironment.
|
21
|
+
|
18
22
|
## TO-DOs
|
19
|
-
- [ ] Refactoring before public release
|
20
|
-
- [
|
21
|
-
- [
|
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
|
+
- [ ] ferry --help
|
22
27
|
- [ ] CLI tool
|
23
28
|
- [ ] Simple CSV export
|
24
|
-
- [
|
25
|
-
- [
|
29
|
+
- [x] using sqlite3
|
30
|
+
- [x] using psql
|
31
|
+
- [x] using MySQL
|
32
|
+
- [ ] using other dbs ...
|
33
|
+
- [ ] Simple CSV import
|
34
|
+
- [ ] Simple YAML export
|
35
|
+
- [ ] Simple CSV import
|
26
36
|
- [ ] RESTful column interaction
|
27
37
|
- [ ] Understanding relationships between generating migrations and migration files in place
|
28
|
-
- [ ] Tests
|
29
38
|
- [ ] Rolling back on errors / mishaps during migrations and manipulations
|
30
|
-
- [ ] Host documentation site via GitHub pages
|
39
|
+
- [ ] Host documentation site via GitHub pages (ferry.github.io)
|
31
40
|
|
32
41
|
## Installation
|
33
42
|
Add this line to your application's Gemfile:
|
34
|
-
|
35
|
-
gem 'ferry'
|
43
|
+
```gem 'ferry'```
|
36
44
|
|
37
45
|
And then execute:
|
38
|
-
|
39
|
-
$ bundle
|
46
|
+
```bundle```
|
40
47
|
|
41
48
|
Or install it yourself as:
|
42
|
-
|
43
|
-
$ gem install ferry
|
49
|
+
```gem install ferry```
|
44
50
|
|
45
51
|
## Contributing
|
46
52
|
|
data/Rakefile
CHANGED
Binary file
|
data/ferry.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "activerecord"
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
-
|
23
|
+
spec.add_development_dependency "progressbar"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "minitest"
|
26
26
|
spec.add_development_dependency "rspec"
|
data/lib/ferry.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'csv'
|
3
3
|
require 'ferry/version'
|
4
|
-
|
4
|
+
require 'progressbar'
|
5
5
|
require 'yaml'
|
6
6
|
|
7
7
|
module Ferry
|
@@ -17,221 +17,78 @@ module Ferry
|
|
17
17
|
|
18
18
|
def to_csv
|
19
19
|
info = YAML::load(IO.read("config/database.yml"))
|
20
|
-
db_type = info[which_db_env
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
#issues:
|
25
|
-
# csv placement in directory: do we want it in the lib?
|
26
|
-
# the case where dev/test dbs are different from production db (sqlite for dev/test, pg for prod??)
|
27
|
-
# empty ARGs
|
28
|
-
# ARGs with invalid values
|
29
|
-
|
30
|
-
|
20
|
+
db_type = info[which_db_env]["adapter"]
|
31
21
|
case db_type
|
32
22
|
when "sqlite3"
|
33
23
|
puts "operating with sqlite3"
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
csv << keys
|
51
|
-
full_table.each do |row|
|
52
|
-
csv << row.values_at(*keys)
|
53
|
-
# sqlite_pbar.inc
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
else #no db_env is specified
|
59
|
-
info.keys.each do |environment|
|
60
|
-
|
61
|
-
if(environment == 'default') #in Rails 4.1+ environments inherit from default, which does not have database so we will not include it
|
62
|
-
next
|
63
|
-
end
|
64
|
-
|
65
|
-
homedir = "lib/ferry_to_csv_#{environment}"
|
66
|
-
ActiveRecord::Base.establish_connection(adapter: db_type, database: info[environment]['database']) #connect to sqlite3 file
|
67
|
-
puts "connected to #{environment} env db"
|
68
|
-
FileUtils.mkdir homedir unless Dir[homedir].present?
|
69
|
-
puts "exporting tables to #{homedir}"
|
70
|
-
# sqlite_pbar = ProgressBar.new("sqlite_to_csv", 100)
|
71
|
-
ActiveRecord::Base.connection.tables.each do |model| #for each model in the db
|
72
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};") #get all the records
|
73
|
-
if !full_table[0].nil?
|
74
|
-
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
75
|
-
size = full_table[0].length / 2
|
76
|
-
keys = full_table[0].keys.first(size)
|
77
|
-
#first row contains column names
|
78
|
-
csv << keys
|
79
|
-
full_table.each do |row|
|
80
|
-
csv << row.values_at(*keys)
|
81
|
-
# sqlite_pbar.inc
|
82
|
-
end
|
83
|
-
end
|
24
|
+
homedir = "lib/ferry_to_csv_#{which_db_env}"
|
25
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: info[which_db_env]['database'])
|
26
|
+
puts "connected to #{which_db_env} env db"
|
27
|
+
FileUtils.mkdir homedir unless Dir[homedir].present?
|
28
|
+
puts "exporting tables to #{homedir}"
|
29
|
+
sqlite_pbar = ProgressBar.new("sqlite_to_csv", 100)
|
30
|
+
ActiveRecord::Base.connection.tables.each do |model|
|
31
|
+
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
32
|
+
if !full_table[0].nil?
|
33
|
+
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
34
|
+
size = full_table[0].length / 2
|
35
|
+
keys = full_table[0].keys.first(size)
|
36
|
+
csv << keys
|
37
|
+
full_table.each do |row|
|
38
|
+
csv << row.values_at(*keys)
|
39
|
+
sqlite_pbar.inc
|
84
40
|
end
|
85
41
|
end
|
86
42
|
end
|
87
43
|
end
|
88
|
-
|
89
44
|
when "postgresql"
|
90
45
|
puts "operating with postgres"
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
108
|
-
# do not create a csv for an empty table
|
109
|
-
if full_table.num_tuples > 0
|
110
|
-
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
111
|
-
size = full_table[0].length / 2
|
112
|
-
keys = full_table[0].keys.first(size)
|
113
|
-
#first row contains column names
|
114
|
-
csv << keys
|
115
|
-
full_table.each do |row|
|
116
|
-
csv << row.values_at(*keys)
|
117
|
-
# psql_pbar.inc
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
else
|
123
|
-
info.keys.each do |environment|
|
124
|
-
|
125
|
-
if(environment == 'default') #in Rails 4.1+ environments inherit from default, which does not have database so we will not include it
|
126
|
-
next
|
127
|
-
end
|
128
|
-
homedir = "lib/ferry_to_csv_#{environment}"
|
129
|
-
|
130
|
-
ActiveRecord::Base.establish_connection(
|
131
|
-
adapter: 'postgresql',
|
132
|
-
host: info[environment]['host'] || 'localhost',
|
133
|
-
username: info[environment]['username'],
|
134
|
-
password: info[environment]['password'],
|
135
|
-
database: info[environment]['database'],
|
136
|
-
encoding: info[environment]['encoding']
|
137
|
-
)
|
138
|
-
puts "connected to #{environment} env db"
|
139
|
-
FileUtils.mkdir homedir unless Dir[homedir].present?
|
140
|
-
puts "exporting tables to #{homedir}"
|
141
|
-
# psql_pbar = ProgressBar.new("psql_to_csv", 100)
|
142
|
-
ActiveRecord::Base.connection.tables.each do |model|
|
143
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
144
|
-
# do not create a csv for an empty table
|
145
|
-
if full_table.num_tuples > 0
|
146
|
-
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
147
|
-
size = full_table[0].length / 2
|
148
|
-
keys = full_table[0].keys.first(size)
|
149
|
-
#first row contains column names
|
150
|
-
csv << keys
|
151
|
-
full_table.each do |row|
|
152
|
-
csv << row.values_at(*keys)
|
153
|
-
# psql_pbar.inc
|
154
|
-
end
|
155
|
-
end
|
46
|
+
homedir = "lib/ferry_to_csv_#{which_db_env}"
|
47
|
+
ActiveRecord::Base.establish_connection(adapter: db_type, database: info[which_db_env]['database'])
|
48
|
+
puts "connected to #{which_db_env} env db"
|
49
|
+
FileUtils.mkdir homedir unless Dir[homedir].present?
|
50
|
+
puts "exporting tables to #{homedir}"
|
51
|
+
psql_pbar = ProgressBar.new("psql_to_csv", 100)
|
52
|
+
ActiveRecord::Base.connection.tables.each do |model|
|
53
|
+
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
54
|
+
if full_table.num_tuples > 0
|
55
|
+
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
56
|
+
size = full_table[0].length / 2
|
57
|
+
keys = full_table[0].keys.first(size)
|
58
|
+
csv << keys
|
59
|
+
full_table.each do |row|
|
60
|
+
csv << row.values_at(*keys)
|
61
|
+
psql_pbar.inc
|
156
62
|
end
|
157
63
|
end
|
158
64
|
end
|
159
65
|
end
|
160
66
|
when "mysql2"
|
161
67
|
puts "operating with mysql2"
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
ActiveRecord::Base.connection.tables.each do |model| #for each model in the db
|
179
|
-
columns = ActiveRecord::Base.connection.execute("SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`= '#{info[which_db_env]['database']}' AND `TABLE_NAME`='#{model}';")
|
180
|
-
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
181
|
-
|
182
|
-
col_names=[]
|
183
|
-
columns.each do |col|
|
184
|
-
col_names.append(col[0]) #append the column names to an array, makes for good formatting
|
185
|
-
end
|
186
|
-
csv << col_names #first csv row is of column names
|
187
|
-
|
188
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
189
|
-
full_table.each do |row|
|
190
|
-
csv << row #not sure if this will hold, but no 'values_at' method exists
|
191
|
-
# psql_pbar.inc
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
else
|
196
|
-
info.keys.each do |environment|
|
197
|
-
|
198
|
-
if(environment == 'default') #in Rails 4.1+ environments inherit from default, which does not have database so we will not include it
|
199
|
-
next
|
68
|
+
homedir = "lib/ferry_to_csv_#{environment}"
|
69
|
+
puts "connected to #{which_db_env} env db"
|
70
|
+
ActiveRecord::Base.establish_connection(adapter: db_type, database: info[which_db_env]['database'])
|
71
|
+
puts "connected to #{environment} env db"
|
72
|
+
FileUtils.mkdir homedir unless Dir[homedir].present?
|
73
|
+
puts "exporting tables to #{homedir}"
|
74
|
+
mysql_bar = ProgressBar.new("psql_to_csv", 100)
|
75
|
+
ActiveRecord::Base.connection.tables.each do |model|
|
76
|
+
columns = ActiveRecord::Base.connection.execute(
|
77
|
+
"SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS`
|
78
|
+
WHERE `TABLE_SCHEMA`= '#{info[environment]['database']}' AND `TABLE_NAME`='#{model}';")
|
79
|
+
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
80
|
+
col_names=[]
|
81
|
+
columns.each do |col|
|
82
|
+
col_names.append(col[0])
|
200
83
|
end
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
host: info[environment]['host'] || 'localhost',
|
207
|
-
username: info[environment]['username'],
|
208
|
-
password: info[environment]['password'],
|
209
|
-
database: info[environment]['database']
|
210
|
-
)
|
211
|
-
puts "connected to #{environment} env db"
|
212
|
-
FileUtils.mkdir homedir unless Dir[homedir].present?
|
213
|
-
puts "exporting tables to #{homedir}"
|
214
|
-
# psql_pbar = ProgressBar.new("psql_to_csv", 100)
|
215
|
-
|
216
|
-
ActiveRecord::Base.connection.tables.each do |model| #for each model in the db
|
217
|
-
columns = ActiveRecord::Base.connection.execute("SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`= '#{info[environment]['database']}' AND `TABLE_NAME`='#{model}';")
|
218
|
-
CSV.open("#{homedir}/#{model}.csv", "w") do |csv|
|
219
|
-
|
220
|
-
col_names=[]
|
221
|
-
columns.each do |col|
|
222
|
-
col_names.append(col[0]) #append the column names to an array, makes for good formatting
|
223
|
-
end
|
224
|
-
csv << col_names #first csv row is of column names
|
225
|
-
|
226
|
-
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
227
|
-
full_table.each do |row|
|
228
|
-
csv << row #not sure if this will hold, but no 'values_at' method exists
|
229
|
-
# psql_pbar.inc
|
230
|
-
end
|
231
|
-
end
|
84
|
+
csv << col_names
|
85
|
+
full_table = ActiveRecord::Base.connection.execute("SELECT * FROM #{model};")
|
86
|
+
full_table.each do |row|
|
87
|
+
csv << row
|
88
|
+
mysql_bar.inc
|
232
89
|
end
|
233
90
|
end
|
234
|
-
end
|
91
|
+
end
|
235
92
|
when "mongo"
|
236
93
|
puts "mongo is currently not supported"
|
237
94
|
else
|
@@ -247,13 +104,17 @@ module Ferry
|
|
247
104
|
puts "to_new_db_type: #{switch_to_db_type}"
|
248
105
|
|
249
106
|
# check for dependencies
|
250
|
-
# if dependencies exist - install them
|
251
|
-
|
107
|
+
# if dependencies exist - install them?
|
108
|
+
# how to go about installation ... just let the user fend for themselves?
|
109
|
+
# create new connection if necessary dependencies exist!
|
252
110
|
# transfer old db into new connection
|
253
|
-
#
|
111
|
+
# remove the old connection? what to do with it? hmm
|
112
|
+
# possibly keep it / have a method to remove it on user specification
|
113
|
+
# what would the user think
|
114
|
+
# "why would it be any other way?"
|
254
115
|
# update the config file
|
255
|
-
# profit
|
256
|
-
end
|
116
|
+
# profit from your new db!
|
257
117
|
|
118
|
+
end
|
258
119
|
end
|
259
120
|
end
|
data/lib/ferry/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ferry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Corletti
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '1.6'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: progressbar
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: rake
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,6 +142,7 @@ files:
|
|
128
142
|
- README.md
|
129
143
|
- Rakefile
|
130
144
|
- bin/ferry
|
145
|
+
- doc/ferry_readme_icon.png
|
131
146
|
- ferry.gemspec
|
132
147
|
- lib/ferry.rb
|
133
148
|
- lib/ferry/version.rb
|