flydata 0.2.17 → 0.2.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/flydata-core/.gitignore +16 -0
  4. data/flydata-core/.rspec +1 -0
  5. data/flydata-core/.travis.yml +6 -0
  6. data/flydata-core/Gemfile +11 -0
  7. data/flydata-core/Gemfile.lock +51 -0
  8. data/flydata-core/lib/flydata-core/core_ext/module/include.rb +5 -0
  9. data/flydata-core/lib/flydata-core/core_ext/module.rb +1 -0
  10. data/flydata-core/lib/flydata-core/core_ext/object/prepend.rb +17 -0
  11. data/flydata-core/lib/flydata-core/core_ext/object.rb +1 -0
  12. data/flydata-core/lib/flydata-core/core_ext.rb +3 -0
  13. data/flydata-core/lib/flydata-core/errors.rb +334 -0
  14. data/flydata-core/lib/flydata-core/logger.rb +205 -0
  15. data/{lib/flydata → flydata-core/lib/flydata-core}/table_def/mysql_table_def.rb +6 -8
  16. data/{lib/flydata → flydata-core/lib/flydata-core}/table_def/redshift_table_def.rb +17 -2
  17. data/flydata-core/lib/flydata-core/table_def.rb +2 -0
  18. data/flydata-core/lib/flydata-core/thread_context.rb +31 -0
  19. data/flydata-core/lib/flydata-core.rb +1 -0
  20. data/flydata-core/spec/spec_helper.rb +2 -0
  21. data/{spec/flydata → flydata-core/spec}/table_def/mysql_table_def_spec.rb +22 -8
  22. data/flydata-core/spec/table_def/mysql_to_redshift_table_def_spec.rb +428 -0
  23. data/flydata-core/spec/table_def/mysqldump_test_bit_table.dump +51 -0
  24. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_foreign_key.dump +0 -0
  25. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_all.dump +0 -0
  26. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_column_comment.dump +0 -0
  27. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_enum.dump +0 -0
  28. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_multi_pk.dump +0 -0
  29. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_no_pk.dump +0 -0
  30. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_unique_key.dump +0 -0
  31. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_unique_key2.dump +0 -0
  32. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_unique_key3.dump +0 -0
  33. data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_unsigned.dump +0 -0
  34. data/{spec/flydata → flydata-core/spec}/table_def/redshift_table_def_spec.rb +63 -16
  35. data/flydata.gemspec +34 -18
  36. data/lib/flydata/command/sync.rb +11 -8
  37. data/lib/flydata/parser/mysql/mysql_alter_table.treetop +128 -18
  38. data/lib/flydata/parser_provider.rb +1 -1
  39. data/lib/flydata.rb +11 -1
  40. data/spec/flydata/parser/mysql/alter_table_parser_spec.rb +173 -2
  41. data/spec/spec_helper.rb +3 -1
  42. metadata +34 -18
  43. data/.gitignore +0 -49
  44. data/lib/flydata/table_def.rb +0 -2
@@ -621,7 +621,7 @@ describe 'MysqlAlterTableParser' do
621
621
  end
622
622
  end
623
623
  end
624
- shared_examples "test key list" do |*examples|
624
+ shared_examples "test key list without order" do |*examples|
625
625
  context "with a single key" do
626
626
  it_behaves_like *examples do
627
627
  let(:key_list) { " testKey" }
@@ -634,6 +634,15 @@ describe 'MysqlAlterTableParser' do
634
634
  let(:expected_key_list) { [ "testKey" ] }
635
635
  end
636
636
  end
637
+ context "with multiple keys" do
638
+ it_behaves_like *examples do
639
+ let(:key_list) { " testKey1, testKey2" }
640
+ let(:expected_key_list) { [ "testKey1", "testKey2" ] }
641
+ end
642
+ end
643
+ end
644
+ shared_examples "test key list" do |*examples|
645
+ include_examples "test key list without order", *examples
637
646
  context "with multiple keys with order" do
638
647
  it_behaves_like *examples do
639
648
  let(:key_list) { " testKey1 ASC, testKey2 desc" }
@@ -644,11 +653,16 @@ describe 'MysqlAlterTableParser' do
644
653
 
645
654
  shared_examples "test constraint keyword" do |*examples|
646
655
  context "with constraint keyword" do
647
- context "with constraint name" do
656
+ context "with backticked constraint name" do
648
657
  it_behaves_like *examples do
649
658
  let(:constraint_keyword) { " CONSTRAINT `chkName`" }
650
659
  end
651
660
  end
661
+ context "with constraint name" do
662
+ it_behaves_like *examples do
663
+ let(:constraint_keyword) { " CONSTRAINT chkName" }
664
+ end
665
+ end
652
666
  context "without constraint name" do
