flydata 0.2.12 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 834f55f013a932c4bbd53408f020fe886ab2acf5
4
- data.tar.gz: 702f346a6a072648956489fab6bf75776adb3351
3
+ metadata.gz: 7d20120a45eeb0e80acb2738e924ff664454d8bf
4
+ data.tar.gz: 96aadd0c65100102b2e659d063fbc1d9a391f56d
5
5
  SHA512:
6
- metadata.gz: 3cafe705f68a2b86801e0af7bd93f5b450adaceb1f183876b44d01c3b921c437c78376b093b2e516e80446bc84fb18f18dfeeacc88ee1b4b6ff2922e0020fd06
7
- data.tar.gz: 9aa3192f6524da454763d808941fdb847806166cfd369712835d37c36d33f2d5f307ac98fe31f44cea46a212c90b12b4c2c78594ebb691623369ab6705947cf5
6
+ metadata.gz: be0a985f146c83e734435c5a84d38d32b0daf8e0c32a59f8774c6b1570d360cfcab3b42fc327cd01b8a54ba4229718b6e7049cc9c635f11c1bf333d163d02e79
7
+ data.tar.gz: 09f3b5918fbe79bbdf86d0570f73524a646d7f507a89c3fe0ae4df9d846e3724577b52da4ee73dcd0f10172128664f2c9121b9d0f5d513ba38f5a5f84f4229d9
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.12
1
+ 0.2.13
data/flydata.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: flydata 0.2.12 ruby lib
5
+ # stub: flydata 0.2.13 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "flydata"
9
- s.version = "0.2.12"
9
+ s.version = "0.2.13"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Koichi Fujikawa", "Masashi Miyazaki", "Matthew Luu", "Mak Inada", "Sriram NS"]
14
- s.date = "2014-11-03"
14
+ s.date = "2014-11-08"
15
15
  s.description = "FlyData Agent"
16
16
  s.email = "sysadmin@flydata.com"
17
17
  s.executables = ["fdmysqldump", "flydata", "serverinfo"]
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "flydata.gemspec",
34
34
  "lib/fly_data_model.rb",
35
35
  "lib/flydata.rb",
36
+ "lib/flydata/agent_errors.rb",
36
37
  "lib/flydata/api/base.rb",
37
38
  "lib/flydata/api/data_entry.rb",
38
39
  "lib/flydata/api/data_port.rb",
@@ -58,7 +59,6 @@ Gem::Specification.new do |s|
58
59
  "lib/flydata/compatibility_check.rb",
59
60
  "lib/flydata/credentials.rb",
60
61
  "lib/flydata/cron.rb",
61
- "lib/flydata/errors.rb",
62
62
  "lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb",
63
63
  "lib/flydata/fluent-plugins/mysql/alter_table_query_handler.rb",
64
64
  "lib/flydata/fluent-plugins/mysql/binlog_position.rb",
File without changes
@@ -20,6 +20,11 @@ module Flydata
20
20
  return
21
21
  end
22
22
 
23
+ # Ends orphan_proceses if there is any
24
+ orphan_processes.each do |pid|
25
+ Process.kill(:TERM, pid)
26
+ end
27
+
23
28
  wait_until_server_ready(options)
24
29
 
25
30
  dp = flydata.data_port.get
@@ -29,8 +34,8 @@ module Flydata
29
34
  say('Starting sender process.') unless options[:quiet]
30
35
  Dir.chdir(FLYDATA_HOME){
31
36
  Kernel.system("bash #{File.dirname(__FILE__)}/../../../bin/serverinfo", :out => ["#{FLYDATA_HOME}/flydata.log",'a'], :err => ["#{FLYDATA_HOME}/flydata.log",'a'])
32
- daemon_option = opts.no_daemon? ? "" : "-d #{FLYDATA_HOME}/flydata.pid"
33
- Kernel.system("fluentd #{daemon_option} -l #{FLYDATA_HOME}/flydata.log -c #{FLYDATA_HOME}/flydata.conf -p #{File.dirname(__FILE__)}/../fluent-plugins")
37
+ daemon_opt = opts.no_daemon? ? "" : daemon_option
38
+ Kernel.system("ruby `which fluentd` #{daemon_opt} -l #{FLYDATA_HOME}/flydata.log -c #{FLYDATA_HOME}/flydata.conf -p #{File.dirname(__FILE__)}/../fluent-plugins")
34
39
  }
