taps 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 2
4
- :patch: 3
4
+ :patch: 4
@@ -41,7 +41,7 @@ class ClientSession
41
41
  end
42
42
 
43
43
  def open_session
44
- uri = server['sessions'].post('', :taps_version => Taps::VERSION)
44
+ uri = server['sessions'].post('', :taps_version => Taps.version)
45
45
  server[uri]
46
46
  end
47
47
 
@@ -50,7 +50,7 @@ class ClientSession
50
50
  end
51
51
 
52
52
  def close_session
53
- @session_resource.delete(:taps_version => Taps::VERSION) if @session_resource
53
+ @session_resource.delete(:taps_version => Taps.version) if @session_resource
54
54
  end
55
55
 
56
56
  def cmd_send
@@ -65,20 +65,20 @@ class ClientSession
65
65
  puts "Sending schema indexes to remote taps server #{remote_url} from local database #{database_url}"
66
66
 
67
67
  index_data = `#{File.dirname(__FILE__)}/../../bin/schema indexes #{database_url}`
68
- session_resource['indexes'].post(index_data, :taps_version => Taps::VERSION)
68
+ session_resource['indexes'].post(index_data, :taps_version => Taps.version)
69
69
  end
70
70
 
71
71
  def cmd_send_schema
72
72
  puts "Sending schema to remote taps server #{remote_url} from local database #{database_url}"
73
73
 
74
74
  schema_data = `#{File.dirname(__FILE__)}/../../bin/schema dump #{database_url}`
75
- session_resource['schema'].post(schema_data, :taps_version => Taps::VERSION)
75
+ session_resource['schema'].post(schema_data, :taps_version => Taps.version)
76
76
  end
77
77
 
78
78
  def cmd_send_reset_sequences
79
79
  puts "Resetting db sequences in remote taps server at #{remote_url}"
80
80
 
81
- session_resource["reset_sequences"].post('', :taps_version => Taps::VERSION)
81
+ session_resource["reset_sequences"].post('', :taps_version => Taps.version)
82
82
  end
83
83
 
84
84
  def cmd_send_data
@@ -103,7 +103,7 @@ class ClientSession
103
103
  chunksize = Taps::Utils.calculate_chunksize(chunksize) do
104
104
  begin
105
105
  session_resource["tables/#{table_name}"].post(gzip_data,
106
- :taps_version => Taps::VERSION,
106
+ :taps_version => Taps.version,
107
107
  :content_type => 'application/octet-stream',
108
108
  :taps_checksum => Taps::Utils.checksum(gzip_data).to_s)
109
109
  rescue RestClient::RequestFailed => e
@@ -168,7 +168,7 @@ class ClientSession
168
168
  def fetch_table_rows(table_name, chunksize, offset)
169
169
  response = nil
170
170
  chunksize = Taps::Utils.calculate_chunksize(chunksize) do
171
- response = session_resource["tables/#{table_name}/#{chunksize}?offset=#{offset}"].get(:taps_version => Taps::VERSION)
171
+ response = session_resource["tables/#{table_name}/#{chunksize}?offset=#{offset}"].get(:taps_version => Taps.version)
172
172
  end
173
173
  raise CorruptedData unless Taps::Utils.valid_data?(response.to_s, response.headers[:taps_checksum])
174
174
 
@@ -186,7 +186,7 @@ class ClientSession
186
186
  retries = 0
187
187
  max_retries = 1
188
188
  begin
189
- tables_with_counts = Marshal.load(session_resource['tables'].get(:taps_version => Taps::VERSION))
189
+ tables_with_counts = Marshal.load(session_resource['tables'].get(:taps_version => Taps.version))
190
190
  record_count = tables_with_counts.values.inject(0) { |a,c| a += c }
191
191
  rescue RestClient::Exception
192
192
  retries += 1
@@ -201,7 +201,7 @@ class ClientSession
201
201
  def cmd_receive_schema
202
202
  puts "Receiving schema from remote taps server #{remote_url} into local database #{database_url}"