653
667
  it_behaves_like *examples do
654
668
  let(:constraint_keyword) { " CONSTRAINT" }
@@ -944,6 +958,123 @@ describe 'MysqlAlterTableParser' do
944
958
  end
945
959
  end
946
960
  end
961
+ shared_examples "test optional equal" do |*examples|
962
+ context "with EQ" do
963
+ it_behaves_like *examples do
964
+ let(:equal){"="}
965
+ end
966
+ end
967
+ context "with EQ and a space before it" do
968
+ it_behaves_like *examples do
969
+ let(:equal){" ="}
970
+ end
971
+ end
972
+ context "with SET_VAR" do
973
+ it_behaves_like *examples do
974
+ let(:equal){":="}
975
+ end
976
+ end
977
+ context "with none" do
978
+ it_behaves_like *examples do
979
+ let(:equal){""}
980
+ end
981
+ end
982
+ end
983
+ shared_examples "test signed literal" do |*examples|
984
+ context "number literal" do
985
+ it_behaves_like *examples do
986
+ let(:signed_literal){"100"}
987
+ end
988
+ end
989
+ context "signed number literal" do
990
+ it_behaves_like *examples do
991
+ let(:signed_literal){"100"}
992
+ end
993
+ end
994
+ context "signed number literal within quotes" do
995
+ it_behaves_like *examples do
996
+ let(:signed_literal){"'+100'"}
997
+ end
998
+ end
999
+ context "null" do
1000
+ it_behaves_like *examples do
1001
+ let(:signed_literal){"NULL"}
1002
+ end
1003
+ end
1004
+ context "boolean" do
1005
+ it_behaves_like *examples do
1006
+ let(:signed_literal){"TRUE"}
1007
+ end
1008
+ end
1009
+ context "quoted string" do
1010
+ it_behaves_like *examples do
1011
+ let(:signed_literal){"'Hello World!'"}
1012
+ end
1013
+ end
1014
+ end
1015
+ shared_examples "test optional reference list" do |*examples|
1016
+ context "with no references" do
1017
+ it_behaves_like *examples do
1018
+ let(:opt_ref_list) {""}
1019
+ end
1020
+ end
1021
+ context "with single reference" do
1022
+ it_behaves_like *examples do
1023
+ let(:opt_ref_list) {"(id)"}
1024
+ end
1025
+ end
1026
+ context "with multiple references" do
1027
+ it_behaves_like *examples do
1028
+ let(:opt_ref_list) {" (id_1, id2)"}
1029
+ end
1030
+ end
1031
+ end
1032
+ shared_examples "test optional match clause" do |*examples|
1033
+ context "no match clause" do
1034
+ it_behaves_like *examples do
1035
+ let(:opt_match_clause) {""}
1036
+ end
1037
+ end
1038
+ context "match full" do
1039
+ it_behaves_like *examples do
1040
+ let(:opt_match_clause) {" MATCH FULL"}
1041
+ end
1042
+ end
1043
+ context "match partial" do
1044
+ it_behaves_like *examples do
1045
+ let(:opt_match_clause) {" match PARTIAL"}
1046
+ end
1047
+ end
1048
+ end
1049
+ shared_examples "test optional on update delete" do |*examples|
1050
+ context "no on update delete clause" do
1051
+ it_behaves_like *examples do
1052
+ let(:opt_on_update_delete) {""}
1053
+ end
1054
+ end
1055
+ context "on update and on delete" do
1056
+ it_behaves_like "test delete option", *examples do
1057
+ let(:opt_on_update_delete) {" on update #{delete_option} on delete #{delete_option}"}
1058
+ end
1059
+ end
1060
+ context "on update only" do
1061
+ it_behaves_like "test delete option", *examples do
1062
+ let(:opt_on_update_delete) {" ON UPDATE #{delete_option}"}
1063
+ end
1064
+ end
1065
+ end
1066
+ shared_examples "test delete option" do |*examples|
1067
+ context "restrict" do
1068
+ it_behaves_like *examples do
1069
+ let(:delete_option) {"restrict"}
1070
+ end
1071
+ end
1072
+ context "set null" do
1073
+ it_behaves_like *examples do
1074
+ let(:delete_option) {"SET NULL"}
1075
+ end
1076
+ end
1077
+ end
947
1078
  context 'add index' do
948
1079
  let(:action) { :add_index }
949
1080
  context "with a simple add index" do
@@ -1112,6 +1243,16 @@ describe 'MysqlAlterTableParser' do
1112
1243
  # "a debug parser"
1113
1244
  "a parser parsing a single action alter table query"
1114
1245
  end
