ridgepole 0.6.5.beta → 0.6.5.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -2
  3. data/Appraisals +1 -1
  4. data/README.md +3 -1
  5. data/gemfiles/activerecord_5.0.gemfile +1 -1
  6. data/lib/ridgepole/client.rb +5 -1
  7. data/lib/ridgepole/delta.rb +21 -5
  8. data/lib/ridgepole/diff.rb +13 -2
  9. data/lib/ridgepole/dsl_parser.rb +38 -3
  10. data/lib/ridgepole/dumper.rb +2 -2
  11. data/lib/ridgepole/ext/abstract_mysql_adapter/disable_table_options.rb +21 -0
  12. data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +28 -0
  13. data/lib/ridgepole/version.rb +1 -1
  14. data/ridgepole.gemspec +3 -3
  15. data/spec/erb_helper.rb +43 -0
  16. data/spec/mysql/bigint_pk/bigint_pk_spec.rb +9 -9
  17. data/spec/mysql/collation/collation_spec.rb +39 -37
  18. data/spec/mysql/default_lambda/default_lambda_spec.rb +162 -0
  19. data/spec/mysql/diff/diff2_spec.rb +10 -10
  20. data/spec/mysql/diff/diff_spec.rb +6 -6
  21. data/spec/mysql/dump/dump_class_method_spec.rb +56 -39
  22. data/spec/mysql/dump/dump_some_tables_spec.rb +21 -13
  23. data/spec/mysql/dump/dump_spec.rb +49 -36
  24. data/spec/mysql/dump/dump_without_table_options_spec.rb +27 -9
  25. data/spec/mysql/fk/migrate_change_fk_spec.rb +17 -11
  26. data/spec/mysql/fk/migrate_create_fk_spec.rb +20 -18
  27. data/spec/mysql/fk/migrate_drop_fk_spec.rb +30 -16
  28. data/spec/mysql/migrate/migrate_add_column2_spec.rb +10 -8
  29. data/spec/mysql/migrate/migrate_add_column_spec.rb +49 -61
  30. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +46 -58
  31. data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +46 -58
  32. data/spec/mysql/migrate/migrate_change_column2_spec.rb +12 -24
  33. data/spec/mysql/migrate/migrate_change_column3_spec.rb +18 -30
  34. data/spec/mysql/migrate/migrate_change_column5_spec.rb +8 -20
  35. data/spec/mysql/migrate/migrate_change_column6_spec.rb +8 -8
  36. data/spec/mysql/migrate/migrate_change_column_default_spec.rb +20 -20
  37. data/spec/mysql/migrate/migrate_change_column_float_spec.rb +2 -2
  38. data/spec/mysql/migrate/migrate_change_column_spec.rb +54 -68
  39. data/spec/mysql/migrate/migrate_change_index2_spec.rb +14 -14
  40. data/spec/mysql/migrate/migrate_change_index3_spec.rb +28 -28
  41. data/spec/mysql/migrate/migrate_change_index4_spec.rb +26 -38
  42. data/spec/mysql/migrate/migrate_change_index5_spec.rb +20 -32
  43. data/spec/mysql/migrate/migrate_change_index6_spec.rb +63 -75
  44. data/spec/mysql/migrate/migrate_change_index_spec.rb +62 -74
  45. data/spec/mysql/migrate/migrate_change_table_option_spec.rb +8 -20
  46. data/spec/mysql/migrate/migrate_create_index2_spec.rb +98 -53
  47. data/spec/mysql/migrate/migrate_create_index_spec.rb +84 -39
  48. data/spec/mysql/migrate/migrate_create_table_spec.rb +69 -39
  49. data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +69 -39
  50. data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +47 -59
  51. data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +43 -55
  52. data/spec/mysql/migrate/migrate_drop_column_spec.rb +48 -60
  53. data/spec/mysql/migrate/migrate_drop_index_spec.rb +84 -39
  54. data/spec/mysql/migrate/migrate_drop_table_spec.rb +76 -46
  55. data/spec/mysql/migrate/migrate_empty_spec.rb +24 -36
  56. data/spec/mysql/migrate/migrate_execute_spec.rb +30 -32
  57. data/spec/mysql/migrate/migrate_log_file_spec.rb +69 -39
  58. data/spec/mysql/migrate/migrate_merge_mode_spec.rb +48 -48
  59. data/spec/mysql/migrate/migrate_noop_spec.rb +23 -13
  60. data/spec/mysql/migrate/migrate_rename_column_spec.rb +48 -60
  61. data/spec/mysql/migrate/migrate_rename_table_spec.rb +56 -68
  62. data/spec/mysql/migrate/migrate_same_default_null_spec.rb +8 -20
  63. data/spec/mysql/migrate/migrate_same_spec.rb +49 -31
  64. data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +48 -60
  65. data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +48 -60
  66. data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +34 -34
  67. data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +84 -39
  68. data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +84 -39
  69. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +84 -0
  70. data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +14 -8
  71. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +15 -27
  72. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +10 -10
  73. data/spec/postgresql/dump/dump_spec.rb +40 -16
  74. data/spec/postgresql/fk/migrate_change_fk_spec.rb +6 -6
  75. data/spec/postgresql/fk/migrate_create_fk_spec.rb +11 -11
  76. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +8 -8
  77. data/spec/postgresql/migrate/migrate_add_column_spec.rb +20 -20
  78. data/spec/postgresql/migrate/migrate_change_column_spec.rb +20 -20
  79. data/spec/postgresql/migrate/migrate_change_index_spec.rb +20 -20
  80. data/spec/postgresql/migrate/migrate_create_table_spec.rb +52 -12
  81. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +20 -20
  82. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +18 -18
  83. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +69 -13
  84. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +55 -13
  85. data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +3 -1
  86. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +20 -20
  87. data/spec/postgresql/migrate/migrate_rename_table_spec.rb +24 -24
  88. data/spec/postgresql/migrate/migrate_same_spec.rb +40 -16
  89. data/spec/postgresql/ridgepole_test_tables.sql +3 -0
  90. data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +6 -6
  91. data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +11 -11
  92. data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +8 -8
  93. data/spec/spec_condition.rb +14 -2
  94. data/spec/spec_helper.rb +12 -11
  95. data/spec/string_ext.rb +2 -0
  96. metadata +16 -9
  97. data/lib/ridgepole/ext/abstract_mysql_adapter.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1afe38c33e11fab6506b3b4803488aec6058ddfb
