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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23d6e9a00c4fe515bd810869dffb3667e7080f5c
4
- data.tar.gz: cd77f263a4774959d6c6fb0253b4992ac54ecd21
3
+ metadata.gz: 8bd2de60bc2ce57fdeabce474e282951ab9ff0c0
4
+ data.tar.gz: 05daaabdc21e93dc5913e0b06e9f44f27e8d8c20
5
5
  SHA512:
6
- metadata.gz: 24aab9f214d73e21188541171a560b772914ed141f026e5b7f58dcf6fb0d41ef66d171fdc6e9e6a51c13a2df353b3141d6bcae40b41310f79b5d9ea62b5da265
7
- data.tar.gz: 2a918e7c071296411a42c99dae4dc56ffb876b527b5b1a8d5c3f765959b2a5c68e5889badd34a992d2ddf5e33f6f224b0bf7d068765a4fcb84798ee445ba20f4
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
@@ -1,2 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+
data/bin/ferry CHANGED
@@ -2,5 +2,11 @@
2
2
 
3
3
  require 'ferry'
4
4
 
5
- var = Ferry::Exporter.new
6
- var.speak
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
- class ActiveRecord::Relation
8
- def migrate(options, &block)
9
- options[:max_workers] ||= 4
10
- options[:batch_size] ||= 10_000
11
-
12
- log = Logger.new()
13
-
14
- active_workers = []
15
- collection = self
16
- collection.find_in_batches(batch_size: options[:batch_size]) do |batch|
17
- if active_workers.length >= options[:max_workers]
18
- log.write "active_workers oversized at capacity of #{active_workers.length}/#{options[:max_workers]}"
19
- finished_process = Process.wait
20
- log.write "finished_process: #{finished_process}"
21
- active_workers.delete finished_process
22
- log.write "active_workers capacity now at: #{active_workers.length}/#{options[:max_workers]}"
23
- else
24
- active_workers << fork do
25
- ActiveRecord::Base.connection.reconnect!
26
- log.write "kicking off engine on batch(#{batch.first}-#{batch.last})"
27
- engine = Engine.new()
28
- engine.run({log: log, batch: batch}, &block)
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
- end
31
- ActiveRecord::Base.connection.reconnect!
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
- end
34
- end
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 Importer
43
- def speak
44
- puts "importing!"
45
- end
46
- end
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
- @homedir = options[:homedir] ||= "log"
4
- FileUtils.mkdir @homedir unless Dir[@homedir].present?
5
- FileUtils.touch "#{@homedir}/ferry.log"
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
- log = File.open("#{@homedir}/ferry.log", 'w')
10
- log.puts msg
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
@@ -1,3 +1,3 @@
1
1
  module Ferry
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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
Binary file
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe "connect" do
4
+ context "connect" do
5
+ it "id" do
6
+ Post.by_year.map(&:text).should include("First post!")
7
+ end
8
+ end
9
+
10
+ end
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,3 @@
1
+ class Design < ActiveRecord::Base
2
+
3
+ end
@@ -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.2
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-14 00:00:00.000000000 Z
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