35
40
  Kernel.sleep 5
36
41
 
@@ -51,7 +56,7 @@ EOF
51
56
  end
52
57
 
53
58
  say('Stopping sender process.') unless options[:quiet]
54
- if Kernel.system("kill `cat #{FLYDATA_HOME}/flydata.pid`") and wait_until_client_stop(options)
59
+ if Kernel.system("kill `cat #{pid_file}`") and wait_until_client_stop(options)
55
60
  say('Done.') unless options[:quiet]
56
61
  return true
57
62
  end
@@ -65,7 +70,7 @@ EOF
65
70
  end
66
71
 
67
72
  say('Stopping input plugins and flushing the client buffer.') unless options[:quiet]
68
- Kernel.system("kill -USR1 `cat #{FLYDATA_HOME}/flydata.pid`")
73
+ Kernel.system("kill -USR1 `cat #{pid_file}`")
69
74
 
70
75
  retry_count = 12
71
76
  1.upto(retry_count) do |i|
@@ -79,7 +84,7 @@ EOF
79
84
  def restart(options = {})
80
85
  if process_exist?
81
86
  say('Restarting sender process.') unless options[:quiet]
82
- if Kernel.system("kill -HUP `cat #{FLYDATA_HOME}/flydata.pid`")
87
+ if Kernel.system("kill -HUP `cat #{pid_file}`")
83
88
  say('Done.') unless options[:quiet]
84
89
  return true
85
90
  else
@@ -99,7 +104,7 @@ EOF
99
104
  end
100
105
  def process_exist?
101
106
  # Returns true if the process is running
102
- `[ -f #{FLYDATA_HOME}/flydata.pid ] && pgrep -P \`cat #{FLYDATA_HOME}/flydata.pid\``.to_i > 0
107
+ `[ -f #{pid_file} ] && pgrep -P \`cat #{pid_file}\``.to_i > 0
103
108
  end
104
109
  def kill_all(optiosn = {})
105
110
  if Kernel.system("ps ax | grep 'flydata' | grep -v grep | awk '{print \"kill \" $1}' | sh")
@@ -111,6 +116,19 @@ EOF
111
116
  end
112
117
 
113
118
  private
119
+ # Return a list of fluentd parent processes run by the same user for the
120
+ # same flydata.pid file but not the process managed by the file itself.
121
+ CMD = %Q{ps -u `whoami` -o ppid,pid,args | grep '^ *1 ' | grep '\\%s' | egrep -v "\\b`cat %s`\\b"}
122
+ def orphan_processes
123
+ cmd = CMD % [ daemon_option, pid_file ]
124
+ result = `#{cmd}`
125
+ orphan_pids = []
126
+ result.each_line do |line|
127
+ orphan_pids << line.split[1].to_i
128
+ end
129
+ orphan_pids
130
+ end
131
+
114
132
  def wait_until_server_ready(options = {})
115
133
  retry_count = 10
116
134
  1.upto(retry_count) do |i|
@@ -181,6 +199,12 @@ EOF
181
199
  say("Checking the client buffer #{client_buffer}") unless options[:quiet]
182
200
  Dir.glob("#{client_buffer}/*").empty?
183
201
  end
202
+ def pid_file
203
+ "#{FLYDATA_HOME}/flydata.pid"
204
+ end
205
+ def daemon_option
206
+ "-d #{pid_file}"
207
+ end
184
208
  end
185
209
  end
186
210
  end
@@ -3,7 +3,7 @@ require 'msgpack'
3
3
  require 'open3'
4
4
  require 'mysql2'
5
5
  require 'flydata/sync_file_manager'
6
- require 'flydata/errors'
6
+ require 'flydata/agent_errors'
7
7
  require 'flydata/compatibility_check'
8
8
  require 'flydata/table_def'
9
9
  require 'flydata/output/forwarder'
@@ -39,22 +39,26 @@ module Flydata
39
39
  SSL_PORT=45327
40
40
 
41
41
  def check_outgoing_ports