4
- data.tar.gz: 84819c79b7e1d2756f84682f2749ee9c51f09181
3
+ metadata.gz: 5175eaaaf37dc9607941847db6b26fc41ded724a
4
+ data.tar.gz: 5091e1b556002310437ea3f6982b89e51ca37e74
5
5
  SHA512:
6
- metadata.gz: a1c834a74ee2b5f861f0a29fccb41b5411dfb9013aeebc9823ae5232a5994ee6b1b14075a1a74b85af005df6f9c4f799f375b7ac3ffd39ba8e1d1a9448404db5
7
- data.tar.gz: 7153c5acdb81e28810c40049490a321ade6bd2f986b0d4a64435cb227ee1d73dd63480e5c8be0af2691af7333775d5664f4852f7281cd24c7091e2bd70fea99d
6
+ metadata.gz: 5468e43b1edb0ec5e3bedd4c51caadb44bced02ee448ad22b5da5b5e0108060d78380387ca96469319bd4661dbef9e7c3c590c4d5ee4e161c51e2f6004bdda59
7
+ data.tar.gz: b73e8fef699d8bf36ea63ae656cd1961e4b1908486155dd055742a0d338d4c4b4a44aa80a34170a89eff58f31c6c17fca2a324dafd154783cdd86712041f84d1
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ cache:
6
6
  - apt