1246
+ context 'add foreign key' do
1247
+ let(:action) { :add_foreign_key_constraint }
1248
+ let(:alter_table_action) { "add#{constraint_keyword} foreign key#{key_name}(#{key_list}) references employees#{opt_ref_list}#{opt_match_clause}#{opt_on_update_delete}"}
1249
+ it_behaves_like "test constraint keyword",
1250
+ "test key name", "test key list without order",
1251
+ "test optional reference list",
1252
+ "test optional match clause",
1253
+ "test optional on update delete",
1254
+ "a parser parsing a nonbreaking query"
1255
+ end
1115
1256
  context "enable keys" do
1116
1257
  let(:alter_table_action) { "ENABLE KEYS" }
1117
1258
  let(:action) { :enable_keys }
@@ -1589,5 +1730,35 @@ describe 'MysqlAlterTableParser' do
1589
1730
  }
1590
1731
  it_behaves_like "test optional column", "test column definition", "test position", "test parser parsing a change column"
1591
1732
  end
1733
+ context 'algorithm and lock option' do
1734
+ ["ALGORITHM", "LOCK"].each do |op|
1735
+ context "#{op}" do
1736
+ let(:action) { op.downcase.to_sym }
1737
+ context "with default #{op}" do
1738
+ let(:alter_table_action) { "#{op}#{equal} DEFAULT" }
1739
+ it_behaves_like "test optional equal", "a parser parsing a nonbreaking query"
1740
+ end
1741
+ context "with any #{op}" do
1742
+ let(:alter_table_action) { "#{op.downcase}#{equal} #{ident}" }
1743
+ it_behaves_like "test optional equal", "test identifier", "a parser parsing a nonbreaking query"
1744
+ end
1745
+ context "without spaces between eq and #{op}" do
1746
+ let(:alter_table_action) { "#{op}=#{ident}" }
1747
+ it_behaves_like "test identifier", "a parser parsing a nonbreaking query"
1748
+ end
1749
+ end
1750
+ end
1751
+ end
1752
+ context 'alter column' do
1753
+ let(:action) { :alter_column }
1754
+ context 'set default' do
1755
+ let(:alter_table_action) { "alter#{column} #{ident} set DEFAULT #{signed_literal}" }
1756
+ it_behaves_like "test optional column", "test field identifier", "test signed literal", "a parser parsing a nonbreaking query"
1757
+ end
1758
+ context 'drop default' do
1759
+ let(:alter_table_action) { "alter#{column} #{ident} DROP default" }
1760
+ it_behaves_like "test optional column", "test field identifier", "a parser parsing a nonbreaking query"
1761
+ end
1762
+ end
1592
1763
  end
1593
1764
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+
3
3
  require 'rspec'
4
4
  require 'active_record' # for Flydata::Heroku
5
5
  require 'protected_attributes'
@@ -30,6 +30,8 @@ RSpec.configure do |config|
30
30
  example.run
31
31
  raise ActiveRecord::Rollback
32
32
  end
33
+ else
34
+ example.run
33
35
  end
34
36
  end
35
37
  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.17
4
+ version: 0.2.18
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-24 00:00:00.000000000 Z
15
+ date: 2014-11-27 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rest-client
@@ -399,7 +399,6 @@ executables:
399
399
  extensions: []
400
400
  extra_rdoc_files: []
401
401
  files:
402
- - .gitignore
403
402
  - .rspec
404
403
  - Gemfile
405
404
  - Gemfile.lock
@@ -413,6 +412,38 @@ files:
413
412
  - bin/fdmysqldump
414
413
  - bin/flydata
415
414
  - bin/serverinfo
