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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/Appraisals +1 -1
- data/README.md +3 -1
- data/gemfiles/activerecord_5.0.gemfile +1 -1
- data/lib/ridgepole/client.rb +5 -1
- data/lib/ridgepole/delta.rb +21 -5
- data/lib/ridgepole/diff.rb +13 -2
- data/lib/ridgepole/dsl_parser.rb +38 -3
- data/lib/ridgepole/dumper.rb +2 -2
- data/lib/ridgepole/ext/abstract_mysql_adapter/disable_table_options.rb +21 -0
- data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +28 -0
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +3 -3
- data/spec/erb_helper.rb +43 -0
- data/spec/mysql/bigint_pk/bigint_pk_spec.rb +9 -9
- data/spec/mysql/collation/collation_spec.rb +39 -37
- data/spec/mysql/default_lambda/default_lambda_spec.rb +162 -0
- data/spec/mysql/diff/diff2_spec.rb +10 -10
- data/spec/mysql/diff/diff_spec.rb +6 -6
- data/spec/mysql/dump/dump_class_method_spec.rb +56 -39
- data/spec/mysql/dump/dump_some_tables_spec.rb +21 -13
- data/spec/mysql/dump/dump_spec.rb +49 -36
- data/spec/mysql/dump/dump_without_table_options_spec.rb +27 -9
- data/spec/mysql/fk/migrate_change_fk_spec.rb +17 -11
- data/spec/mysql/fk/migrate_create_fk_spec.rb +20 -18
- data/spec/mysql/fk/migrate_drop_fk_spec.rb +30 -16
- data/spec/mysql/migrate/migrate_add_column2_spec.rb +10 -8
- data/spec/mysql/migrate/migrate_add_column_spec.rb +49 -61
- data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +46 -58
- data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +46 -58
- data/spec/mysql/migrate/migrate_change_column2_spec.rb +12 -24
- data/spec/mysql/migrate/migrate_change_column3_spec.rb +18 -30
- data/spec/mysql/migrate/migrate_change_column5_spec.rb +8 -20
- data/spec/mysql/migrate/migrate_change_column6_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_change_column_default_spec.rb +20 -20
- data/spec/mysql/migrate/migrate_change_column_float_spec.rb +2 -2
- data/spec/mysql/migrate/migrate_change_column_spec.rb +54 -68
- data/spec/mysql/migrate/migrate_change_index2_spec.rb +14 -14
- data/spec/mysql/migrate/migrate_change_index3_spec.rb +28 -28
- data/spec/mysql/migrate/migrate_change_index4_spec.rb +26 -38
- data/spec/mysql/migrate/migrate_change_index5_spec.rb +20 -32
- data/spec/mysql/migrate/migrate_change_index6_spec.rb +63 -75
- data/spec/mysql/migrate/migrate_change_index_spec.rb +62 -74
- data/spec/mysql/migrate/migrate_change_table_option_spec.rb +8 -20
- data/spec/mysql/migrate/migrate_create_index2_spec.rb +98 -53
- data/spec/mysql/migrate/migrate_create_index_spec.rb +84 -39
- data/spec/mysql/migrate/migrate_create_table_spec.rb +69 -39
- data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +69 -39
- data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +47 -59
- data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +43 -55
- data/spec/mysql/migrate/migrate_drop_column_spec.rb +48 -60
- data/spec/mysql/migrate/migrate_drop_index_spec.rb +84 -39
- data/spec/mysql/migrate/migrate_drop_table_spec.rb +76 -46
- data/spec/mysql/migrate/migrate_empty_spec.rb +24 -36
- data/spec/mysql/migrate/migrate_execute_spec.rb +30 -32
- data/spec/mysql/migrate/migrate_log_file_spec.rb +69 -39
- data/spec/mysql/migrate/migrate_merge_mode_spec.rb +48 -48
- data/spec/mysql/migrate/migrate_noop_spec.rb +23 -13
- data/spec/mysql/migrate/migrate_rename_column_spec.rb +48 -60
- data/spec/mysql/migrate/migrate_rename_table_spec.rb +56 -68
- data/spec/mysql/migrate/migrate_same_default_null_spec.rb +8 -20
- data/spec/mysql/migrate/migrate_same_spec.rb +49 -31
- data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +48 -60
- data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +48 -60
- data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +34 -34
- data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +84 -39
- data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +84 -39
- data/spec/mysql/text_blob_types/text_blob_types_spec.rb +84 -0
- data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +14 -8
- data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +15 -27
- data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +10 -10
- data/spec/postgresql/dump/dump_spec.rb +40 -16
- data/spec/postgresql/fk/migrate_change_fk_spec.rb +6 -6
- data/spec/postgresql/fk/migrate_create_fk_spec.rb +11 -11
- data/spec/postgresql/fk/migrate_drop_fk_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +20 -20
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +20 -20
- data/spec/postgresql/migrate/migrate_change_index_spec.rb +20 -20
- data/spec/postgresql/migrate/migrate_create_table_spec.rb +52 -12
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +20 -20
- data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +18 -18
- data/spec/postgresql/migrate/migrate_drop_index_spec.rb +69 -13
- data/spec/postgresql/migrate/migrate_drop_table_spec.rb +55 -13
- data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +3 -1
- data/spec/postgresql/migrate/migrate_rename_column_spec.rb +20 -20
- data/spec/postgresql/migrate/migrate_rename_table_spec.rb +24 -24
- data/spec/postgresql/migrate/migrate_same_spec.rb +40 -16
- data/spec/postgresql/ridgepole_test_tables.sql +3 -0
- data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +6 -6
- data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +11 -11
- data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +8 -8
- data/spec/spec_condition.rb +14 -2
- data/spec/spec_helper.rb +12 -11
- data/spec/string_ext.rb +2 -0
- metadata +16 -9
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5175eaaaf37dc9607941847db6b26fc41ded724a
|
4
|
+
data.tar.gz: 5091e1b556002310437ea3f6982b89e51ca37e74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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
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
|
|
data/lib/ridgepole/client.rb
CHANGED
@@ -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)
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
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
|
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
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -114,7 +114,7 @@ class Ridgepole::Diff
|
|
114
114
|
normalize_column_options!(from_attrs)
|
115
115
|
normalize_column_options!(to_attrs)
|
116
116
|
|
117
|
-
|
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
|
data/lib/ridgepole/dsl_parser.rb
CHANGED
@@ -19,7 +19,7 @@ class Ridgepole::DSLParser
|
|
19
19
|
end
|
20
20
|
|
21
21
|
TYPES = [
|
22
|
-
# https://github.com/
|
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/
|
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
|
data/lib/ridgepole/dumper.rb
CHANGED
@@ -10,14 +10,14 @@ class Ridgepole::Dumper
|
|
10
10
|
ignore_tables = @options[:ignore_tables]
|
11
11
|
|
12
12
|
if target_tables
|
13
|
-
conn.
|
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.
|
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
|
data/lib/ridgepole/version.rb
CHANGED
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.
|
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.
|
32
|
+
spec.add_development_dependency 'hash_order_helper', '>= 0.1.5'
|
33
33
|
end
|
data/spec/erb_helper.rb
ADDED
@@ -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
|
-
<<-
|
3
|
+
erbh(<<-EOS)
|
4
4
|
create_table "books", id: :primary_key, limit: 8, force: :cascade do |t|
|
5
|
-
t.string "title", limit
|
6
|
-
t.integer "author_id", limit
|
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
|
-
|
10
|
+
EOS
|
11
11
|
}
|
12
12
|
|
13
13
|
let(:dsl2) {
|
14
|
-
<<-
|
14
|
+
erbh(<<-EOS)
|
15
15
|
create_table "books", id: :bigint, force: :cascade do |t|
|
16
|
-
t.string "title", limit
|
17
|
-
t.integer "author_id", limit
|
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
|
-
|
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
|
-
<<-
|
4
|
+
erbh(<<-EOS)
|
5
5
|
create_table "employee_clubs", unsigned: true, force: :cascade do |t|
|
6
|
-
t.integer "emp_no", limit
|
7
|
-
t.integer "club_id", limit
|
8
|
-
t.string "string", limit:
|
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
|
-
|
11
|
+
EOS
|
12
12
|
}
|
13
13
|
|
14
14
|
let(:expected_dsl) {
|
15
|
-
<<-
|
15
|
+
erbh(<<-EOS)
|
16
16
|
create_table "employee_clubs", unsigned: true, force: :cascade do |t|
|
17
|
-
t.integer "emp_no", limit
|
18
|
-
t.integer "club_id", limit
|
19
|
-
t.string "string", limit
|
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
|
-
|
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
|
-
<<-
|
39
|
+
erbh(<<-EOS)
|
40
40
|
create_table "employee_clubs", unsigned: true, force: :cascade do |t|
|
41
|
-
t.integer "emp_no", limit
|
42
|
-
t.integer "club_id", limit
|
43
|
-
t.string "string", limit
|
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
|
-
|
46
|
+
EOS
|
47
47
|
}
|
48
48
|
|
49
49
|
let(:expected_dsl) {
|
50
|
-
<<-
|
50
|
+
erbh(<<-EOS)
|
51
51
|
create_table "employee_clubs", unsigned: true, force: :cascade do |t|
|
52
|
-
t.integer "emp_no", limit
|
53
|
-
t.integer "club_id", limit
|
54
|
-
t.string "string", limit:
|
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
|
-
|
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
|
-
<<-
|
74
|
+
erbh(<<-EOS)
|
75
75
|
create_table "employee_clubs", unsigned: true, force: :cascade do |t|
|
76
|
-
t.integer "emp_no", limit
|
77
|
-
t.integer "club_id", limit
|
78
|
-
t.string "string", limit
|
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
|
-
|
81
|
+
EOS
|
82
82
|
}
|
83
83
|
|
84
84
|
let(:expected_dsl) {
|
85
|
-
<<-
|
85
|
+
erbh(<<-EOS)
|
86
86
|
create_table "employee_clubs", unsigned: true, force: :cascade do |t|
|
87
|
-
t.integer "emp_no", limit
|
88
|
-
t.integer "club_id", limit
|
89
|
-
t.string "string", limit
|
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
|
-
|
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
|
-
<<-
|
109
|
+
erbh(<<-EOS)
|
110
110
|
create_table "employee_clubs", unsigned: true, force: :cascade do |t|
|
111
|
-
t.integer "emp_no", limit
|
112
|
-
t.integer "club_id", limit
|
113
|
-
t.string "string", limit
|
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
|
-
|
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
|
-
|
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
|