7
7
  rvm:
8
8
  - 2.2.4
9
- - 2.3.0
9
+ - 2.3.1
10
10
  before_install:
11
11
  - gem install bundler
12
12
  - sudo service postgresql stop
@@ -20,12 +20,16 @@ script:
20
20
  - bundle exec rake
21
21
  gemfile:
22
22
  - gemfiles/activerecord_4.2.gemfile
23
- #- gemfiles/activerecord_5.0.gemfile
23
+ - gemfiles/activerecord_5.0.gemfile
24
24
  env:
25
25
  matrix:
26
26
  - ENABLE_MYSQL_AWESOME=0
27
27
  - ENABLE_MYSQL_AWESOME=1
28
28
  - POSTGRESQL=1
29
+ matrix:
30
+ exclude:
31
+ - env: ENABLE_MYSQL_AWESOME=1
32
+ gemfile: gemfiles/activerecord_5.0.gemfile
29
33
  services:
30
34
  - docker
31
35
  addons:
data/Appraisals CHANGED
@@ -4,5 +4,5 @@ appraise "activerecord-4.2" do
4
4
  end
5
5
 
6
6
  appraise 'activerecord-5.0' do
7
- gem 'activerecord', '>= 5.0.0.beta3'
7
+ gem 'activerecord', '>= 5.0.0.rc1'
8
8
  end
data/README.md CHANGED
@@ -51,7 +51,9 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
51
51
  * Remove migration_comments
52
52
  * Fix foreign key apply order
53
53
  * `>= 0.6.5`