42
- unless can_connect_to_port?(TCP_PORT) and
43
- can_connect_to_port?(SSL_PORT)
44
- raise AgentCompatibilityError,
45
- "Cannot connect to outisde ports. Please check to make sure you have these outgoing ports open: #{TCP_PORT},#{SSL_PORT}"
46
- end
47
- end
42
+ ports = [TCP_PORT]
43
+ ports << SSL_PORT unless ENV['FLYDATA_ENV_KEY'] == 'development'
48
44
 
49
- private
50
- def can_connect_to_port?(port)
51
45
  url = @dp["servers"].first
52
- begin
53
- e = TCPSocket.new(url, port)
54
- e.close
55
- return true
56
- rescue Errno::ETIMEDOUT => e
57
- return false
46
+ errors = {}
47
+ ports.each do |port|
48
+ begin
49
+ e = TCPSocket.new(url, port)
50
+ e.close
51
+ rescue => e
52
+ errors[port] = e
53
+ end
54
+ end
55
+
56
+ unless errors.empty?
57
+ message = "Cannot connect to outisde ports. Please check to make sure you have these outgoing ports open."
58
+ errors.each do |port, e|
59
+ message += " Port #{port}, Error #{e.class.name}: #{e.to_s}"
60
+ end
61
+ raise AgentCompatibilityError, message
58
62
  end
59
63
  end
60
64
  end
@@ -100,7 +100,7 @@ grammar MysqlAlterTable
100
100
  action_hash
101
101
  end
102
102
  }
