ridgepole 0.7.0.alpha → 0.7.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +1 -0
- data/README.md +7 -5
- data/bin/ridgepole +14 -14
- data/lib/ridgepole/cli/config.rb +1 -1
- data/lib/ridgepole/client.rb +0 -4
- data/lib/ridgepole/delta.rb +15 -9
- data/lib/ridgepole/diff.rb +13 -9
- data/lib/ridgepole/dsl_parser/context.rb +2 -6
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +3 -1
- data/spec/erb_helper.rb +0 -39
- data/spec/hide_pending_formatter.rb +6 -0
- data/spec/mysql/bigint_pk/bigint_pk_spec.rb +9 -9
- data/spec/mysql/bigint_pk/int_pk_spec.rb +9 -9
- data/spec/mysql/cli/ridgepole_spec.rb +2 -2
- data/spec/mysql/collation/collation_spec.rb +28 -28
- data/spec/mysql/comment/comment_spec.rb +36 -36
- data/spec/mysql/default_lambda/default_lambda_spec.rb +1 -1
- data/spec/mysql/diff/diff2_spec.rb +41 -41
- data/spec/mysql/diff/diff_spec.rb +41 -41
- data/spec/mysql/dump/dump_class_method_spec.rb +26 -33
- data/spec/mysql/dump/dump_some_tables_spec.rb +16 -18
- data/spec/mysql/dump/dump_spec.rb +27 -34
- data/spec/mysql/dump/dump_without_table_options_spec.rb +5 -5
- data/spec/mysql/fk/migrate_change_fk_spec.rb +76 -23
- data/spec/mysql/fk/migrate_create_fk_spec.rb +70 -50
- data/spec/mysql/fk/migrate_drop_fk_spec.rb +131 -32
- data/spec/mysql/migrate/check_orphan_index_spec.rb +19 -19
- data/spec/mysql/migrate/migrate_add_column2_spec.rb +33 -45
- data/spec/mysql/migrate/migrate_add_column_order_spec.rb +47 -47
- data/spec/mysql/migrate/migrate_add_column_spec.rb +75 -89
- data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +72 -86
- data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +72 -86
- data/spec/mysql/migrate/migrate_change_column2_spec.rb +27 -32
- data/spec/mysql/migrate/migrate_change_column3_spec.rb +78 -78
- data/spec/mysql/migrate/migrate_change_column4_spec.rb +24 -24
- data/spec/mysql/migrate/migrate_change_column5_spec.rb +42 -42
- data/spec/mysql/migrate/migrate_change_column6_spec.rb +60 -60
- data/spec/mysql/migrate/migrate_change_column_default_spec.rb +47 -47
- data/spec/mysql/migrate/migrate_change_column_float_spec.rb +16 -16
- data/spec/mysql/migrate/migrate_change_column_spec.rb +65 -79
- data/spec/mysql/migrate/migrate_change_index2_spec.rb +22 -27
- data/spec/mysql/migrate/migrate_change_index3_spec.rb +52 -62
- data/spec/mysql/migrate/migrate_change_index4_spec.rb +32 -38
- data/spec/mysql/migrate/migrate_change_index5_spec.rb +24 -28
- data/spec/mysql/migrate/migrate_change_index6_spec.rb +105 -119
- data/spec/mysql/migrate/migrate_change_index7_spec.rb +27 -30
- data/spec/mysql/migrate/migrate_change_index_spec.rb +99 -120
- data/spec/mysql/migrate/migrate_change_table_option_spec.rb +14 -14
- data/spec/mysql/migrate/migrate_create_index2_spec.rb +101 -112
- data/spec/mysql/migrate/migrate_create_index_spec.rb +55 -66
- data/spec/mysql/migrate/migrate_create_table_spec.rb +68 -91
- data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +1 -1
- data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +58 -70
- data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +62 -76
- data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +58 -72
- data/spec/mysql/migrate/migrate_drop_column_spec.rb +63 -77
- data/spec/mysql/migrate/migrate_drop_index_spec.rb +55 -66
- data/spec/mysql/migrate/migrate_drop_table_spec.rb +51 -63
- data/spec/mysql/migrate/migrate_duplicate_index_spec.rb +3 -3
- data/spec/mysql/migrate/migrate_duplicate_table_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_empty_spec.rb +35 -42
- data/spec/mysql/migrate/migrate_execute_spec.rb +16 -24
- data/spec/mysql/migrate/migrate_log_file_spec.rb +58 -70
- data/spec/mysql/migrate/migrate_merge_mode_spec.rb +75 -99
- data/spec/mysql/migrate/migrate_noop_spec.rb +38 -38
- data/spec/mysql/migrate/migrate_rename_column_spec.rb +74 -88
- data/spec/mysql/migrate/migrate_rename_table_spec.rb +100 -97
- data/spec/mysql/migrate/migrate_same_default_null_spec.rb +18 -18
- data/spec/mysql/migrate/migrate_same_spec.rb +29 -37
- data/spec/mysql/migrate/migrate_script_error_spec.rb +19 -19
- data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +148 -0
- data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +70 -84
- data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +70 -84
- data/spec/mysql/migrate/migrate_with_ignore_tables_spec.rb +87 -87
- data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +61 -75
- data/spec/mysql/migrate/migrate_with_tables_spec.rb +41 -41
- data/spec/mysql/migrate/migrate_with_verbose_log_spec.rb +10 -10
- data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +67 -78
- data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +67 -78
- data/spec/mysql/text_blob_types/text_blob_types_spec.rb +9 -9
- data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +21 -24
- data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +35 -67
- data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +28 -34
- data/spec/postgresql/diff/diff_spec.rb +37 -37
- data/spec/postgresql/dump/dump_spec.rb +27 -34
- data/spec/postgresql/fk/migrate_change_fk_spec.rb +76 -23
- data/spec/postgresql/fk/migrate_create_fk_spec.rb +73 -54
- data/spec/postgresql/fk/migrate_drop_fk_spec.rb +131 -32
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +63 -75
- data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +1 -1
- data/spec/postgresql/migrate/migrate_change_column_default_spec.rb +7 -7
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +53 -65
- data/spec/postgresql/migrate/migrate_change_index_spec.rb +54 -68
- data/spec/postgresql/migrate/migrate_create_table_spec.rb +56 -77
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +46 -60
- data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +41 -55
- data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +3 -3
- data/spec/postgresql/migrate/migrate_drop_index_spec.rb +51 -62
- data/spec/postgresql/migrate/migrate_drop_table_spec.rb +48 -60
- data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +6 -6
- data/spec/postgresql/migrate/migrate_rename_column_spec.rb +54 -68
- data/spec/postgresql/migrate/migrate_rename_table_spec.rb +62 -78
- data/spec/postgresql/migrate/migrate_same_spec.rb +27 -34
- data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +21 -24
- data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +35 -66
- data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +28 -34
- data/spec/spec_helper.rb +1 -1
- metadata +9 -8
- data/ridgepole.iml +0 -9
- data/spec/string_ext.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 062b636d39f10f64c5fc0b450021c914121982bc
|
4
|
+
data.tar.gz: 7948f752d4a6165ce5b95926ed910c47b32587af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aeab93ec074378be562709f3984dee5716381c961aa04e845fe78646cc40ee47a1e57caaad5bed77fd11639c5d3d6ad4db4a7a5e1055e320906cb9d2168a9ea8
|
7
|
+
data.tar.gz: 9fabbad5e5158b4916d1772352ca735a82363a41f11eaadae7776e789644c844dbd87d5b48d8b036cfb9ceb5a08c9bb612171ce1e5af833d4424e7b79a0746a7
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -76,6 +76,9 @@ add_foreign_key :articles, :authors # without `name:`
|
|
76
76
|
* `>= 0.7.0`
|
77
77
|
* Remove Rails 4.x support
|
78
78
|
* Add Rails 5.1 support
|
79
|
+
* Remove `--enable-mysql-awesome` option
|
80
|
+
* Add `--skip-drop-table` option
|
81
|
+
* Support foreign key without name
|
79
82
|
|
80
83
|
## Installation
|
81
84
|
|
@@ -120,12 +123,12 @@ Usage: ridgepole [options]
|
|
120
123
|
--with-apply
|
121
124
|
-o, --output SCHEMAFILE
|
122
125
|
-t, --tables TABLES
|
123
|
-
--ignore-tables
|
124
|
-
--enable-mysql-awesome
|
126
|
+
--ignore-tables REGEX_LIST
|
125
127
|
--mysql-use-alter
|
126
128
|
--dump-without-table-options
|
127
129
|
--dump-with-default-fk-name
|
128
130
|
--index-removed-drop-column
|
131
|
+
--skip-drop-table
|
129
132
|
-r, --require LIBS
|
130
133
|
--log-file LOG_FILE
|
131
134
|
--verbose
|
@@ -358,9 +361,8 @@ Apply `Schemafile`
|
|
358
361
|
docker-compose up -d
|
359
362
|
bundle install
|
360
363
|
bundle exec appraisal install
|
361
|
-
bundle exec appraisal activerecord-
|
362
|
-
#
|
363
|
-
# POSTGRESQL=1 bundle exec appraisal activerecord-4.2 rake
|
364
|
+
bundle exec appraisal activerecord-5.1 rake
|
365
|
+
# POSTGRESQL=1 bundle exec appraisal activerecord-5.1 rake
|
364
366
|
```
|
365
367
|
|
366
368
|
**Notice:** mysql-client/postgresql-client is required.
|
data/bin/ridgepole
CHANGED
@@ -104,20 +104,20 @@ ARGV.options do |opt|
|
|
104
104
|
ARGV.shift
|
105
105
|
diff_files = [diff_arg1, diff_arg2]
|
106
106
|
}
|
107
|
-
opt.on('', '--reverse')
|
108
|
-
opt.on('', '--with-apply')
|
109
|
-
opt.on('-o', '--output SCHEMAFILE')
|
110
|
-
opt.on('-t', '--tables TABLES', Array)
|
111
|
-
opt.on('', '--ignore-tables
|
112
|
-
opt.on('', '--
|
113
|
-
opt.on('', '--
|
114
|
-
opt.on('', '--dump-
|
115
|
-
opt.on('', '--
|
116
|
-
opt.on('', '--
|
117
|
-
opt.on('-r', '--require LIBS', Array)
|
118
|
-
opt.on('' , '--log-file LOG_FILE')
|
119
|
-
opt.on('' , '--verbose')
|
120
|
-
opt.on('' , '--debug')
|
107
|
+
opt.on('', '--reverse') { options[:reverse] = true }
|
108
|
+
opt.on('', '--with-apply') { diff_with_apply = true }
|
109
|
+
opt.on('-o', '--output SCHEMAFILE') {|v| output_file = v }
|
110
|
+
opt.on('-t', '--tables TABLES', Array) {|v| options[:tables] = v }
|
111
|
+
opt.on('', '--ignore-tables REGEX_LIST', Array) {|v| options[:ignore_tables] = v.map {|i| Regexp.new(i) } }
|
112
|
+
opt.on('', '--mysql-use-alter') { options[:mysql_use_alter] = true }
|
113
|
+
opt.on('', '--dump-without-table-options') { options[:dump_without_table_options] = true }
|
114
|
+
opt.on('', '--dump-with-default-fk-name') { options[:dump_with_default_fk_name] = true }
|
115
|
+
opt.on('', '--index-removed-drop-column') { options[:index_removed_drop_column] = true }
|
116
|
+
opt.on('', '--skip-drop-table') { options[:skip_drop_table] = true }
|
117
|
+
opt.on('-r', '--require LIBS', Array) {|v| v.each {|i| require i } }
|
118
|
+
opt.on('' , '--log-file LOG_FILE') {|v| options[:log_file] = v }
|
119
|
+
opt.on('' , '--verbose') { Ridgepole::Logger.verbose = true }
|
120
|
+
opt.on('' , '--debug') { options[:debug] = true }
|
121
121
|
|
122
122
|
opt.on('-v', '--version') {
|
123
123
|
puts opt.ver
|
data/lib/ridgepole/cli/config.rb
CHANGED
@@ -33,7 +33,7 @@ class Ridgepole::Config
|
|
33
33
|
def parse_database_url(config)
|
34
34
|
uri = URI.parse(config)
|
35
35
|
|
36
|
-
if [uri.scheme, uri.user, uri.
|
36
|
+
if [uri.scheme, uri.user, uri.host, uri.path].any? {|i| i.nil? }
|
37
37
|
raise "Invalid config: #{config.inspect}"
|
38
38
|
end
|
39
39
|
|
data/lib/ridgepole/client.rb
CHANGED
@@ -14,10 +14,6 @@ class Ridgepole::Client
|
|
14
14
|
@parser = Ridgepole::DSLParser.new(@options)
|
15
15
|
@diff = Ridgepole::Diff.new(@options)
|
16
16
|
|
17
|
-
if @options[:enable_mysql_awesome]
|
18
|
-
require 'activerecord/mysql/awesome/base'
|
19
|
-
end
|
20
|
-
|
21
17
|
if @options[:mysql_use_alter]
|
22
18
|
require 'ridgepole/ext/abstract_mysql_adapter/use_alter_index'
|
23
19
|
end
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -244,8 +244,8 @@ end
|
|
244
244
|
end
|
245
245
|
|
246
246
|
unless (foreign_keys = attrs[:foreign_keys] || {}).empty?
|
247
|
-
foreign_keys.each do |
|
248
|
-
append_add_foreign_key(table_name,
|
247
|
+
foreign_keys.each do |_, foreign_key_attrs|
|
248
|
+
append_add_foreign_key(table_name, foreign_key_attrs, buf_for_fk, @options)
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
@@ -415,16 +415,16 @@ remove_index(#{table_name.inspect}, #{target.inspect})
|
|
415
415
|
end
|
416
416
|
|
417
417
|
def append_change_foreign_keys(table_name, delta, buf, options)
|
418
|
-
(delta[:delete] || {}).each do |
|
419
|
-
append_remove_foreign_key(table_name,
|
418
|
+
(delta[:delete] || {}).each do |_, attrs|
|
419
|
+
append_remove_foreign_key(table_name, attrs, buf, options)
|
420
420
|
end
|
421
421
|
|
422
|
-
(delta[:add] || {}).each do |
|
423
|
-
append_add_foreign_key(table_name,
|
422
|
+
(delta[:add] || {}).each do |_, attrs|
|
423
|
+
append_add_foreign_key(table_name, attrs, buf, options)
|
424
424
|
end
|
425
425
|
end
|
426
426
|
|
427
|
-
def append_add_foreign_key(table_name,
|
427
|
+
def append_add_foreign_key(table_name, attrs, buf, options)
|
428
428
|
to_table = attrs.fetch(:to_table)
|
429
429
|
attrs_options = attrs[:options] || {}
|
430
430
|
|
@@ -433,9 +433,15 @@ add_foreign_key(#{table_name.inspect}, #{to_table.inspect}, #{attrs_options.insp
|
|
433
433
|
EOS
|
434
434
|
end
|
435
435
|
|
436
|
-
def append_remove_foreign_key(table_name,
|
436
|
+
def append_remove_foreign_key(table_name, attrs, buf, options)
|
437
437
|
attrs_options = attrs[:options] || {}
|
438
|
-
|
438
|
+
fk_name = attrs_options[:name]
|
439
|
+
|
440
|
+
if fk_name
|
441
|
+
target = {:name => fk_name}
|
442
|
+
else
|
443
|
+
target = attrs.fetch(:to_table)
|
444
|
+
end
|
439
445
|
|
440
446
|
buf.puts(<<-EOS)
|
441
447
|
remove_foreign_key(#{table_name.inspect}, #{target.inspect})
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -34,7 +34,7 @@ class Ridgepole::Diff
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
unless @options[:merge]
|
37
|
+
unless @options[:merge] or @options[:skip_drop_table]
|
38
38
|
from.each do |table_name, from_attrs|
|
39
39
|
next unless target?(table_name)
|
40
40
|
|
@@ -55,6 +55,8 @@ class Ridgepole::Diff
|
|
55
55
|
next unless target?(table_name)
|
56
56
|
|
57
57
|
if (from_table_name = (to_attrs[:options] || {}).delete(:renamed_from))
|
58
|
+
from_table_name = from_table_name.to_s if from_table_name
|
59
|
+
|
58
60
|
# Already renamed
|
59
61
|
next if from[table_name]
|
60
62
|
|
@@ -195,6 +197,8 @@ class Ridgepole::Diff
|
|
195
197
|
def scan_column_rename(from, to, definition_delta)
|
196
198
|
to.dup.each do |column_name, to_attrs|
|
197
199
|
if (from_column_name = (to_attrs[:options] || {}).delete(:renamed_from))
|
200
|
+
from_column_name = from_column_name.to_s if from_column_name
|
201
|
+
|
198
202
|
# Already renamed
|
199
203
|
next if from[column_name]
|
200
204
|
|
@@ -291,7 +295,7 @@ class Ridgepole::Diff
|
|
291
295
|
opts[:default] = nil
|
292
296
|
end
|
293
297
|
|
294
|
-
if
|
298
|
+
if Ridgepole::ConnectionAdapters.mysql?
|
295
299
|
opts[:unsigned] = false unless opts.has_key?(:unsigned)
|
296
300
|
end
|
297
301
|
end
|
@@ -319,29 +323,29 @@ class Ridgepole::Diff
|
|
319
323
|
to = (to || {}).dup
|
320
324
|
foreign_keys_delta = {}
|
321
325
|
|
322
|
-
to.each do |
|
323
|
-
from_attrs = from.delete(
|
326
|
+
to.each do |foreign_key_name_or_tables, to_attrs|
|
327
|
+
from_attrs = from.delete(foreign_key_name_or_tables)
|
324
328
|
|
325
329
|
if from_attrs
|
326
330
|
if from_attrs != to_attrs
|
327
331
|
foreign_keys_delta[:add] ||= {}
|
328
|
-
foreign_keys_delta[:add][
|
332
|
+
foreign_keys_delta[:add][foreign_key_name_or_tables] = to_attrs
|
329
333
|
|
330
334
|
unless options[:merge]
|
331
335
|
foreign_keys_delta[:delete] ||= {}
|
332
|
-
foreign_keys_delta[:delete][
|
336
|
+
foreign_keys_delta[:delete][foreign_key_name_or_tables] = from_attrs
|
333
337
|
end
|
334
338
|
end
|
335
339
|
else
|
336
340
|
foreign_keys_delta[:add] ||= {}
|
337
|
-
foreign_keys_delta[:add][
|
341
|
+
foreign_keys_delta[:add][foreign_key_name_or_tables] = to_attrs
|
338
342
|
end
|
339
343
|
end
|
340
344
|
|
341
345
|
unless options[:merge]
|
342
|
-
from.each do |
|
346
|
+
from.each do |foreign_key_name_or_tables, from_attrs|
|
343
347
|
foreign_keys_delta[:delete] ||= {}
|
344
|
-
foreign_keys_delta[:delete][
|
348
|
+
foreign_keys_delta[:delete][foreign_key_name_or_tables] = from_attrs
|
345
349
|
end
|
346
350
|
end
|
347
351
|
|
@@ -75,16 +75,12 @@ class Ridgepole::DSLParser
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def add_foreign_key(from_table, to_table, options = {})
|
78
|
-
unless options[:name]
|
79
|
-
raise "Foreign key name in `#{from_table}` is undefined"
|
80
|
-
end
|
81
|
-
|
82
78
|
from_table = from_table.to_s
|
83
79
|
to_table = to_table.to_s
|
84
|
-
options[:name] = options[:name].to_s
|
80
|
+
options[:name] = options[:name].to_s if options[:name]
|
85
81
|
@__definition[from_table] ||= {}
|
86
82
|
@__definition[from_table][:foreign_keys] ||= {}
|
87
|
-
idx = options[:name]
|
83
|
+
idx = options[:name] || [from_table, to_table]
|
88
84
|
|
89
85
|
if @__definition[from_table][:foreign_keys][idx]
|
90
86
|
raise "Foreign Key `#{from_table}(#{idx})` already defined"
|
data/lib/ridgepole/version.rb
CHANGED
data/ridgepole.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.2.7')
|
22
|
+
|
21
23
|
spec.add_dependency 'activerecord', '>= 5.0.1', '< 6'
|
22
24
|
spec.add_dependency 'diffy'
|
23
25
|
spec.add_development_dependency 'bundler'
|
@@ -26,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
26
28
|
spec.add_development_dependency 'mysql2', '~> 0.3.20'
|
27
29
|
spec.add_development_dependency 'pg'
|
28
30
|
spec.add_development_dependency 'coveralls'
|
29
|
-
spec.add_development_dependency 'appraisal'
|
31
|
+
spec.add_development_dependency 'appraisal', '>= 2.2.0'
|
30
32
|
spec.add_development_dependency 'rspec-match_fuzzy', '>= 0.1.3'
|
31
33
|
spec.add_development_dependency 'erbh', '>= 0.1.2'
|
32
34
|
spec.add_development_dependency 'hash_modern_inspect', '>= 0.1.1'
|
data/spec/erb_helper.rb
CHANGED
@@ -9,45 +9,6 @@ ERBh.define_method(:i) do |obj|
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
ERBh.define_method(:add_index) do |table_name, column_name, options|
|
13
|
-
if options[:length].is_a?(Hash)
|
14
|
-
options[:length] = options[:length].symbolize_keys
|
15
|
-
end
|
16
|
-
|
17
|
-
@_erbout.sub!(/\bend\s*\z/, '')
|
18
|
-
|
19
|
-
# XXX:
|
20
|
-
if not condition('5.0') and options[:using] == :btree
|
21
|
-
options.delete(:using)
|
22
|
-
end
|
23
|
-
|
24
|
-
# XXX:
|
25
|
-
if options.has_key?(:force_using)
|
26
|
-
options[:using] = options.delete(:force_using)
|
27
|
-
end
|
28
|
-
|
29
|
-
<<-EOS
|
30
|
-
t.index #{column_name.inspect}, #{options.modern_inspect_without_brace}
|
31
|
-
end
|
32
|
-
EOS
|
33
|
-
end
|
34
|
-
|
35
|
-
ERBh.define_method(:unsigned) do |value, *conds|
|
36
|
-
if condition(*conds)
|
37
|
-
{unsigned: value}
|
38
|
-
else
|
39
|
-
{}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
ERBh.define_method(:limit) do |value, *conds|
|
44
|
-
if condition(*conds)
|
45
|
-
{limit: value}
|
46
|
-
else
|
47
|
-
{}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
12
|
ERBh.define_method(:cond) do |conds, m, e = nil|
|
52
13
|
if condition(*Array(conds))
|
53
14
|
m
|
@@ -1,24 +1,24 @@
|
|
1
|
-
describe 'Ridgepole::Client (with bigint pk)', condition:
|
1
|
+
describe 'Ridgepole::Client (with bigint pk)', condition: 5.0 do
|
2
2
|
let(:id_primary_key_create_table) {
|
3
|
-
<<-
|
3
|
+
<<-EOS
|
4
4
|
create_table "books", id: :primary_key, limit: 8, force: :cascade do |t|
|
5
|
-
t.string "title",
|
6
|
-
t.integer "author_id",
|
5
|
+
t.string "title", null: false
|
6
|
+
t.integer "author_id", 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(:id_bigint_create_table) {
|
14
|
-
<<-
|
14
|
+
<<-EOS
|
15
15
|
create_table "books", id: :bigint, force: :cascade do |t|
|
16
|
-
t.string "title",
|
17
|
-
t.integer "author_id",
|
16
|
+
t.string "title", null: false
|
17
|
+
t.integer "author_id", 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,14 +1,14 @@
|
|
1
|
-
describe 'Ridgepole::Client (with integer pk)', condition:
|
1
|
+
describe 'Ridgepole::Client (with integer pk)', condition: 5.1 do
|
2
2
|
context 'when with id:integer' do
|
3
3
|
let(:dsl) {
|
4
|
-
<<-
|
4
|
+
<<-EOS
|
5
5
|
create_table "books", id: :integer, force: :cascade do |t|
|
6
|
-
t.string "title",
|
7
|
-
t.integer "author_id",
|
6
|
+
t.string "title", null: false
|
7
|
+
t.integer "author_id", null: false
|
8
8
|
t.datetime "created_at"
|
9
9
|
t.datetime "updated_at"
|
10
10
|
end
|
11
|
-
|
11
|
+
EOS
|
12
12
|
}
|
13
13
|
|
14
14
|
subject { client }
|
@@ -23,14 +23,14 @@ describe 'Ridgepole::Client (with integer pk)', condition: '5.1.' do
|
|
23
23
|
|
24
24
|
context 'when without id:integer' do
|
25
25
|
let(:dsl) {
|
26
|
-
<<-
|
26
|
+
<<-EOS
|
27
27
|
create_table "books", force: :cascade do |t|
|
28
|
-
t.string "title",
|
29
|
-
t.integer "author_id",
|
28
|
+
t.string "title", null: false
|
29
|
+
t.integer "author_id", null: false
|
30
30
|
t.datetime "created_at"
|
31
31
|
t.datetime "updated_at"
|
32
32
|
end
|
33
|
-
|
33
|
+
EOS
|
34
34
|
}
|
35
35
|
|
36
36
|
subject { client }
|
@@ -39,12 +39,12 @@ describe 'ridgepole' do
|
|
39
39
|
--with-apply
|
40
40
|
-o, --output SCHEMAFILE
|
41
41
|
-t, --tables TABLES
|
42
|
-
--ignore-tables
|
43
|
-
--enable-mysql-awesome
|
42
|
+
--ignore-tables REGEX_LIST
|
44
43
|
--mysql-use-alter
|
45
44
|
--dump-without-table-options
|
46
45
|
--dump-with-default-fk-name
|
47
46
|
--index-removed-drop-column
|
47
|
+
--skip-drop-table
|
48
48
|
-r, --require LIBS
|
49
49
|
--log-file LOG_FILE
|
50
50
|
--verbose
|
@@ -2,22 +2,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
2
2
|
context 'when change column (add collation)' do
|
3
3
|
let(:actual_dsl) {
|
4
4
|
erbh(<<-EOS)
|
5
|
-
create_table "employee_clubs", <%= i cond(
|
6
|
-
t.integer "emp_no",
|
5
|
+
create_table "employee_clubs", <%= i cond(5.1, id: :bigint) %>, unsigned: true, force: :cascade do |t|
|
6
|
+
t.integer "emp_no", null: false
|
7
7
|
t.integer "club_id", null: false, unsigned: true
|
8
|
-
t.string "string",
|
9
|
-
t.text "text",
|
8
|
+
t.string "string", null: false, collation: "ascii_bin"
|
9
|
+
t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false
|
10
10
|
end
|
11
11
|
EOS
|
12
12
|
}
|
13
13
|
|
14
14
|
let(:expected_dsl) {
|
15
15
|
erbh(<<-EOS)
|
16
|
-
create_table "employee_clubs", <%= i cond(
|
17
|
-
t.integer "emp_no",
|
16
|
+
create_table "employee_clubs", <%= i cond(5.1, id: :bigint) %>, unsigned: true, force: :cascade do |t|
|
17
|
+
t.integer "emp_no", null: false
|
18
18
|
t.integer "club_id", null: false, unsigned: true
|
19
|
-
t.string "string",
|
20
|
-
t.text "text",
|
19
|
+
t.string "string", null: false, collation: "ascii_bin"
|
20
|
+
t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false, collation: "utf8mb4_bin"
|
21
21
|
end
|
22
22
|
EOS
|
23
23
|
}
|
@@ -37,22 +37,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
37
37
|
context 'when change column (delete collation)' do
|
38
38
|
let(:actual_dsl) {
|
39
39
|
erbh(<<-EOS)
|
40
|
-
create_table "employee_clubs", <%= i cond(
|
41
|
-
t.integer "emp_no",
|
40
|
+
create_table "employee_clubs", <%= i cond(5.1, id: :bigint) %>, unsigned: true, force: :cascade do |t|
|
41
|
+
t.integer "emp_no", null: false
|
42
42
|
t.integer "club_id", null: false, unsigned: true
|
43
|
-
t.string "string",
|
44
|
-
t.text "text",
|
43
|
+
t.string "string", null: false, collation: "ascii_bin"
|
44
|
+
t.text "text", <%= i cond(5.0, 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
|
-
create_table "employee_clubs", <%= i cond(
|
52
|
-
t.integer "emp_no",
|
51
|
+
create_table "employee_clubs", <%= i cond(5.1, id: :bigint) %>, unsigned: true, force: :cascade do |t|
|
52
|
+
t.integer "emp_no", null: false
|
53
53
|
t.integer "club_id", null: false, unsigned: true
|
54
|
-
t.string "string",
|
55
|
-
t.text "text",
|
54
|
+
t.string "string", null: false, collation: "ascii_bin"
|
55
|
+
t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false
|
56
56
|
end
|
57
57
|
EOS
|
58
58
|
}
|
@@ -72,22 +72,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
72
72
|
context 'when change column (change collation)' do
|
73
73
|
let(:actual_dsl) {
|
74
74
|
erbh(<<-EOS)
|
75
|
-
create_table "employee_clubs", <%= i cond(
|
76
|
-
t.integer "emp_no",
|
75
|
+
create_table "employee_clubs", <%= i cond(5.1, id: :bigint) %>, unsigned: true, force: :cascade do |t|
|
76
|
+
t.integer "emp_no", null: false
|
77
77
|
t.integer "club_id", null: false, unsigned: true
|
78
|
-
t.string "string",
|
79
|
-
t.text "text",
|
78
|
+
t.string "string", null: false, collation: "ascii_bin"
|
79
|
+
t.text "text", <%= i cond(5.0, 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
|
-
create_table "employee_clubs", <%= i cond(
|
87
|
-
t.integer "emp_no",
|
86
|
+
create_table "employee_clubs", <%= i cond(5.1, id: :bigint) %>, unsigned: true, force: :cascade do |t|
|
87
|
+
t.integer "emp_no", null: false
|
88
88
|
t.integer "club_id", null: false, unsigned: true
|
89
|
-
t.string "string",
|
90
|
-
t.text "text",
|
89
|
+
t.string "string", null: false, collation: "utf8mb4_bin"
|
90
|
+
t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false, collation: "ascii_bin"
|
91
91
|
end
|
92
92
|
EOS
|
93
93
|
}
|
@@ -107,11 +107,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
107
107
|
context 'when change column (no change collation)' do
|
108
108
|
let(:actual_dsl) {
|
109
109
|
erbh(<<-EOS)
|
110
|
-
create_table "employee_clubs", <%= i cond(
|
111
|
-
t.integer "emp_no",
|
110
|
+
create_table "employee_clubs", <%= i cond(5.1, id: :bigint) %>, unsigned: true, force: :cascade do |t|
|
111
|
+
t.integer "emp_no", null: false
|
112
112
|
t.integer "club_id", null: false, unsigned: true
|
113
|
-
t.string "string",
|
114
|
-
t.text "text",
|
113
|
+
t.string "string", null: false, collation: "ascii_bin"
|
114
|
+
t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false, collation: "utf8mb4_bin"
|
115
115
|
end
|
116
116
|
EOS
|
117
117
|
}
|