203
203
 
204
- schema_data = session_resource['schema'].get(:taps_version => Taps::VERSION)
204
+ schema_data = session_resource['schema'].get(:taps_version => Taps.version)
205
205
  output = Taps::Utils.load_schema(database_url, schema_data)
206
206
  puts output if output
207
207
  end
@@ -209,7 +209,7 @@ class ClientSession
209
209
  def cmd_receive_indexes
210
210
  puts "Receiving schema indexes from remote taps server #{remote_url} into local database #{database_url}"
211
211
 
212
- index_data = session_resource['indexes'].get(:taps_version => Taps::VERSION)
212
+ index_data = session_resource['indexes'].get(:taps_version => Taps.version)
213
213
 
214
214
  puts Taps::Utils.load_indexes(database_url, index_data)
215
215
  end
@@ -226,7 +226,7 @@ class ClientSession
226
226
 
227
227
  def verify_server
228
228
  begin
229
- server['/'].get(:taps_version => Taps::VERSION)
229
+ server['/'].get(:taps_version => Taps.version)
230
230
  rescue RestClient::RequestFailed => e
231
231
  if e.http_code == 417
232
232
  puts "#{remote_url} is running a different version of taps."
data/lib/taps/config.rb CHANGED
@@ -2,23 +2,28 @@ require 'sequel'
2
2
  require 'sqlite3'
3
3
 
4
4
  module Taps
5
+ def self.version_yml
6
+ @@version_yml ||= YAML.load(File.read(File.dirname(__FILE__) + '/../../VERSION.yml'))
7
+ end
5
8
 
6
- VERSION = '0.2.3'
9
+ def self.version
10
+ "#{version_yml[:major]}.#{version_yml[:minor]}.#{version_yml[:patch]}"
11
+ end
7
12
 
8
- class Config
9
- class << self
10
- attr_accessor :taps_database_url
11
- attr_accessor :login, :password, :database_url, :remote_url
12
- attr_accessor :chunksize
13
+ class Config
14
+ class << self
15
+ attr_accessor :taps_database_url
16
+ attr_accessor :login, :password, :database_url, :remote_url
17
+ attr_accessor :chunksize
13
18
 
14
- def verify_database_url
15
- db = Sequel.connect(self.database_url)
16
- db.tables
17
- db.disconnect
18
- rescue Object => e
19
- puts "Failed to connect to database:\n #{e.class} -> #{e}"
20
- exit 1
19
+ def verify_database_url
20
+ db = Sequel.connect(self.database_url)
21
+ db.tables
22
+ db.disconnect
23
+ rescue Object => e
24
+ puts "Failed to connect to database:\n #{e.class} -> #{e}"
25
+ exit 1
26
+ end
21
27
  end
22
28
  end
23
29
  end
24
- end
data/lib/taps/schema.rb CHANGED
@@ -55,7 +55,6 @@ module Schema
55
55
  def load(database_url, schema)
56
56
  connection(database_url)
57
57
  eval(schema)
58
- ActiveRecord::Base.connection.execute("DELETE FROM schema_migrations") rescue nil
59
58
  end
60
59
 
61
60
  def load_indexes(database_url, indexes)
@@ -80,3 +79,19 @@ EORUBY
80
79
  end
81
80
  end
82
81
  end
82
+
83
+ module ActiveRecord
84
+ class SchemaDumper
85
+ private
86
+
87
+ def header(stream)
88
+ stream.puts "ActiveRecord::Schema.define do"
89
+ end
90
+
91
+ def tables(stream)
92
+ @connection.tables.sort.each do |tbl|
93
+ table(tbl, stream)
94
+ end
95
+ end
96
+ end
97
+ end
data/lib/taps/server.rb CHANGED
@@ -14,8 +14,8 @@ class Server < Sinatra::Default
14
14
  end
15
15
 
16
16
  before do