103
- / add_key (sp col_key)? sp col_name_def ( sp pos_def )? {
103
+ / add_key opt_column sp col_name_def opt_place {
104
104
  def action
105
105
  ret = { action: :add_column }
106
106
  ret.merge!(col_name_def.column_def)
@@ -110,7 +110,7 @@ grammar MysqlAlterTable
110
110
  ret
111
111
  end
112
112
  }
113
- / add_key (sp col_key)? nsp '(' nsp col_name_def ( comma col_name_def )* nsp ')' {
113
+ / add_key opt_column nsp '(' nsp col_name_def ( comma col_name_def )* nsp ')' {
114
114
  def action
115
115
  ret = [col_name_def.column_def]
116
116
  ret += 0.upto(elements[6].elements.count - 1).collect do |i|
@@ -119,6 +119,30 @@ grammar MysqlAlterTable
119
119
  ret.collect{|v| {action: :add_column}.merge(v) }
120
120
  end
121
121
  }
122
+ # Re-using col_name and col_name_def for now
123
+ # TODO Refactor later to match sql_yacc.yy more closely
124
+ / change_sym opt_column sp col_name sp col_name_def opt_place {
125
+ def action
126
+ ret = { action: :change_column }
127
+ ret[:old_column] = col_name.value
128
+ ret.merge!(col_name_def.column_def)
129
+ if elements[6].nonterminal?
130
+ ret.merge!(elements[6].elements[1].pos_def_option)
131
+ end
132
+ ret
133
+ end
134
+ }
135
+ / modify_sym opt_column sp col_name_def opt_place {
136
+ def action
137
+ ret = { action: :change_column }
138
+ ret.merge!(col_name_def.column_def)
139
+ ret[:old_column] = ret[:column]
140
+ if elements[4].nonterminal?
141
+ ret.merge!(elements[4].elements[1].pos_def_option)
142
+ end
143
+ ret
144
+ end
145
+ }
122
146
  / drop_key sp primary_sym sp key_sym {
123
147
  def action
124
148
  { action: :drop_primary_key }
@@ -138,7 +162,7 @@ grammar MysqlAlterTable
138
162
  }
139
163
  end
140
164
  }
141
- / drop_key (sp col_key)? sp col_name {
165
+ / drop_key opt_column sp col_name {
142
166
  def action
143
167
  { action: :drop_column,
144
168
  column: col_name.value, }
@@ -578,6 +602,10 @@ grammar MysqlAlterTable
578
602
  }
579
603
  end
580
604
 
605
+ rule opt_place
606
+ ( sp pos_def )?
607
+ end
608
+
581
609
  rule pos_def
582
610
  'first'i {
583
611
  def pos_def_option
@@ -929,7 +957,6 @@ grammar MysqlAlterTable
929
957
  rule table_key 'table'i end
930
958
  rule add_key 'add'i end
931
959
  rule drop_key 'drop'i end
932
- rule col_key 'column'i end
933
960
 
934
961
 
935
962
  ######## Common rules
@@ -967,6 +994,7 @@ grammar MysqlAlterTable
967
994
 
968
995
  rule value
969
996
  quoted_value { def raw_value; text_raw_value; end }
997
+ / double_quoted_value { def raw_value; text_raw_value; end }
970
998
  / ident_sym { def raw_value; text_value; end }
971
999
  end
972
1000
 
@@ -974,10 +1002,22 @@ grammar MysqlAlterTable
974
1002
  "'" text "'" { def text_raw_value; text.text_value; end }
975
1003
  end
976
1004
 
1005
+ rule double_quoted_value
1006
+ '"' text_within_double_quotes '"' {
1007
+ def text_raw_value
1008
+ text_within_double_quotes.text_value
1009
+ end
1010
+ }
1011
+ end
1012
+
977
1013
  rule text
978
1014
  ("\\\\" / "\\'" / !"'" . )*
979
1015
  end
980
1016
 
1017
+ rule text_within_double_quotes
1018
+ ('\\\\' / '\\"' / !'"' . )*
1019
+ end
1020
+
981
1021
  rule ident
982
1022
  ident_sys / keyword
983
1023
  end
@@ -1298,4 +1338,23 @@ grammar MysqlAlterTable
1298
1338
  / extended_sym
1299
1339
  / use_frm_sym
1300
1340
  end
1341
+
1342
+ ## Change column related rules
1343
+
1344
+ rule change_sym
1345
+ 'change'i ![A-Za-z0-9_]
1346
+ end
1347
+
1348
+ rule modify_sym
1349
+ 'modify'i ![A-Za-z0-9_]
1350
+ end
1351
+
1352
+ rule column_sym
1353
+ 'column'i ![A-Za-z0-9_]
1354
+ end
1355
+
1356
+ rule opt_column
1357
+ ( sp column_sym )?
1358
+ end
1359
+
1301
1360
  end
@@ -26,7 +26,7 @@ module Flydata
26
26
  expect(Kernel).to receive(:system).with( Regexp.new(
27
27
  "bash .+/../../../bin/serverinfo"), :out => [Regexp.new(".+/flydata.log"),'a'], :err => [Regexp.new(".+/flydata.log"),'a'])
28
28
  expect(Kernel).to receive(:system).with( Regexp.new(
29
- "fluentd -d .+/flydata.pid -l .+/flydata.log -c .+/flydata.conf -p .+/\.\./fluent-plugins"))
29
+ "ruby `which fluentd` -d .+/flydata.pid -l .+/flydata.log -c .+/flydata.conf -p .+/\.\./fluent-plugins"))
30
30
  subject.start(false)
31
31
  end
32
32
  end
@@ -36,7 +36,7 @@ module Flydata
36
36
  expect(Kernel).to receive(:system).with( Regexp.new(
37
37
  "bash .+/../../../bin/serverinfo"), :out => [Regexp.new(".+/flydata.log"),'a'], :err => [Regexp.new(".+/flydata.log"),'a'])
38
38
  expect(Kernel).to receive(:system).with(Regexp.new(
39
- "fluentd -l .+/flydata.log -c .+/flydata.conf -p .+/\.\./fluent-plugins"))
39
+ "ruby `which fluentd` -l .+/flydata.log -c .+/flydata.conf -p .+/\.\./fluent-plugins"))
40
40
  subject.start(false)
41
41
  end
42
42
  end
@@ -46,7 +46,7 @@ module Flydata
46
46
  expect(Kernel).to receive(:system).with( Regexp.new(
47
47
  "bash .+/../../../bin/serverinfo"), :out => [Regexp.new(".+/flydata.log"),'a'], :err => [Regexp.new(".+/flydata.log"),'a'])
48
48
  expect(Kernel).to receive(:system).with(Regexp.new(
49
- "fluentd -l .+/flydata.log -c .+/flydata.conf -p .+/\.\./fluent-plugins"))
49
+ "ruby `which fluentd` -l .+/flydata.log -c .+/flydata.conf -p .+/\.\./fluent-plugins"))
50
50
  subject.start(false)
