ferry 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -3
- data/Rakefile +2 -0
- data/bin/ferry +8 -2
- data/dbfile.sqlite3 +0 -0
- data/ferry.gemspec +7 -0
- data/lib/ferry.rb +102 -35
- data/lib/ferry/logger.rb +9 -9
- data/lib/ferry/version.rb +1 -1
- data/lib/tasks/dump_task.rake +18 -0
- data/spec/ferry.sqlite3 +0 -0
- data/spec/ferry_spec.rb +10 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/data.rb +11 -0
- data/spec/support/models.rb +3 -0
- data/spec/support/schema.rb +18 -0
- metadata +42 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bd2de60bc2ce57fdeabce474e282951ab9ff0c0
|
4
|
+
data.tar.gz: 05daaabdc21e93dc5913e0b06e9f44f27e8d8c20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6adc5f4e801b15379a537d1cc1657ec9a1597b084a3a41ba79f4bb8619bbb00d23f75b8cd49d07bc95a37051106f82793e19a181365900e5643be8a17b10b1bb
|
7
|
+
data.tar.gz: dfe0796e1442fd45ad52dba431c77e76b8b5f78cd53eb291d6a282bcb6f08092a3207d11cd6a8edff84122be4dc14cfa4f095c6207c762bb7b0a39ff3e39a5fd
|
data/README.md
CHANGED
@@ -39,9 +39,6 @@ Usage pending. See examples / submit PR's for your ideas.
|
|
39
39
|
Use Case Ideas
|
40
40
|
|
41
41
|
Note: Demo app can initially function with RoR and Postgres.
|
42
|
-
Instantiate the command line tool for ferry ...
|
43
|
-
- Init the project with ferry rake namespace (ferry.rake)
|
44
|
-
- Run the tasks containing the methods we write in ferry
|
45
42
|
|
46
43
|
Manipulation Use Cases
|
47
44
|
- CRUD for Columns
|
data/Rakefile
CHANGED
data/bin/ferry
CHANGED
@@ -2,5 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'ferry'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
export = Ferry::Export.new
|
6
|
+
|
7
|
+
#ARGV[0] should be the ferry function they want to call
|
8
|
+
#subsequent params are the options to that function
|
9
|
+
|
10
|
+
if(ARGV[0] == "to_csv" )
|
11
|
+
export.to_csv
|
12
|
+
end
|
data/dbfile.sqlite3
ADDED
File without changes
|
data/ferry.gemspec
CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
# spec.executables = ["ferry"]
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
@@ -24,4 +25,10 @@ Gem::Specification.new do |spec|
|
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
spec.add_development_dependency "minitest"
|
26
27
|
spec.add_development_dependency "rspec"
|
28
|
+
# spec.add_development_dependency "yaml"
|
29
|
+
#to test db access
|
30
|
+
spec.add_development_dependency "pg"
|
31
|
+
spec.add_development_dependency "sqlite3"
|
32
|
+
|
33
|
+
#spec.add_dependency "activerecord" #whats difference between dev and not dev?
|
27
34
|
end
|
data/lib/ferry.rb
CHANGED
@@ -1,48 +1,115 @@
|
|
1
1
|
require "ferry/version"
|
2
2
|
require "ferry/engine"
|
3
3
|
require "ferry/logger"
|
4
|
+
require "csv"
|
5
|
+
require 'active_record'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'yaml'
|
8
|
+
require 'rails'
|
4
9
|
|
5
10
|
module Ferry
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
11
|
+
|
12
|
+
|
13
|
+
class Export
|
14
|
+
def to_csv()
|
15
|
+
|
16
|
+
# ActiveRecord::Base.connection
|
17
|
+
#ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db/development.sqlite3') #need to automatically get db name
|
18
|
+
#puts ActiveRecord::Base.configurations[Rails.env]['adapter']
|
19
|
+
|
20
|
+
info = YAML::load(IO.read("config/database.yml")) #this holds all the db config information. pretty much a rosetta stone for dbs
|
21
|
+
db_type = info["production"]["adapter"] #this tells us the db rails is using
|
22
|
+
|
23
|
+
|
24
|
+
# puts Rails.configuration#.database_configuration[Rails.env]
|
25
|
+
# puts ActiveRecord::Base.configurations[Rails.env]
|
26
|
+
|
27
|
+
# type = db_type.downcase
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
case db_type
|
32
|
+
when "sqlite3"
|
33
|
+
puts "its sqlite3"
|
34
|
+
|
35
|
+
|
36
|
+
info.keys.each do |environment|
|
37
|
+
|
38
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: info[environment]['database']) #connect to sqlite3 file
|
39
|
+
|
40
|
+
unless(Dir.exists?('db/csv')) #creating a 'csv' folder in the 'db' folder
|
41
|
+
Dir.mkdir('db/csv')
|
42
|
+
puts 'db/csv created'
|
43
|
+
end
|
44
|
+
|
45
|
+
unless(Dir.exists?('db/csv/'+environment)) #creating folders for each file (dev, test, prod, etc)
|
46
|
+
Dir.mkdir('db/csv/'+environment)
|
47
|
+
puts 'db/csv/'+environment+' created'
|
48
|
+
end
|
49
|
+
|
50
|
+
ActiveRecord::Base.connection.tables.each do |model| #for each model in the db
|
51
|
+
everything = ActiveRecord::Base.connection.execute('SELECT * FROM '+model+';') #get all the records
|
52
|
+
|
53
|
+
if everything[0].nil? #do not create a csv for an empty table
|
54
|
+
next
|
55
|
+
end
|
56
|
+
|
57
|
+
CSV.open("db/csv/"+environment+"/"+model+".csv", "w") do |csv| #create a csv for each table, titled 'model.csv'
|
58
|
+
|
59
|
+
size = everything[0].length / 2
|
60
|
+
keys = everything[0].keys.first(size)
|
61
|
+
|
62
|
+
csv << keys #first row contains column names
|
63
|
+
|
64
|
+
everything.each do |row|
|
65
|
+
csv << row.values_at(*keys) #subsequent rows hold record values
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
29
70
|
end
|
30
|
-
|
31
|
-
|
71
|
+
|
72
|
+
|
73
|
+
when "mysql"
|
74
|
+
puts "its mysql"
|
75
|
+
when "postgres"
|
76
|
+
puts "its postgres"
|
77
|
+
else
|
78
|
+
puts "unknown db type"
|
32
79
|
end
|
33
|
-
|
34
|
-
|
80
|
+
|
81
|
+
|
82
|
+
puts Time.now()
|
35
83
|
|
36
|
-
class Exporter
|
37
|
-
def speak
|
38
|
-
puts "exporting!"
|
39
84
|
end
|
40
85
|
end
|
41
86
|
|
42
|
-
class
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
87
|
+
# class ActiveRecord::Relation
|
88
|
+
# def migrate(options, &block)
|
89
|
+
# options[:max_workers] ||= 4
|
90
|
+
# options[:batch_size] ||= 10_000
|
91
|
+
|
92
|
+
# log = Logger.new()
|
47
93
|
|
94
|
+
# active_workers = []
|
95
|
+
# collection = self
|
96
|
+
# collection.find_in_batches(batch_size: options[:batch_size]) do |batch|
|
97
|
+
# if active_workers.length >= options[:max_workers]
|
98
|
+
# log.write "active_workers oversized at capacity of #{active_workers.length}/#{options[:max_workers]}"
|
99
|
+
# finished_process = Process.wait
|
100
|
+
# log.write "finished_process: #{finished_process}"
|
101
|
+
# active_workers.delete finished_process
|
102
|
+
# log.write "active_workers capacity now at: #{active_workers.length}/#{options[:max_workers]}"
|
103
|
+
# else
|
104
|
+
# active_workers << fork do
|
105
|
+
# ActiveRecord::Base.connection.reconnect!
|
106
|
+
# log.write "kicking off engine on batch(#{batch.first}-#{batch.last})"
|
107
|
+
# engine = Engine.new()
|
108
|
+
# engine.run({log: log, batch: batch}, &block)
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
# ActiveRecord::Base.connection.reconnect!
|
112
|
+
# end
|
113
|
+
# end
|
114
|
+
# end
|
48
115
|
end
|
data/lib/ferry/logger.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
class Logger
|
2
|
-
def initialize(options={})
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
2
|
+
# def initialize(options={})
|
3
|
+
# @homedir = options[:homedir] ||= "log"
|
4
|
+
# FileUtils.mkdir @homedir unless Dir[@homedir].present?
|
5
|
+
# FileUtils.touch "#{@homedir}/ferry.log"
|
6
|
+
# end
|
7
7
|
|
8
|
-
def write(msg)
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
# def write(msg)
|
9
|
+
# log = File.open("#{@homedir}/ferry.log", 'w')
|
10
|
+
# log.puts msg
|
11
|
+
# end
|
12
12
|
end
|
data/lib/ferry/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :db do
|
2
|
+
desc "Dump schema and data to db/schema.rb and db/data.yml"
|
3
|
+
task(:dump => [ "db:schema:dump", "db:data:dump" ])
|
4
|
+
|
5
|
+
namespace :data do
|
6
|
+
def db_dump_data_file (extension = "yml")
|
7
|
+
"#{dump_dir}/data.#{extension}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Dump contents of database to db/data.extension (defaults to yaml)"
|
11
|
+
task :dump => :environment do
|
12
|
+
# format_class = ENV['class'] || "YamlDb::Helper"
|
13
|
+
# helper = format_class.constantize
|
14
|
+
# SerializationHelper::Base.new(helper).dump db_dump_data_file helper.extension
|
15
|
+
puts "yolo"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/ferry.sqlite3
ADDED
Binary file
|
data/spec/ferry_spec.rb
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -14,6 +14,17 @@
|
|
14
14
|
# users commonly want.
|
15
15
|
#
|
16
16
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
require 'ferry'
|
18
|
+
|
19
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3",
|
20
|
+
:database => File.dirname(__FILE__) + "/ferry.sqlite3")
|
21
|
+
|
22
|
+
load File.dirname(__FILE__) + '/support/schema.rb'
|
23
|
+
load File.dirname(__FILE__) + '/support/models.rb'
|
24
|
+
load File.dirname(__FILE__) + '/support/data.rb'
|
25
|
+
|
26
|
+
|
27
|
+
|
17
28
|
RSpec.configure do |config|
|
18
29
|
# The settings below are suggested to provide a good initial experience
|
19
30
|
# with RSpec, but feel free to customize to your heart's content.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Design.create(
|
2
|
+
:design_id => 1,
|
3
|
+
:product_id => 1,
|
4
|
+
:account_id => 1,
|
5
|
+
:account_file => "Reunion 2014",
|
6
|
+
:save_method => "WWW",
|
7
|
+
:total_units => 25,
|
8
|
+
:has_upload => true,
|
9
|
+
:created_at => DateTime.now,
|
10
|
+
:updated_at => DateTime.now,
|
11
|
+
:postal_code => 96822)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
self.verbose = false
|
3
|
+
|
4
|
+
create_table :designs do |t|
|
5
|
+
t.integer :design_id
|
6
|
+
t.integer :product_id
|
7
|
+
t.integer :account_id
|
8
|
+
t.string :account_file
|
9
|
+
t.string :save_method
|
10
|
+
t.integer :total_units
|
11
|
+
t.boolean :has_upload
|
12
|
+
t.date :created_at
|
13
|
+
t.date :updated_at
|
14
|
+
t.integer :postal_code
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
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.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Corletti
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-09-
|
13
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -96,6 +96,34 @@ dependencies:
|
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: pg
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: sqlite3
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
type: :development
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
99
127
|
description: Ferry is a data migration and data manipulation tool that seeks to simplify
|
100
128
|
the increasingly prevalent big data problems that tech companies face
|
101
129
|
email:
|
@@ -114,12 +142,19 @@ files:
|
|
114
142
|
- README.md
|
115
143
|
- Rakefile
|
116
144
|
- bin/ferry
|
145
|
+
- dbfile.sqlite3
|
117
146
|
- ferry.gemspec
|
118
147
|
- lib/ferry.rb
|
119
148
|
- lib/ferry/engine.rb
|
120
149
|
- lib/ferry/logger.rb
|
121
150
|
- lib/ferry/version.rb
|
151
|
+
- lib/tasks/dump_task.rake
|
152
|
+
- spec/ferry.sqlite3
|
153
|
+
- spec/ferry_spec.rb
|
122
154
|
- spec/spec_helper.rb
|
155
|
+
- spec/support/data.rb
|
156
|
+
- spec/support/models.rb
|
157
|
+
- spec/support/schema.rb
|
123
158
|
homepage: https://github.com/cmu-is-projects/
|
124
159
|
licenses:
|
125
160
|
- MIT
|
@@ -145,4 +180,9 @@ signing_key:
|
|
145
180
|
specification_version: 4
|
146
181
|
summary: Ferry is a data migration and data manipulation tool
|
147
182
|
test_files:
|
183
|
+
- spec/ferry.sqlite3
|
184
|
+
- spec/ferry_spec.rb
|
148
185
|
- spec/spec_helper.rb
|
186
|
+
- spec/support/data.rb
|
187
|
+
- spec/support/models.rb
|
188
|
+
- spec/support/schema.rb
|