ridgepole 0.7.1.beta4 → 0.7.1.beta5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 573f4b844c5ea5951efd6c7a5807300a79545121
4
- data.tar.gz: f94d8891b7acc9b42106bd2ccd7e08f8771f922a
3
+ metadata.gz: b663d82d153001757f0f7ea0437fc4ca478968c5
4
+ data.tar.gz: 8d0280aea682ea7aa618814305dc6a6a095765a9
5
5
  SHA512:
6
- metadata.gz: d5f191e59ef592721209cc97a4f1d019297d5d6d042e9f504665c365d35a3a55cbb4480fc6345966dc227fb35229e9012fbe866beb3e4641944d6d82f675b3f9
7
- data.tar.gz: 693ab38c2cb409e988311872ee9e7586b10d834a654077d98b235c7cb8f10b8339a05cf7e8036dc7518ab8ae176d7555841ead84d61d59613fbddc088d4cbd74
6
+ metadata.gz: b372feddfa461f7eae624ce7167323de0ce1d4aa6f5f797737603d02df15e7caae0dcab2af372823fbddbe5bb017f0da43ce1c4b874a207f0fa3cf00710c1c1c
7
+ data.tar.gz: 92e8c615746f466c4a557ef05c5ff7935180277f1fcae0ead01de4b485bb89718adc226a88a087fab3d3afdb4d476ad05a282c0e8b5ad46835a8c8e81d575791
data/README.md CHANGED
@@ -83,6 +83,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
83
83
  * Remove `--reverse` option
84
84
  * Add `--allow-pk-change` option
85
85
  * Add `--create-table-with-index` option
86
+ * Add `--mysql-dump-auto-increment` option (`rails >= 5.1`)
86
87
 
87
88
  ## Installation
88
89
 
@@ -137,6 +138,8 @@ Usage: ridgepole [options]
137
138
  --check-relation-type DEF_PK
138
139
  --ignore-table-comment
139
140
  --skip-column-comment-change
141
+ --create-table-with-index
142
+ --mysql-dump-auto-increment
140
143
  -r, --require LIBS
141
144
  --log-file LOG_FILE
142
145
  --verbose
@@ -126,6 +126,15 @@ ARGV.options do |opt|
126
126
  opt.on('', '--skip-column-comment-change') { options[:skip_column_comment_change] = true }
127
127
  opt.on('', '--allow-pk-change') { options[:allow_pk_change] = true }
128
128
  opt.on('', '--create-table-with-index') { options[:create_table_with_index] = true }
129
+
130
+ opt.on('', '--mysql-dump-auto-increment') {
131
+ if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('5.1')
132
+ raise OptionParser::InvalidOption, '`mysql-dump-auto-increment` is not available in `activerecord < 5.1`'
133
+ end
134
+
135
+ options[:mysql_dump_auto_increment] = true
136
+ }
137
+
129
138
  opt.on('-r', '--require LIBS', Array) {|v| v.each {|i| require i } }
130
139
  opt.on('' , '--log-file LOG_FILE') {|v| options[:log_file] = v }
131
140
  opt.on('' , '--verbose') { Ridgepole::Logger.verbose = true }
@@ -17,6 +17,10 @@ class Ridgepole::Client
17
17
  if @options[:mysql_use_alter]
18
18
  require 'ridgepole/ext/abstract_mysql_adapter/use_alter_index'
19
19
  end
20
+
21
+ if @options[:mysql_dump_auto_increment]
22
+ require 'ridgepole/ext/abstract_mysql_adapter/dump_auto_increment'
23
+ end
20
24
  end
21
25
 
22
26
  def dump(&block)
@@ -0,0 +1,23 @@
1
+ require 'active_record/connection_adapters/abstract_mysql_adapter'
2
+
3
+ module Ridgepole
4
+ module Ext
5
+ module AbstractMysqlAdapter
6
+ module DumpAutoIncrement
7
+ def prepare_column_options(column)
8
+ spec = super
9
+ spec[:auto_increment] = "true" if column.auto_increment?
10
+ spec
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ module ActiveRecord
18
+ module ConnectionAdapters
19
+ class AbstractMysqlAdapter
20
+ prepend Ridgepole::Ext::AbstractMysqlAdapter::DumpAutoIncrement
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.7.1.beta4'
2
+ VERSION = '0.7.1.beta5'
3
3
  end
@@ -51,6 +51,7 @@ describe 'ridgepole' do
51
51
  --skip-column-comment-change
52
52
  --allow-pk-change
53
53
  --create-table-with-index
54
+ --mysql-dump-auto-increment
54
55
  -r, --require LIBS
55
56
  --log-file LOG_FILE
56
57
  --verbose