51
51
  end
52
52
  end
@@ -7,17 +7,25 @@ module Flydata
7
7
  end
8
8
 
9
9
  describe "#check" do
10
- subject { AgentCompatibilityCheck.new(:default_data_port) }
10
+ subject { AgentCompatibilityCheck.new("servers" => ['localhost']) }
11
11
  context "runs all check methods" do
12
- it "successfully checks open ports" do
13
- expect(subject).to receive(:can_connect_to_port?).with(Flydata::AgentCompatibilityCheck::TCP_PORT).and_return true
14
- expect(subject).to receive(:can_connect_to_port?).with(Flydata::AgentCompatibilityCheck::SSL_PORT).and_return true
15
- subject.check
12
+ context "when all ports are accessible" do
13
+ let(:sock) { double('sock') }
14
+ before do
15
+ allow(TCPSocket).to receive(:new).and_return(sock)
16
+ allow(sock).to receive(:close)
17
+ end
18
+ it "does nothing" do
19
+ subject.check
20
+ end
16
21
  end
17
- it "successfully catches errors on open ports" do
18
- expect(subject).to receive(:can_connect_to_port?).with(Flydata::AgentCompatibilityCheck::TCP_PORT).and_return true
19
- expect(subject).to receive(:can_connect_to_port?).with(Flydata::AgentCompatibilityCheck::SSL_PORT).and_return false
20
- expect{subject.check_outgoing_ports}.to raise_error(Flydata::AgentCompatibilityCheck::AgentCompatibilityError, /ports/)
22
+ context "when a port access fails" do
23
+ before do
24
+ allow(TCPSocket).to receive(:new).and_raise(Errno::ETIMEDOUT)
25
+ end
26
+ it do
27
+ expect{subject.check_outgoing_ports}.to raise_error(Flydata::AgentCompatibilityCheck::AgentCompatibilityError, /ports/)
28
+ end
21
29
  end
22
30
  end
23
31
  end
@@ -1333,5 +1333,261 @@ describe 'MysqlAlterTableParser' do
1333
1333
  let(:alter_table_action) { "REMOVE PARTITIONING" }
1334
1334
  it_behaves_like "a parser parsing a nonbreaking query"
1335
1335
  end
