flydata 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/flydata.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "flydata"
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Koichi Fujikawa"]
12
- s.date = "2014-05-10"
12
+ s.date = "2014-05-15"
13
13
  s.description = "FlyData Command Line Interface"
14
14
  s.email = "sysadmin@flydata.co"
15
15
  s.executables = ["fdmysqldump", "flydata"]
@@ -36,13 +36,15 @@ module Flydata
36
36
 
37
37
  def check
38
38
  de = retrieve_data_entries.first
39
- ret = do_check(de)
40
- if ret['complete']
41
- puts "No buffer data on FlyData. #{ret.inspect}"
42
- true
43
- else
44
- puts "Now processing data on FlyData. #{ret.inspect}"
45
- false
39
+ retry_on(RestClient::Exception) do
40
+ ret = do_check(de)
41
+ if ret['complete']
42
+ puts "No buffer data on FlyData. #{ret.inspect}"
43
+ true
44
+ else
45
+ puts "Now processing data on FlyData. #{ret.inspect}"
46
+ false
47
+ end
46
48
  end
47
49
  end
48
50
 
@@ -75,5 +75,22 @@ You can check the logs of sender(flydata) process.
75
75
  def flydata_conf_file
76
76
  File.join(FLYDATA_HOME, 'flydata.conf')
77
77
  end
78
+
79
+ # Retry the given block if +exception+ happens
80
+ def retry_on(exception = StandardError, try_count = 3, interval = 1.0)
81
+ count = 0
82
+ begin
83
+ count += 1
84
+ yield
85
+ rescue exception
86
+ if count < try_count
87
+ sleep interval
88
+ interval *= 2
89
+ retry
90
+ else
91
+ raise
92
+ end
93
+ end
94
+ end
78
95
  end
79
96
  end
@@ -71,19 +71,24 @@ class MysqlTableDef
71
71
  when :in_create_table
72
72
  table_def += line.chomp
73
73
 
74
+ stripped_line = line.strip
74
75
  # `col_smallint` smallint(6) DEFAULT NULL,
75
- if line.strip.start_with?('`')
76
+ if stripped_line.start_with?('`')
76
77
  columns << parse_column_line(line)
77
78
  # PRIMARY KEY (`id`)
78
- elsif line.strip.start_with?("PRIMARY KEY")
79
+ elsif stripped_line.start_with?("PRIMARY KEY")
79
80
  parse_primary_key(line, columns)
80
81
  #) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='test table';
81
- elsif line.strip.start_with?(')')
82
+ elsif stripped_line.start_with?(')')
82
83
  default_charset = $1 if line =~ /DEFAULT CHARSET\s*=\s*([^\s]+)/
83
84
  comment = $1 if /COMMENT='((?:\\'|[^'])*)'/.match(line)
84
85
  position = :after_create_table
86
+ elsif stripped_line.start_with?("KEY")
87
+ # index creation. No action required.
88
+ elsif stripped_line.start_with?("CONSTRAINT")
89
+ # constraint definition. No acction required.
85
90
  else
86
- raise "Invalid mysqldump file. It must be a bug...\n#{line}"
91
+ $stderr.puts "Unknown table definition. Skip. (#{line})"
87
92
  end
88
93
 
89
94
  when :after_create_table
@@ -116,6 +116,20 @@ describe MysqlTableDef do
116
116
  )
117
117
  end
118
118
  end
119
+
120
+ context 'when table has index and foreign key constraints' do
121
+ let(:dump_file_io) { file_io('mysqldump_test_foreign_key.dump') }
122
+ it 'should parse the dump correctly' do
123
+ expect(subject[:columns]).to eq(
124
+ [
125
+ {:name=>"no", :type=>"int4(11)", :auto_increment=>true, :not_null=>true, :primary_key=>true},
126
+ {:name=>"product_category", :type=>"int4(11)", :not_null=>true},
127
+ {:name=>"product_id", :type=>"int4(11)", :not_null=>true},
128
+ {:name=>"customer_id", :type=>"int4(11)", :not_null=>true},
129
+ ]
130
+ )
131
+ end
132
+ end
119
133
  end
120
134
  end
121
135
 
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.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-10 00:00:00.000000000 Z
12
+ date: 2014-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -390,7 +390,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
390
390
  version: '0'
391
391
  segments:
392
392
  - 0
393
- hash: -1932242309607756156
393
+ hash: -913931267445812581
394
394
  required_rubygems_version: !ruby/object:Gem::Requirement
395
395
  none: false
396
396
  requirements: