sq-dbsync 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,6 +51,10 @@ module Sq::Dbsync::Database
51
51
 
52
52
  "time without time zone" => "time",
53
53
  "timestamp without time zone" => "datetime",
54
+
55
+ # mysql has no single-column representation for timestamp with time zone
56
+ "timestamp with time zone" => "datetime",
57
+
54
58
  "boolean" => "char(1)"
55
59
  }.fetch(db_type, db_type)
56
60
  end
@@ -60,7 +64,7 @@ module Sq::Dbsync::Database
60
64
  file = sql_to_file(sql)
61
65
 
62
66
  cmd = "set -o pipefail; "
63
- cmd += "psql --no-align --tuples-only -F '\t'"
67
+ cmd += "env PGTZ=utc psql --no-align --tuples-only -F '\t'"
64
68
  cmd += " -U %s" % opts[:user] if opts[:user]
65
69
  cmd += " -h %s" % opts[:host] if opts[:host]
66
70
  cmd += " -p %i" % opts[:port] if opts[:port]
@@ -1,5 +1,5 @@
1
1
  module Sq
2
2
  module Dbsync
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
@@ -224,6 +224,37 @@ describe SQD::BatchLoadAction do
224
224
  let(:source) { test_source(:postgres) }
225
225
 
226
226
  it_should_behave_like 'a batch load'
227
- end
228
227
 
228
+ it 'loads records with time zones' do
229
+ table_plan = {
230
+ table_name: :test_table,
231
+ source_table_name: :test_table,
232
+ columns: [:id, :col1, :updated_at, :ts_with_tz],
233
+ source_db: source,
234
+ indexes: index
235
+ }
236
+
237
+ action = SQD::BatchLoadAction.new(target,
238
+ table_plan,
239
+ registry,
240
+ SQD::Loggers::Null.new,
241
+ ->{ @now })
242
+
243
+ create_pg_source_table_with(
244
+ id: 1,
245
+ col1: 'hello',
246
+ pii: 'don alias',
247
+ created_at: '2012-01-01 01:01:01',
248
+ updated_at: '2012-01-01 01:01:01',
249
+ ts_with_tz: '2012-01-01 01:01:01+02',
250
+ )
251
+
252
+ registry.ensure_storage_exists
253
+
254
+ action.call
255
+
256
+ target[:test_table].count.should == 1
257
+ target[:test_table].to_a.last[:ts_with_tz].should == Time.utc(2011, 12, 31, 23, 1, 1)
258
+ end
259
+ end
229
260
  end
@@ -24,6 +24,30 @@ def create_source_table_with(*rows)
24
24
  end
25
25
  end
26
26
 
27
+ def create_pg_source_table_with(*rows)
28
+ # Total hack to allow source db to be passed as optional first argument.
29
+ if rows[0].is_a?(Hash)
30
+ source_db = source
31
+ else
32
+ source_db = rows.shift
33
+ end
34
+ table_name = :test_table
35
+
36
+ source_db.create_table! table_name do
37
+ primary_key :id
38
+ String :col1
39
+ String :pii
40
+ DateTime :updated_at
41
+ DateTime :created_at
42
+ DateTime :imported_at
43
+ column :ts_with_tz, 'timestamp with time zone'
44
+ end
45
+
46
+ rows.each do |row|
47
+ source_db[table_name].insert(row)
48
+ end
49
+ end
50
+
27
51
  def setup_target_table(last_synced_at)
28
52
  target.create_table! :test_table do
29
53
  Integer :id
metadata CHANGED
@@ -1,105 +1,105 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sq-dbsync
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 3
10
+ version: 1.0.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Xavier Shay
9
14
  - Damon McCormick
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2013-04-15 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2013-04-16 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: rspec
17
- requirement: !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
22
- version: '2.0'
23
- type: :development
24
23
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
- requirements:
26
+ requirements:
28
27
  - - ~>
29
- - !ruby/object:Gem::Version
30
- version: '2.0'
31
- - !ruby/object:Gem::Dependency
32
- name: rake
33
- requirement: !ruby/object:Gem::Requirement
34
- none: false
35
- requirements:
36
- - - ! '>='
37
- - !ruby/object:Gem::Version
38
- version: '0'
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 0
33
+ version: "2.0"
39
34
  type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
40
38
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
- - !ruby/object:Gem::Dependency
48
- name: simplecov
49
- requirement: !ruby/object:Gem::Requirement
39
+ requirement: &id002 !ruby/object:Gem::Requirement
50
40
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
55
48
  type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: simplecov
56
52
  prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- - !ruby/object:Gem::Dependency
64
- name: cane
65
- requirement: !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
66
54
  none: false
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
71
62
  type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: cane
72
66
  prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
67
+ requirement: &id004 !ruby/object:Gem::Requirement
74
68
  none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
79
- - !ruby/object:Gem::Dependency
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
80
79
  name: sequel
81
- requirement: !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
84
- - - ! '>='
85
- - !ruby/object:Gem::Version
86
- version: '0'
87
- type: :runtime
88
80
  prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
81
+ requirement: &id005 !ruby/object:Gem::Requirement
90
82
  none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :runtime
91
+ version_requirements: *id005
95
92
  description: Column based, timestamp replication of MySQL and Postgres databases.
96
- email:
93
+ email:
97
94
  - xavier@squareup.com
98
95
  - damon@squaerup.com
99
96
  executables: []
97
+
100
98
  extensions: []
99
+
101
100
  extra_rdoc_files: []
102
- files:
101
+
102
+ files:
103
103
  - spec/acceptance/loading_spec.rb
104
104
  - spec/acceptance_helper.rb
105
105
  - spec/database_helper.rb
@@ -145,30 +145,38 @@ files:
145
145
  - sq-dbsync.gemspec
146
146
  homepage: http://github.com/square/sq-dbsync
147
147
  licenses: []
148
+
148
149
  post_install_message:
149
150
  rdoc_options: []
150
- require_paths:
151
+
152
+ require_paths:
151
153
  - lib
152
- required_ruby_version: !ruby/object:Gem::Requirement
154
+ required_ruby_version: !ruby/object:Gem::Requirement
153
155
  none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
- required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ hash: 3
160
+ segments:
161
+ - 0
162
+ version: "0"
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
164
  none: false
160
- requirements:
161
- - - ! '>='
162
- - !ruby/object:Gem::Version
163
- version: '0'
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ hash: 3
169
+ segments:
170
+ - 0
171
+ version: "0"
164
172
  requirements: []
173
+
165
174
  rubyforge_project:
166
175
  rubygems_version: 1.8.25
167
176
  signing_key:
168
177
  specification_version: 3
169
- summary: Column based, timestamp replication of MySQL and Postgres databases. Uses
170
- Ruby for the glue code but pushes the heavy lifting on to the database.
171
- test_files:
178
+ summary: Column based, timestamp replication of MySQL and Postgres databases. Uses Ruby for the glue code but pushes the heavy lifting on to the database.
179
+ test_files:
172
180
  - spec/acceptance/loading_spec.rb
173
181
  - spec/acceptance_helper.rb
174
182
  - spec/database_helper.rb
@@ -185,3 +193,4 @@ test_files:
185
193
  - spec/unit/pipeline_spec.rb
186
194
  - spec/unit/stream_logger_spec.rb
187
195
  - spec/unit_helper.rb
196
+ has_rdoc: false