1336
+
1337
+ ## Change and modify column related tests
1338
+ shared_examples "test optional column" do |*examples|
1339
+ context "with column" do
1340
+ it_behaves_like *examples do
1341
+ let(:column) {" COLUMN"}
1342
+ end
1343
+ end
1344
+ context "without column" do
1345
+ it_behaves_like *examples do
1346
+ let(:column) { "" }
1347
+ end
1348
+ end
1349
+ end
1350
+ shared_examples "test position" do |*examples|
1351
+ context "with after" do
1352
+ it_behaves_like *examples do
1353
+ let(:position) {" after test_name"}
1354
+ let(:position_hash){
1355
+ { after: "test_name" }
1356
+ }
1357
+ end
1358
+ end
1359
+ context "with first" do
1360
+ it_behaves_like *examples do
1361
+ let(:position) {" first"}
1362
+ let(:position_hash){
1363
+ { position: :first }
1364
+ }
1365
+ end
1366
+ end
1367
+ context "with none" do
1368
+ it_behaves_like *examples do
1369
+ let(:position) {""}
1370
+ let(:position_hash){
1371
+ {}
1372
+ }
1373
+ end
1374
+ end
1375
+ end
1376
+ shared_examples "test not null" do |*examples|
1377
+ context "with not null option" do
1378
+ it_behaves_like *examples do
1379
+ let(:not_null) {" not null"}
1380
+ let(:not_null_hash){
1381
+ { not_null: true }
1382
+ }
1383
+ end
1384
+ end
1385
+ context "without not null option" do
1386
+ it_behaves_like *examples do
1387
+ let(:not_null) {""}
1388
+ let(:not_null_hash){
1389
+ {}
1390
+ }
1391
+ end
1392
+ end
1393
+ end
1394
+ shared_examples "test default for timestamp" do |*examples|
1395
+ context "timestamp" do
1396
+ it_behaves_like *examples do
1397
+ let(:default) {" default current_timestamp"}
1398
+ let(:default_hash){
1399
+ { default: "current_timestamp" }
1400
+ }
1401
+ end
1402
+ end
1403
+ context "timestamp" do
1404
+ it_behaves_like *examples do
1405
+ let(:default) {" default localtime"}
1406
+ let(:default_hash){
1407
+ { default: "current_timestamp" }
1408
+ }
1409
+ end
1410
+ end
1411
+ context "none" do
1412
+ it_behaves_like *examples do
1413
+ let(:default) {""}
1414
+ let(:default_hash){
1415
+ {}
1416
+ }
1417
+ end
1418
+ end
1419
+ end
1420
+ shared_examples "test default for varchar" do |*examples|
1421
+ context "null" do
1422
+ it_behaves_like *examples do
1423
+ let(:default) {" default NULL"}
1424
+ let(:default_hash){
1425
+ { default: nil }
1426
+ }
1427
+ end
1428
+ end
1429
+ context "empty string" do
1430
+ it_behaves_like *examples do
1431
+ let(:default) {" default ''"}
1432
+ let(:default_hash){
1433
+ { default: "" }
1434
+ }
1435
+ end
1436
+ end
1437
+ context "string with spaces" do
1438
+ it_behaves_like *examples do
1439
+ let(:default) {" default '0 0 0 0 0 0'"}
1440
+ let(:default_hash){
1441
+ { default: "0 0 0 0 0 0" }
1442
+ }
1443
+ end
1444
+ end
1445
+ context "none" do
1446
+ it_behaves_like *examples do
1447
+ let(:default) {""}
1448
+ let(:default_hash){
1449
+ {}
1450
+ }
1451
+ end
1452
+ end
1453
+ end
1454
+ shared_examples "test auto increment" do |*examples|
1455
+ context "with auto_increment" do
1456
+ it_behaves_like *examples do
1457
+ let(:auto_increment) {" auto_increment"}
1458
+ let(:auto_increment_hash){
1459
+ { auto_increment: true }
1460
+ }
1461
+ end
1462
+ end
1463
+ context "without auto_increment" do
1464
+ it_behaves_like *examples do
1465
+ let(:auto_increment) {""}
1466
+ let(:auto_increment_hash){
1467
+ {}
1468
+ }
1469
+ end
1470
+ end
1471
+ end
1472
+ shared_examples "test comment" do |*examples|
1473
+ context "with a comment" do
1474
+ it_behaves_like *examples do
1475
+ let(:comment) {" COMMENT 'Hello World!'"}
1476
+ end
1477
+ end
1478
+ context "with a double quoted comment" do
1479
+ it_behaves_like *examples do
1480
+ let(:comment) {%q| comment "Hello World!"|}
1481
+ end
1482
+ end
1483
+ context "with a backslash inside double quotes" do
1484
+ it_behaves_like *examples do
1485
+ let(:comment) {%q| comment "\\\\"|}
1486
+ end
1487
+ end
1488
+ context "with special characters" do
1489
+ it_behaves_like *examples do
1490
+ let(:comment) {%q| comment "https://flydata.com $ \\\\'\"\n\t"|}
1491
+ end
1492
+ end
1493
+ context "without a comment" do
1494
+ it_behaves_like *examples do
1495
+ let(:comment) {""}
1496
+ end
1497
+ end
1498
+ end
1499
+ shared_examples "test unique" do |*examples|
1500
+ context "with unique" do
1501
+ it_behaves_like *examples do
1502
+ let(:unique) {" UNIQUE"}
1503
+ let(:unique_hash){
1504
+ { unique: true }
1505
+ }
1506
+ end
1507
+ end
1508
+ context "without unique" do
1509
+ it_behaves_like *examples do
1510
+ let(:unique) {""}
1511
+ let(:unique_hash){
1512
+ {}
1513
+ }
1514
+ end
1515
+ end
1516
+ end
1517
+ shared_examples "test column definition" do |*examples|
1518
+ context "varchar" do
1519
+ it_behaves_like "test not null", "test default for varchar", "test comment", *examples do
1520
+ let(:col_def) {"varchar(256)#{not_null}#{default}#{comment}"}
1521
+ let(:col_def_hash) {
1522
+ { type: "varchar(768)" }.merge!(not_null_hash).merge!(default_hash)
1523
+ }
1524
+ end
1525
+ end
1526
+ context "timestamp" do
1527
+ it_behaves_like "test not null", "test default for timestamp", *examples do
1528
+ let(:col_def) {"timestamp#{not_null}#{default}"}
1529
+ let(:col_def_hash) {
1530
+ { type: "datetime" }.merge!(not_null_hash).merge!(default_hash)
1531
+ }
1532
+ end
1533
+ end
1534
+ context "integer" do
1535
+ it_behaves_like "test not null", "test auto increment", "test comment", *examples do
1536
+ let(:col_def) {"int(11)#{not_null}#{auto_increment}#{comment}"}
1537
+ let(:col_def_hash) {
1538
+ { type: "int4(11)" }.merge!(not_null_hash).merge!(auto_increment_hash)
1539
+ }
1540
+ end
1541
+ end
1542
+ context "decimal" do
1543
+ it_behaves_like "test not null", "test unique", *examples do
1544
+ let(:col_def) {"decimal(10,2)#{not_null}#{unique}"}
1545
+ let(:col_def_hash) {
1546
+ { type: "numeric(10,2)" }.merge!(not_null_hash).merge!(unique_hash)
1547
+ }
1548
+ end
1549
+ end
1550
+ end
1551
+ shared_examples "test parser parsing a change column" do
1552
+ let(:action_hash) {
1553
+ change_action_hash.merge!({
1554
+ action: :change_column,
1555
+ query: alter_table_action
1556
+ })
1557
+ }
1558
+ it_behaves_like "a parser parsing a single action alter table query"
1559
+ end
1560
+ context 'change column' do
1561
+ context 'change column name' do
1562
+ let(:alter_table_action) { "change#{column} name name1 #{col_def}#{position}" }
1563
+ let(:change_action_hash) {
1564
+ {
1565
+ old_column: "name",
1566
+ column: "name1",
1567
+ }.merge!(position_hash).merge!(col_def_hash)
1568
+ }
1569
+ it_behaves_like "test optional column", "test column definition", "test position", "test parser parsing a change column"
1570
+ end
1571
+ context 'no change to column name' do
1572
+ let(:alter_table_action) { "change#{column} name1 name1 #{col_def}#{position}" }
1573
+ let(:change_action_hash) {
1574
+ {
1575
+ old_column: "name1",
1576
+ column: "name1",
1577
+ }.merge!(position_hash).merge!(col_def_hash)
1578
+ }
1579
+ it_behaves_like "test optional column", "test column definition", "test position", "test parser parsing a change column"
1580
+ end
1581
+ end
1582
+ context 'modify column' do
1583
+ let(:alter_table_action) { "modify#{column} name1 #{col_def}#{position}" }
1584
+ let(:change_action_hash) {
1585
+ {
1586
+ old_column: "name1",
1587
+ column: "name1",
1588
+ }.merge!(position_hash).merge!(col_def_hash)
1589
+ }
1590
+ it_behaves_like "test optional column", "test column definition", "test position", "test parser parsing a change column"
1591
+ end
1336
1592
  end
1337
1593
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flydata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Fujikawa
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-11-03 00:00:00.000000000 Z
15
+ date: 2014-11-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rest-client
@@ -416,6 +416,7 @@ files:
416
416
  - flydata.gemspec
417
417
  - lib/fly_data_model.rb
418
418
  - lib/flydata.rb
419
+ - lib/flydata/agent_errors.rb
419
420
  - lib/flydata/api/base.rb
420
421
  - lib/flydata/api/data_entry.rb
421
422
  - lib/flydata/api/data_port.rb
@@ -441,7 +442,6 @@ files:
441
442
  - lib/flydata/compatibility_check.rb
442
443
  - lib/flydata/credentials.rb
443
444
  - lib/flydata/cron.rb
444
- - lib/flydata/errors.rb
445
445
  - lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb
446
446
  - lib/flydata/fluent-plugins/mysql/alter_table_query_handler.rb
447
447
  - lib/flydata/fluent-plugins/mysql/binlog_position.rb