415
+ - flydata-core/.gitignore
416
+ - flydata-core/.rspec
417
+ - flydata-core/.travis.yml
418
+ - flydata-core/Gemfile
419
+ - flydata-core/Gemfile.lock
420
+ - flydata-core/lib/flydata-core.rb
421
+ - flydata-core/lib/flydata-core/core_ext.rb
422
+ - flydata-core/lib/flydata-core/core_ext/module.rb
423
+ - flydata-core/lib/flydata-core/core_ext/module/include.rb
424
+ - flydata-core/lib/flydata-core/core_ext/object.rb
425
+ - flydata-core/lib/flydata-core/core_ext/object/prepend.rb
426
+ - flydata-core/lib/flydata-core/errors.rb
427
+ - flydata-core/lib/flydata-core/logger.rb
428
+ - flydata-core/lib/flydata-core/table_def.rb
429
+ - flydata-core/lib/flydata-core/table_def/mysql_table_def.rb
430
+ - flydata-core/lib/flydata-core/table_def/redshift_table_def.rb
431
+ - flydata-core/lib/flydata-core/thread_context.rb
432
+ - flydata-core/spec/spec_helper.rb
433
+ - flydata-core/spec/table_def/mysql_table_def_spec.rb
434
+ - flydata-core/spec/table_def/mysql_to_redshift_table_def_spec.rb
435
+ - flydata-core/spec/table_def/mysqldump_test_bit_table.dump
436
+ - flydata-core/spec/table_def/mysqldump_test_foreign_key.dump
437
+ - flydata-core/spec/table_def/mysqldump_test_table_all.dump
438
+ - flydata-core/spec/table_def/mysqldump_test_table_column_comment.dump
439
+ - flydata-core/spec/table_def/mysqldump_test_table_enum.dump
440
+ - flydata-core/spec/table_def/mysqldump_test_table_multi_pk.dump
441
+ - flydata-core/spec/table_def/mysqldump_test_table_no_pk.dump
442
+ - flydata-core/spec/table_def/mysqldump_test_unique_key.dump
443
+ - flydata-core/spec/table_def/mysqldump_test_unique_key2.dump
444
+ - flydata-core/spec/table_def/mysqldump_test_unique_key3.dump
445
+ - flydata-core/spec/table_def/mysqldump_test_unsigned.dump
446
+ - flydata-core/spec/table_def/redshift_table_def_spec.rb
416
447
  - flydata.gemspec
417
448
  - lib/fly_data_model.rb
418
449
  - lib/flydata.rb
@@ -468,9 +499,6 @@ files:
468
499
  - lib/flydata/preference/data_entry_preference.rb
469
500
  - lib/flydata/proxy.rb
470
501
  - lib/flydata/sync_file_manager.rb
471
- - lib/flydata/table_def.rb
472
- - lib/flydata/table_def/mysql_table_def.rb
473
- - lib/flydata/table_def/redshift_table_def.rb
474
502
  - lib/flydata/util/encryptor.rb
475
503
  - spec/fluent_plugins_spec_helper.rb
476
504
  - spec/fly_data_model_spec.rb
@@ -488,18 +516,6 @@ files:
488
516
  - spec/flydata/parser/mysql/alter_table_parser_spec.rb
489
517
  - spec/flydata/parser/mysql/dump_parser_spec.rb
490
518
  - spec/flydata/sync_file_manager_spec.rb
491
- - spec/flydata/table_def/mysql_table_def_spec.rb
492
- - spec/flydata/table_def/mysqldump_test_foreign_key.dump
493
- - spec/flydata/table_def/mysqldump_test_table_all.dump
494
- - spec/flydata/table_def/mysqldump_test_table_column_comment.dump
495
- - spec/flydata/table_def/mysqldump_test_table_enum.dump
496
- - spec/flydata/table_def/mysqldump_test_table_multi_pk.dump
497
- - spec/flydata/table_def/mysqldump_test_table_no_pk.dump
498
- - spec/flydata/table_def/mysqldump_test_unique_key.dump
499
- - spec/flydata/table_def/mysqldump_test_unique_key2.dump
500
- - spec/flydata/table_def/mysqldump_test_unique_key3.dump
501
- - spec/flydata/table_def/mysqldump_test_unsigned.dump
502
- - spec/flydata/table_def/redshift_table_def_spec.rb
503
519
  - spec/flydata/util/encryptor_spec.rb
504
520
  - spec/flydata_spec.rb
505
521
  - spec/spec_helper.rb
data/.gitignore DELETED
@@ -1,49 +0,0 @@
1
- # rcov generated
2
- coverage
3
- coverage.data
4
-
5
- # rdoc generated
6
- rdoc
7
-
8
- # yard generated
9
- doc
10
- .yardoc
11
-
12
- # bundler
13
- .bundle
14
-
15
- # jeweler generated
16
- pkg
17
-
18
- # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
- #
20
- # * Create a file at ~/.gitignore
21
- # * Include files you want ignored
22
- # * Run: git config --global core.excludesfile ~/.gitignore
23
- #
24
- # After doing this, these files will be ignored in all your git projects,
25
- # saving you from having to 'pollute' every project you touch with them
26
- #
27
- # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
- #
29
- # For MacOS:
30
- #
31
- #.DS_Store
32
-
33
- # For TextMate
34
- #*.tmproj
35
- #tmtags
36
-
37
- # For emacs:
38
- #*~
39
- #\#*
40
- #.\#*
41
-
42
- # For vim:
43
- #*.swp
44
-
45
- # For redcar:
46
- #.redcar
47
-
48
- # For rubinius:
49
- #*.rbc
@@ -1,2 +0,0 @@
1
- require 'flydata/table_def/redshift_table_def'
2
- require 'flydata/table_def/mysql_table_def'