17
- unless request.env['HTTP_TAPS_VERSION'] == Taps::VERSION
18
- halt 417, "Taps version #{Taps::VERSION} is required for this server"
17
+ unless request.env['HTTP_TAPS_VERSION'] == Taps.version
18
+ halt 417, "Taps version #{Taps.version} is required for this server"
19
19
  end
20
20
  end
21
21
 
@@ -37,7 +37,7 @@ describe Taps::ClientSession do
37
37
  @client.stubs(:server).returns(mock('server'))
38
38
  @request = mock('request')
39
39
  @client.server.expects(:[]).with('/').returns(@request)
40
- @request.expects(:get).with({:taps_version => Taps::VERSION})
40
+ @request.expects(:get).with({:taps_version => Taps.version})
41
41
 
42
42
  lambda { @client.verify_server }.should.not.raise
43
43
  end
@@ -62,7 +62,7 @@ describe Taps::ClientSession do
62
62
  it "fetches tables info from taps server" do
63
63
  @marshal_data = Marshal.dump({ :mytable => 2 })
64
64
  @client.session_resource.stubs(:[]).with('tables').returns(mock('tables'))
65
- @client.session_resource['tables'].stubs(:get).with(:taps_version => Taps::VERSION).returns(@marshal_data)
65
+ @client.session_resource['tables'].stubs(:get).with(:taps_version => Taps.version).returns(@marshal_data)
66
66
  @client.fetch_tables_info.should == [ { :mytable => 2 }, 2 ]
67
67
  end
68
68
 
@@ -73,7 +73,7 @@ describe Taps::ClientSession do
73
73
 
74
74
  @response = mock('response')
75
75
  @client.session_resource.stubs(:[]).with('tables/mytable/1000?offset=0').returns(mock('table resource'))
76
- @client.session_resource['tables/mytable/1000?offset=0'].expects(:get).with(:taps_version => Taps::VERSION).returns(@response)
76
+ @client.session_resource['tables/mytable/1000?offset=0'].expects(:get).with(:taps_version => Taps.version).returns(@response)
77
77
  @response.stubs(:to_s).returns(@gzip_data)
78
78
  @response.stubs(:headers).returns({ :taps_checksum => Taps::Utils.checksum(@gzip_data) })
79
79
  @client.fetch_table_rows('mytable', 1000, 0).should == [ 1000, { :header => [:x, :y], :data => [[1, 2], [3, 4]] } ]
data/spec/server_spec.rb CHANGED
@@ -21,7 +21,7 @@ describe Taps::Server do
21
21
  end
22
22
 
23
23
  it "verifies the client taps version" do
24
- get('/', { }, { 'HTTP_AUTHORIZATION' => @auth_header, 'HTTP_TAPS_VERSION' => Taps::VERSION })
24
+ get('/', { }, { 'HTTP_AUTHORIZATION' => @auth_header, 'HTTP_TAPS_VERSION' => Taps.version })
25
25
  status.should == 200
26
26
  end
27
27
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Chimal, Jr.
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-02-13 00:00:00 -08:00
13
+ date: 2009-02-17 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -84,18 +84,18 @@ extra_rdoc_files: []
84
84
 
85
85
  files:
86
86
  - spec/base.rb
87
- - spec/client_session_spec.rb
88
87
  - spec/schema_spec.rb
89
- - spec/server_spec.rb
90
88
  - spec/utils_spec.rb
89
+ - spec/client_session_spec.rb
90
+ - spec/server_spec.rb
91
91
  - lib/taps/db_session.rb
92
- - lib/taps/schema.rb
93
92
  - lib/taps/progress_bar.rb
94
93
  - lib/taps/cli.rb
95
- - lib/taps/utils.rb
96
- - lib/taps/server.rb
97
- - lib/taps/client_session.rb
98
94
  - lib/taps/config.rb
95
+ - lib/taps/schema.rb
96
+ - lib/taps/client_session.rb
97
+ - lib/taps/server.rb
98
+ - lib/taps/utils.rb
99
99
  - README.rdoc
100
100
  - LICENSE
101
101
  - VERSION.yml