54
- * Fix rails version '>= 4.2', '< 6'
54
+ * Fix rails version `'>= 4.2', '< 6'`
55
+ * Support new types ([pull#84](https://github.com/winebarrel/ridgepole/pull/84))
56
+ * Support `default: -> { ... }` ([pull#85](https://github.com/winebarrel/ridgepole/pull/85))
55
57
 
56
58
  ## Installation
57
59
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", ">= 5.0.0.beta3"
5
+ gem "activerecord", ">= 5.0.0.rc1"
6
6
 
7
7
  gemspec :path => "../"
@@ -19,12 +19,16 @@ class Ridgepole::Client
19
19
  end
20
20
 
21
21
  if @options[:mysql_use_alter]
22
- require 'ridgepole/ext/abstract_mysql_adapter'
22
+ require 'ridgepole/ext/abstract_mysql_adapter/use_alter_index'
23
23
  end
24
24
 
25
25
  if @options[:dumb_with_default_fk_name]
26
26
  require 'ridgepole/ext/schema_dumper'
27
27
  end
28
+
29
+ if ActiveRecord::VERSION::MAJOR >= 5 and @options[:dump_without_table_options]
30
+ require 'ridgepole/ext/abstract_mysql_adapter/disable_table_options'
31
+ end
28
32
  end
29
33
 
30
34
  def dump(&block)
@@ -227,7 +227,7 @@ create_table(#{table_name.inspect}, #{options.inspect}) do |t|
227
227
  normalize_limit(column_type, column_options)
228
228
 
229
229
  buf.puts(<<-EOS)
230
- t.#{column_type}(#{column_name.inspect}, #{column_options.inspect})
230
+ t.#{column_type}(#{column_name.inspect}, #{inspect_column_options(column_options)})
231
231
  EOS
232
232
  end
233
233
 
@@ -320,11 +320,11 @@ drop_table(#{table_name.inspect})
320
320
 
321
321
  if @options[:bulk_change]
322
322
  buf.puts(<<-EOS)
323
- t.column(#{column_name.inspect}, #{type.inspect}, #{options.inspect})
323
+ t.column(#{column_name.inspect}, #{type.inspect}, #{inspect_column_options(options)})
324
324
  EOS
325
325
  else
326
326
  buf.puts(<<-EOS)
327
- add_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{options.inspect})
327
+ add_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{inspect_column_options(options)})
328
328
  EOS
329
329
  end
330
330
  end
@@ -347,11 +347,11 @@ rename_column(#{table_name.inspect}, #{from_column_name.inspect}, #{to_column_na
347
347
 
348
348
  if @options[:bulk_change]
349
349
  buf.puts(<<-EOS)
350
- t.change(#{column_name.inspect}, #{type.inspect}, #{options.inspect})
350
+ t.change(#{column_name.inspect}, #{type.inspect}, #{inspect_column_options(options)})
351
351
  EOS
352
352
  else
353
353
  buf.puts(<<-EOS)
354
- change_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{options.inspect})
354
+ change_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{inspect_column_options(options)})
355
355
  EOS
356
356
  end
357
357
  end
@@ -445,4 +445,20 @@ remove_foreign_key(#{table_name.inspect}, #{target.inspect})
445
445
  default_limit = Ridgepole::DefaultsLimit.default_limit(column_type, @options)
446
446
  column_options[:limit] ||= default_limit if default_limit
447
447
  end
448
+
449
+ def inspect_column_options(options)
450
+ options = options.dup
451
+
452
+ if options[:default].kind_of?(Proc)
453
+ proc_default = options.delete(:default)
454
+ proc_default = ":default=>proc{#{proc_default.call.inspect}}"
455
+ options_inspect = options.inspect
456
+ options_inspect.sub!(/\}\z/, '')
457
+ options_inspect << ', ' if options_inspect !~ /\{\z/
458
+ options_inspect << proc_default << '}'
459
+ options_inspect
460
+ else
461
+ options.inspect
462
+ end
463
+ end
448
464
  end
@@ -114,7 +114,7 @@ class Ridgepole::Diff
114
114
  normalize_column_options!(from_attrs)
115
115
  normalize_column_options!(to_attrs)
116
116
 
117
- if from_attrs != to_attrs
117
+ unless compare_column_attrs(from_attrs, to_attrs)
118
118
  definition_delta[:change] ||= {}
119
119
  to_attrs = fix_change_column_options(table_name, from_attrs, to_attrs)
120
120
  definition_delta[:change][column_name] = to_attrs
@@ -322,7 +322,6 @@ class Ridgepole::Diff
322
322
  end
323
323
  end
324
324
 
325
-
326
325
  # XXX: MySQL only?
327
326
  # https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L760
328
327
  # https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb#L102
@@ -347,4 +346,16 @@ class Ridgepole::Diff
347
346
 
348
347
  to_attrs
349
348
  end
349
+
350
+ def compare_column_attrs(attrs1, attrs2)
351
+ attrs1 = attrs1.merge(:options => attrs1.fetch(:options, {}).dup)
352
+ attrs2 = attrs2.merge(:options => attrs2.fetch(:options, {}).dup)
353
+
354
+ if attrs1[:options][:default].kind_of?(Proc) and attrs2[:options][:default].kind_of?(Proc)
355
+ attrs1[:options][:default] = attrs1[:options][:default].call
356
+ attrs2[:options][:default] = attrs2[:options][:default].call
357
+ end
358
+
359
+ attrs1 == attrs2
360
+ end
350
361
  end
@@ -19,7 +19,7 @@ class Ridgepole::DSLParser
19
19
  end
20
20
 
21
21
  TYPES = [
22
- # https://github.com/winebarrel/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L274
22
+ # https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L274
23
23
  :string,
24
24
  :text,
25
25
  :integer,
@@ -33,7 +33,7 @@ class Ridgepole::DSLParser
33
33
  :binary,
34
34
  :boolean,
35
35
 
36
- # https://github.com/winebarrel/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L79
36
+ # https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L79
37
37
  :daterange,
38
38
  :numrange,
39
39
  :tsrange,
@@ -58,7 +58,7 @@ class Ridgepole::DSLParser
58
58
  :bit,
59
59
  :bit_varying,
60
60
  :money,
61
- ]
61
+ ].uniq
62
62
 
63
63
  TYPES.each do |column_type|
64
64
  define_method column_type do |*args|
@@ -68,6 +68,41 @@ class Ridgepole::DSLParser
68
68
  end
69
69
  end
70
70
 
71
+ ALIAS_TYPES = {
72
+ # https://github.com/rails/rails/blob/v5.0.0.rc1/activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb
73
+ tinyblob: [:blob, {limit: 255}],
74
+ mediumblob: [:binary, {limit: 16777215}],
75
+ longblob: [:binary, {limit: 4294967295}],
76
+ tinytext: [:text, {limit: 255}],
77
+ mediumtext: [:text, {limit: 16777215}],
78
+ longtext: [:text, {limit: 4294967295}],
79
+ unsigned_integer: [:integer, {unsigned: true}],
80
+ unsigned_bigint: [:bigint, {unsigned: true}],
81
+ unsigned_float: [:float, {limit: 24, unsigned: true}],
82
+ unsigned_decimal: [:decimal, {precision: 10, unsigned: true}],
83
+ }
84
+
85
+ # XXX:
86
+ def blob(*args)
87
+ options = args.extract_options!
88
+ options = {limit: 65535}.merge(options)
89
+ column_names = args
90
+
91
+ column_names.each do |name|
92
+ column_type = (0..0xff).include?(options[:limit]) ? :blob : :binary
93
+ column(name, column_type, options)
94
+ end
95
+ end
96
+
97
+ ALIAS_TYPES.each do |alias_type, (column_type, default_options)|
98
+ define_method alias_type do |*args|
99
+ options = args.extract_options!
100
+ options = default_options.merge(options)
101
+ column_names = args
102
+ column_names.each {|name| column(name, column_type, options) }
103
+ end
104
+ end
105
+
71
106
  def index(name, options = {})
72
107
  @base.add_index(@table_name, name, options)
73
108
  end
@@ -10,14 +10,14 @@ class Ridgepole::Dumper
10
10
  ignore_tables = @options[:ignore_tables]
11
11
 
12
12
  if target_tables
13
- conn.tables.each do |tbl|
13
+ conn.data_sources.each do |tbl|
14
14
  next if target_tables.include?(tbl)
15
15
  ActiveRecord::SchemaDumper.ignore_tables << tbl
16
16
  end
17
17
  end
18
18
 
19
19
  if ignore_tables
20
- conn.tables.each do |tbl|
20
+ conn.data_sources.each do |tbl|
21
21
  if ignore_tables.any? {|i| i =~ tbl } and not (target_tables and target_tables.include?(tbl))
22
22
  ActiveRecord::SchemaDumper.ignore_tables << tbl
23
23
  end
@@ -0,0 +1,21 @@
1
+ require 'active_record/connection_adapters/abstract_mysql_adapter'
2
+
3
+ module Ridgepole
4
+ module Ext
5
+ module AbstractMysqlAdapter
6
+ module DisableTableOptions
7
+ def table_options(table_name)
8
+ nil
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ module ActiveRecord
16
+ module ConnectionAdapters
17
+ class AbstractMysqlAdapter
18
+ prepend Ridgepole::Ext::AbstractMysqlAdapter::DisableTableOptions
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ require 'active_record/connection_adapters/abstract_mysql_adapter'
2
+
3
+ module Ridgepole
4
+ module Ext
5
+ module AbstractMysqlAdapter
6
+ module UseAlterIndex
7
+ def add_index(table_name, column_name, options = {})
8
+ index_name, index_type, index_columns, index_options, index_algorithm, index_using = add_index_options(table_name, column_name, options)
9
+
10
+ # cannot specify index_algorithm
11
+ execute "ALTER TABLE #{quote_table_name(table_name)} ADD #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})#{index_options}"
12
+ end
13
+
14
+ def remove_index!(table_name, index_name)
15
+ execute "ALTER TABLE #{quote_table_name(table_name)} DROP INDEX #{quote_column_name(index_name)}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ module ActiveRecord
23
+ module ConnectionAdapters
24
+ class AbstractMysqlAdapter
25
+ prepend Ridgepole::Ext::AbstractMysqlAdapter::UseAlterIndex
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.6.5.beta'
2
+ VERSION = '0.6.5.beta2'
3
3
  end
data/ridgepole.gemspec CHANGED
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'pg'
27
27
  spec.add_development_dependency 'coveralls'
28
28
  spec.add_development_dependency 'appraisal'
29
- spec.add_development_dependency 'rspec-match_fuzzy', '>= 0.1.2'
30
- spec.add_development_dependency 'erbh'
29
+ spec.add_development_dependency 'rspec-match_fuzzy', '>= 0.1.3'
30
+ spec.add_development_dependency 'erbh', '>= 0.1.2'
31
31
  spec.add_development_dependency 'hash_modern_inspect', '>= 0.1.1'
32
- spec.add_development_dependency 'hash_order_helper', '>= 0.1.1'
32
+ spec.add_development_dependency 'hash_order_helper', '>= 0.1.5'
33
33
  end
@@ -0,0 +1,43 @@
1
+ include ERBh
2
+
3
+ ERBh.define_method(:i) do |obj|
4
+ if obj.nil? or (obj.respond_to?(:empty?) and obj.empty?)
5
+ @_erbout.sub!(/,\s*\z/, '')
6
+ ''
7
+ else
8
+ obj.modern_inspect_without_brace
9
+ end
10
+ end
11
+
12
+ ERBh.define_method(:add_index) do |table_name, column_name, options|
13
+ if condition(:activerecord_5)
14
+ @_erbout.sub!(/\bend\s*\z/, '')
15
+
16
+ <<-EOS
17
+ t.index #{column_name.inspect}, #{options.modern_inspect_without_brace}
18
+ end
19
+ EOS
20
+ else
21
+ "add_index #{table_name.inspect}, #{column_name.inspect}, #{options.modern_inspect_without_brace}"
22
+ end
23
+ end
24
+
25
+ ERBh.define_method(:unsigned) do |value, *conds|
26
+ conds = [:mysql_awesome_enabled] if conds.empty?
27
+
28
+ if condition(*conds)
29
+ {unsigned: value}
30
+ else
31
+ {}
32
+ end
33
+ end
34
+
35
+ ERBh.define_method(:limit) do |value, *conds|
36
+ conds = [:activerecord_4] if conds.empty?
37
+
38
+ if condition(*conds)
39
+ {limit: value}
40
+ else
41
+ {}
42
+ end
43
+ end
@@ -1,24 +1,24 @@
1
- describe 'Ridgepole::Client (with bigint pk)', condition: [:mysql_awesome_enabled] do
1
+ describe 'Ridgepole::Client (with bigint pk)', condition: [:mysql_awesome_enabled, :activerecord_5] do
2
2
  let(:dsl1) {
3
- <<-RUBY
3
+ erbh(<<-EOS)
4
4
  create_table "books", id: :primary_key, limit: 8, force: :cascade do |t|
5
- t.string "title", limit: 255, null: false
6
- t.integer "author_id", limit: 4, null: false
5
+ t.string "title", <%= i limit(255) + {null: false} %>
6
+ t.integer "author_id", <%= i limit(4) + {null: false} %>
7
7
  t.datetime "created_at"
8
8
  t.datetime "updated_at"
9
9
  end
10
- RUBY
10
+ EOS
11
11
  }
12
12
 
13
13
  let(:dsl2) {
14
- <<-RUBY
14
+ erbh(<<-EOS)
15
15
  create_table "books", id: :bigint, force: :cascade do |t|
16
- t.string "title", limit: 255, null: false
17
- t.integer "author_id", limit: 4, null: false
16
+ t.string "title", <%= i limit(255) + {null: false} %>
17
+ t.integer "author_id", <%= i limit(4) + {null: false} %>
18
18
  t.datetime "created_at"
19
19
  t.datetime "updated_at"
20
20
  end
21
- RUBY
21
+ EOS
22
22
  }
23
23
 
24
24
  context 'when with limit:8' do
@@ -1,25 +1,25 @@
1
- describe 'Ridgepole::Client#diff -> migrate', condition: [:mysql_awesome_enabled] do
1
+ describe 'Ridgepole::Client#diff -> migrate', condition: [:mysql_awesome_enabled, :activerecord_5] do
2
2
  context 'when change column (add collation)' do
3
3
  let(:actual_dsl) {
4
- <<-RUBY
4
+ erbh(<<-EOS)
5
5
  create_table "employee_clubs", unsigned: true, force: :cascade do |t|
6
- t.integer "emp_no", limit: 4, null: false
7
- t.integer "club_id", limit: 4, null: false, unsigned: true
8
- t.string "string", limit: 255, null: false
6
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
7
+ t.integer "club_id", <%= i limit(4) + {null: false, unsigned: true} %>
8
+ t.string "string", <%= i limit(255) + {null: false, collation: "ascii_bin"} %>
9
9
  t.text "text", limit: 65535, null: false
10
10
  end
11
- RUBY
11
+ EOS
12
12
  }
13
13
 
14
14
  let(:expected_dsl) {
15
- <<-RUBY
15
+ erbh(<<-EOS)
16
16
  create_table "employee_clubs", unsigned: true, force: :cascade do |t|
17
- t.integer "emp_no", limit: 4, null: false
18
- t.integer "club_id", limit: 4, null: false, unsigned: true
19
- t.string "string", limit: 255, null: false, collation: "ascii_bin"
17
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
18
+ t.integer "club_id", <%= i limit(4) + {null: false, unsigned: true} %>
19
+ t.string "string", <%= i limit(255) + {null: false, collation: "ascii_bin"} %>
20
20
  t.text "text", limit: 65535, null: false, collation: "utf8mb4_bin"
21
21
  end
22
- RUBY
22
+ EOS
23
23
  }
24
24
 
25
25
  before { subject.diff(actual_dsl).migrate }
@@ -36,25 +36,25 @@ describe 'Ridgepole::Client#diff -> migrate', condition: [:mysql_awesome_enabled
36
36
 
37
37
  context 'when change column (delete collation)' do
38
38
  let(:actual_dsl) {
39
- <<-RUBY
39
+ erbh(<<-EOS)
40
40
  create_table "employee_clubs", unsigned: true, force: :cascade do |t|
41
- t.integer "emp_no", limit: 4, null: false
42
- t.integer "club_id", limit: 4, null: false, unsigned: true
43
- t.string "string", limit: 255, null: false, collation: "ascii_bin"
41
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
42
+ t.integer "club_id", <%= i limit(4) + {null: false, unsigned: true} %>
43
+ t.string "string", <%= i limit(255) + {null: false, collation: "ascii_bin"} %>
44
44
  t.text "text", limit: 65535, null: false, collation: "utf8mb4_bin"
45
45
  end
46
- RUBY
46
+ EOS
47
47
  }
48
48
 
49
49
  let(:expected_dsl) {
50
- <<-RUBY
50
+ erbh(<<-EOS)
51
51
  create_table "employee_clubs", unsigned: true, force: :cascade do |t|
52
- t.integer "emp_no", limit: 4, null: false
53
- t.integer "club_id", limit: 4, null: false, unsigned: true
54
- t.string "string", limit: 255, null: false
52
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
53
+ t.integer "club_id", <%= i limit(4) + {null: false, unsigned: true} %>
54
+ t.string "string", <%= i limit(255) + {null: false, collation: "ascii_bin"} %>
55
55
  t.text "text", limit: 65535, null: false
56
56
  end
57
- RUBY
57
+ EOS
58
58
  }
59
59
 
60
60
  before { subject.diff(actual_dsl).migrate }
@@ -71,25 +71,25 @@ describe 'Ridgepole::Client#diff -> migrate', condition: [:mysql_awesome_enabled
71
71
 
72
72
  context 'when change column (change collation)' do
73
73
  let(:actual_dsl) {
74
- <<-RUBY
74
+ erbh(<<-EOS)
75
75
  create_table "employee_clubs", unsigned: true, force: :cascade do |t|
76
- t.integer "emp_no", limit: 4, null: false
77
- t.integer "club_id", limit: 4, null: false, unsigned: true
78
- t.string "string", limit: 255, null: false, collation: "ascii_bin"
76
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
77
+ t.integer "club_id", <%= i limit(4) + {null: false, unsigned: true} %>
78
+ t.string "string", <%= i limit(255) + {null: false, collation: "ascii_bin"} %>
79
79
  t.text "text", limit: 65535, null: false, collation: "utf8mb4_bin"
80
80
  end
81
- RUBY
81
+ EOS
82
82
  }
83
83
 
84
84
  let(:expected_dsl) {
85
- <<-RUBY
85
+ erbh(<<-EOS)
86
86
  create_table "employee_clubs", unsigned: true, force: :cascade do |t|
87
- t.integer "emp_no", limit: 4, null: false
88
- t.integer "club_id", limit: 4, null: false, unsigned: true
89
- t.string "string", limit: 255, null: false, collation: "utf8mb4_bin"
87
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
88
+ t.integer "club_id", <%= i limit(4) + {null: false, unsigned: true} %>
89
+ t.string "string", <%= i limit(255) + {null: false, collation: "utf8mb4_bin"} %>
90
90
  t.text "text", limit: 65535, null: false, collation: "ascii_bin"
91
91
  end
92
- RUBY
92
+ EOS
93
93
  }
94
94
 
95
95
  before { subject.diff(actual_dsl).migrate }
@@ -106,14 +106,14 @@ describe 'Ridgepole::Client#diff -> migrate', condition: [:mysql_awesome_enabled
106
106
 
107
107
  context 'when change column (no change collation)' do
108
108
  let(:actual_dsl) {
109
- <<-RUBY
109
+ erbh(<<-EOS)
110
110
  create_table "employee_clubs", unsigned: true, force: :cascade do |t|
111
- t.integer "emp_no", limit: 4, null: false
112
- t.integer "club_id", limit: 4, null: false, unsigned: true
113
- t.string "string", limit: 255, null: false, collation: "ascii_bin"
111
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
112
+ t.integer "club_id", <%= i limit(4) + {null: false, unsigned: true} %>
113
+ t.string "string", <%= i limit(255) + {null: false, collation: "ascii_bin"} %>
114
114
  t.text "text", limit: 65535, null: false, collation: "utf8mb4_bin"
115
115
  end
116
- RUBY
116
+ EOS
117
117
  }
118
118
 
119
119
  before { subject.diff(actual_dsl).migrate }
@@ -133,7 +133,9 @@ describe 'Ridgepole::Client#diff -> migrate', condition: [:mysql_awesome_enabled
133
133
  f.puts(actual_dsl)
134
134
  f.flush
135
135
 
136
- out, status = run_ridgepole('--diff', "'#{JSON.dump(conn_spec)}'", f.path, '--enable-mysql-awesome', '--dump-without-table-options')
136
+ opts = ['--dump-without-table-options']
137
+ opts << '--enable-mysql-awesome' if condition(:mysql_awesome_enabled)
138
+ out, status = run_ridgepole('--diff', "'#{JSON.dump(conn_spec)}'", f.path, *opts)
137
139
 
138
140
  expect(out).to be_empty
139
141
  expect(status.success?).to be_truthy