@@ -0,0 +1,41 @@
1
+ describe 'Ridgepole::Client#diff -> migrate (with index)' do
2
+ context 'when create table' do
3
+ let(:actual_dsl) { '' }
4
+
5
+ let(:expected_dsl) {
6
+ erbh(<<-EOS)
7
+ create_table "dept_emp", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
8
+ t.integer "emp_no", null: false
9
+ t.string "dept_no", null: false
10
+ t.date "from_date", null: false
11
+ t.date "to_date", null: false
12
+ t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
13
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
14
+ end
15
+ EOS
16
+ }
17
+
18
+ before { subject.diff(actual_dsl).migrate }
19
+ subject { client(create_table_with_index: true) }
20
+
21
+ it {
22
+ delta = subject.diff(expected_dsl)
23
+ expect(delta.differ?).to be_truthy
24
+
25
+ expect(delta.script).to match_fuzzy erbh(<<-EOS)
26
+ create_table("dept_emp", {:primary_key=>["emp_no", "dept_no"]}) do |t|
27
+ t.column("emp_no", :"integer", {:null=>false, :limit=>4})
28
+ t.column("dept_no", :"string", {:null=>false, :limit=>255})
29
+ t.column("from_date", :"date", {:null=>false})
30
+ t.column("to_date", :"date", {:null=>false})
31
+ t.index(["dept_no"], <%= {:name=>"dept_no"} + cond(5.0, using: :btree) %>)
32
+ t.index(["emp_no"], <%= {:name=>"emp_no"} + cond(5.0, using: :btree) %>)
33
+ end
34
+ EOS
35
+
36
+ expect(subject.dump).to match_fuzzy actual_dsl
37
+ delta.migrate
38
+ expect(subject.dump).to match_fuzzy expected_dsl
39
+ }
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ describe 'Ridgepole::Client#diff -> migrate (with index)', condition: 5.1 do
2
+ context 'when create table with auto increment column' do
3
+ let(:actual_dsl) { '' }
4
+
5
+ let(:expected_dsl) {
6
+ erbh(<<-EOS)
7
+ create_table "dept_emp", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
8
+ t.integer "emp_no", null: false
9
+ t.integer "dept_no", null: false, auto_increment: true
10
+ t.date "from_date", null: false
11
+ t.date "to_date", null: false
12
+ t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
13
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
14
+ end
15
+ EOS
16
+ }
17
+
18
+ before { subject.diff(actual_dsl).migrate }
19
+ subject { client(create_table_with_index: true, mysql_dump_auto_increment: true) }
20
+
21
+ it {
22
+ delta = subject.diff(expected_dsl)
23
+ expect(delta.differ?).to be_truthy
24
+
25
+ expect(delta.script).to match_fuzzy erbh(<<-EOS)
26
+ create_table("dept_emp", {:primary_key=>["emp_no", "dept_no"]}) do |t|
27
+ t.column("emp_no", :"integer", {:null=>false, :limit=>4})
28
+ t.column("dept_no", :"integer", {:null=>false, :auto_increment=>true, :limit=>4})
29
+ t.column("from_date", :"date", {:null=>false})
30
+ t.column("to_date", :"date", {:null=>false})
31
+ t.index(["dept_no"], <%= {:name=>"dept_no"} + cond(5.0, using: :btree) %>)
32
+ t.index(["emp_no"], <%= {:name=>"emp_no"} + cond(5.0, using: :btree) %>)
33
+ end
34
+ EOS
35
+
36
+ expect(subject.dump).to match_fuzzy actual_dsl
37
+ delta.migrate
38
+ expect(subject.dump).to match_fuzzy expected_dsl
39
+ }
40
+ end
41
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1.beta4
4
+ version: 0.7.1.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -232,6 +232,7 @@ files:
232
232
  - lib/ridgepole/dumper.rb
233
233
  - lib/ridgepole/execute_expander.rb
234
234
  - lib/ridgepole/ext/abstract_adapter/disable_table_options.rb
235
+ - lib/ridgepole/ext/abstract_mysql_adapter/dump_auto_increment.rb
235
236
  - lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb
236
237
  - lib/ridgepole/ext/pp_sort_hash.rb
237
238
  - lib/ridgepole/ext/schema_dumper.rb
@@ -292,6 +293,7 @@ files:
292
293
  - spec/mysql/migrate/migrate_create_index2_spec.rb
293
294
  - spec/mysql/migrate/migrate_create_index_spec.rb
294
295
  - spec/mysql/migrate/migrate_create_table_spec.rb
296
+ - spec/mysql/migrate/migrate_create_table_with_index_spec.rb
295
297
  - spec/mysql/migrate/migrate_create_table_with_options_spec.rb
296
298
  - spec/mysql/migrate/migrate_create_table_with_script_spec.rb
297
299
  - spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb
@@ -330,6 +332,7 @@ files:
330
332
  - spec/mysql/~default_name_fk/migrate_change_fk_spec.rb
331
333
  - spec/mysql/~default_name_fk/migrate_create_fk_spec.rb
332
334
  - spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb
335
+ - spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb
333
336
  - spec/mysql57/json/add_json_column_spec.rb
334
337
  - spec/mysql57/json/change_json_column_spec.rb
335
338
  - spec/mysql57/json/drop_json_column_spec.rb
@@ -444,6 +447,7 @@ test_files:
444
447
  - spec/mysql/migrate/migrate_create_index2_spec.rb
445
448
  - spec/mysql/migrate/migrate_create_index_spec.rb
446
449
  - spec/mysql/migrate/migrate_create_table_spec.rb
450
+ - spec/mysql/migrate/migrate_create_table_with_index_spec.rb
447
451
  - spec/mysql/migrate/migrate_create_table_with_options_spec.rb
448
452
  - spec/mysql/migrate/migrate_create_table_with_script_spec.rb
449
453
  - spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb
@@ -482,6 +486,7 @@ test_files:
482
486
  - spec/mysql/~default_name_fk/migrate_change_fk_spec.rb
483
487
  - spec/mysql/~default_name_fk/migrate_create_fk_spec.rb
484
488
  - spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb
489
+ - spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb
485
490
  - spec/mysql57/json/add_json_column_spec.rb
486
491
  - spec/mysql57/json/change_json_column_spec.rb
487
492
  - spec/mysql57/json/drop_json_column_spec.rb