ridgepole 0.8.9 → 0.9.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +83 -0
  3. data/.rubocop.yml +9 -34
  4. data/.simplecov +6 -0
  5. data/Appraisals +4 -5
  6. data/README.md +25 -40
  7. data/bin/ridgepole +13 -3
  8. data/gemfiles/{activerecord_5.0.gemfile → activerecord_6.1.gemfile} +1 -2
  9. data/lib/ridgepole/client.rb +8 -3
  10. data/lib/ridgepole/default_limit.rb +1 -1
  11. data/lib/ridgepole/delta.rb +16 -1
  12. data/lib/ridgepole/diff.rb +50 -31
  13. data/lib/ridgepole/dsl_parser.rb +3 -5
  14. data/lib/ridgepole/dsl_parser/context.rb +1 -1
  15. data/lib/ridgepole/dsl_parser/table_definition.rb +52 -42
  16. data/lib/ridgepole/execute_expander.rb +10 -1
  17. data/lib/ridgepole/ext/abstract_adapter/disable_table_options.rb +9 -1
  18. data/lib/ridgepole/external_sql_executer.rb +12 -1
  19. data/lib/ridgepole/version.rb +1 -1
  20. data/ridgepole.gemspec +7 -4
  21. data/spec/erb_helper.rb +5 -5
  22. data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +2 -2
  23. data/spec/mysql/bigint_pk/int_pk_spec.rb +1 -1
  24. data/spec/mysql/cli/ridgepole_spec.rb +35 -1
  25. data/spec/mysql/collation/collation_spec.rb +15 -15
  26. data/spec/mysql/comment/comment_spec.rb +9 -9
  27. data/spec/mysql/diff/diff2_spec.rb +5 -5
  28. data/spec/mysql/diff/diff_spec.rb +3 -3
  29. data/spec/mysql/dump/dump_class_method_spec.rb +13 -13
  30. data/spec/mysql/dump/dump_some_tables_spec.rb +4 -4
  31. data/spec/mysql/dump/dump_spec.rb +13 -13
  32. data/spec/mysql/dump/dump_unknown_column_type_spec.rb +2 -2
  33. data/spec/mysql/dump/dump_without_table_options_spec.rb +2 -2
  34. data/spec/mysql/fk/migrate_change_fk2_spec.rb +2 -2
  35. data/spec/mysql/fk/migrate_change_fk_spec.rb +20 -20
  36. data/spec/mysql/fk/migrate_create_fk_spec.rb +73 -24
  37. data/spec/mysql/fk/migrate_drop_fk_spec.rb +26 -26
  38. data/spec/mysql/fk/migrate_fk_with_column_spec.rb +16 -16
  39. data/spec/mysql/fk/migrate_ignore_fk_spec.rb +6 -6
  40. data/spec/mysql/migrate/migrate_add_column_order_spec.rb +2 -2
  41. data/spec/mysql/migrate/migrate_add_column_spec.rb +18 -18
  42. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +106 -18
  43. data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +18 -18
  44. data/spec/mysql/migrate/migrate_change_column2_spec.rb +5 -5
  45. data/spec/mysql/migrate/migrate_change_column3_spec.rb +116 -25
  46. data/spec/mysql/migrate/migrate_change_column5_spec.rb +3 -3
  47. data/spec/mysql/migrate/migrate_change_column6_spec.rb +7 -7
  48. data/spec/mysql/migrate/migrate_change_column8_spec.rb +38 -5
  49. data/spec/mysql/migrate/migrate_change_column_default_spec.rb +2 -14
  50. data/spec/mysql/migrate/migrate_change_column_spec.rb +21 -21
  51. data/spec/mysql/migrate/migrate_change_index2_spec.rb +5 -5
  52. data/spec/mysql/migrate/migrate_change_index3_spec.rb +7 -7
  53. data/spec/mysql/migrate/migrate_change_index4_spec.rb +6 -6
  54. data/spec/mysql/migrate/migrate_change_index5_spec.rb +4 -4
  55. data/spec/mysql/migrate/migrate_change_index6_spec.rb +27 -27
  56. data/spec/mysql/migrate/migrate_change_index7_spec.rb +4 -4
  57. data/spec/mysql/migrate/migrate_change_index8_spec.rb +4 -4
  58. data/spec/mysql/migrate/migrate_change_index_spec.rb +34 -28
  59. data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +5 -5
  60. data/spec/mysql/migrate/migrate_create_index2_spec.rb +24 -24
  61. data/spec/mysql/migrate/migrate_create_index_spec.rb +18 -18
  62. data/spec/mysql/migrate/migrate_create_table_spec.rb +16 -16
  63. data/spec/mysql/migrate/migrate_create_table_with_ignore_spec.rb +4 -4
  64. data/spec/mysql/migrate/migrate_create_table_with_index_spec.rb +4 -4
  65. data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +16 -16
  66. data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +18 -18
  67. data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +16 -16
  68. data/spec/mysql/migrate/migrate_drop_column_and_unique_index_spec.rb +1 -1
  69. data/spec/mysql/migrate/migrate_drop_column_spec.rb +18 -18
  70. data/spec/mysql/migrate/migrate_drop_index_spec.rb +15 -15
  71. data/spec/mysql/migrate/migrate_drop_table_spec.rb +16 -16
  72. data/spec/mysql/migrate/migrate_empty_spec.rb +9 -9
  73. data/spec/mysql/migrate/migrate_execute_spec.rb +32 -32
  74. data/spec/mysql/migrate/migrate_ignore_column_spec.rb +4 -4
  75. data/spec/mysql/migrate/migrate_ignore_index_spec.rb +5 -5
  76. data/spec/mysql/migrate/migrate_log_file_spec.rb +16 -16
  77. data/spec/mysql/migrate/migrate_merge_mode_spec.rb +18 -18
  78. data/spec/mysql/migrate/migrate_noop_spec.rb +12 -12
  79. data/spec/mysql/migrate/migrate_primary_key_spec.rb +31 -6
  80. data/spec/mysql/migrate/migrate_rename_column_spec.rb +18 -18
  81. data/spec/mysql/migrate/migrate_rename_table_spec.rb +22 -22
  82. data/spec/mysql/migrate/migrate_same_spec.rb +13 -13
  83. data/spec/mysql/migrate/migrate_skip_column_comment_change_spec.rb +2 -2
  84. data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +18 -18
  85. data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +18 -18
  86. data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +18 -18
  87. data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +18 -18
  88. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +2 -2
  89. data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +6 -6
  90. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +9 -9
  91. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +8 -8
  92. data/spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb +5 -5
  93. data/spec/mysql57/json/add_json_column_spec.rb +2 -2
  94. data/spec/mysql57/json/change_json_column_spec.rb +6 -6
  95. data/spec/mysql57/json/drop_json_column_spec.rb +2 -2
  96. data/spec/mysql57/virtual/add_virtual_column_spec.rb +1 -1
  97. data/spec/mysql57/virtual/change_virtual_column_spec.rb +1 -1
  98. data/spec/mysql57/virtual/drop_virtual_column_spec.rb +1 -1
  99. data/spec/postgresql/dump/dump_spec.rb +13 -13
  100. data/spec/postgresql/fk/migrate_change_fk_spec.rb +6 -6
  101. data/spec/postgresql/fk/migrate_create_fk_spec.rb +5 -5
  102. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +8 -8
  103. data/spec/postgresql/migrate/migrate_add_column_spec.rb +27 -20
  104. data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +1 -1
  105. data/spec/postgresql/migrate/migrate_change_column_spec.rb +20 -16
  106. data/spec/postgresql/migrate/migrate_change_index_spec.rb +18 -18
  107. data/spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb +1 -1
  108. data/spec/postgresql/migrate/migrate_create_table_spec.rb +14 -14
  109. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +29 -22
  110. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +17 -17
  111. data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +3 -3
  112. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +15 -15
  113. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +16 -16
  114. data/spec/postgresql/migrate/migrate_primary_key2_spec.rb +1 -1
  115. data/spec/postgresql/migrate/migrate_primary_key_spec.rb +1 -1
  116. data/spec/postgresql/migrate/migrate_references_spec.rb +6 -6
  117. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +18 -18
  118. data/spec/postgresql/migrate/migrate_rename_table_spec.rb +20 -20
  119. data/spec/postgresql/migrate/migrate_same_spec.rb +13 -13
  120. data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +3 -3
  121. data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +4 -4
  122. data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +4 -4
  123. data/spec/processing_for_ci.rb +13 -0
  124. data/spec/spec_condition.rb +4 -0
  125. data/spec/spec_helper.rb +3 -2
  126. metadata +74 -49
  127. data/.travis.yml +0 -45
  128. data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +0 -31
  129. data/omnibus-ridgepole/.gitignore +0 -10
  130. data/omnibus-ridgepole/Dockerfile.centos +0 -25
  131. data/omnibus-ridgepole/Dockerfile.ubuntu +0 -21
  132. data/omnibus-ridgepole/Gemfile +0 -24
  133. data/omnibus-ridgepole/README.md +0 -15
  134. data/omnibus-ridgepole/Rakefile +0 -38
  135. data/omnibus-ridgepole/config/projects/ridgepole.rb +0 -27
  136. data/omnibus-ridgepole/config/software/ridgepole.rb +0 -13
  137. data/omnibus-ridgepole/omnibus.rb +0 -54
  138. data/omnibus-ridgepole/package-scripts/ridgepole/postinst +0 -1
  139. data/omnibus-ridgepole/package-scripts/ridgepole/postrm +0 -1
  140. data/spec/mysql/bigint_pk/bigint_pk_spec.rb +0 -47
  141. data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +0 -141
  142. data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +0 -141
  143. data/spec/processing_for_travis.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4a820687bccfcbcfaa3290b28536a0ea3599d32a35a16e897f37a20a4e1ef75
4
- data.tar.gz: c25c8a48b003aa297f7b1a979f609898b776c3393628d42c2dc2a0897d87be0e
3
+ metadata.gz: 10f8b6443da2ed263c957eb68325c4fa6d96ff3e5b0b8b0c32970c39a70e7fdb
4
+ data.tar.gz: f46637323aee71ad24e87c0fed171ecdf96903a0f43bb20aea270db5e454b609
5
5
  SHA512:
6
- metadata.gz: d58fae0cd35607eb2980be9600b0d31b04605c559445932d7f73ab7cec066267bb45da5ef783c0ab577fec2272f664214afd190d088c1976f299fcfb30a6c54a
7
- data.tar.gz: 498c6a55c4d7480a7ac019e58ddc63a8212961bda3d587f9d30d860be1d04d8a8f33e5bcbac72044d759919a3abba46f36750cc4cf2bcd44b87d4af352f7318d
6
+ metadata.gz: dbf4ef4b329627688da0d8ae61e3190ab3773c4b6b9e3d46b55b481db5ece42fcba73395f2f2b4980430930479fea27ce039c51892e981b2cf7e55276e36dbac
7
+ data.tar.gz: 9d4dd03ace90b791ffd33924204cb785491569a859227db9bd0e18f186e27b716f325663249625bba378608a0e3c3fadedbeb306e9cf03634af19adf010db491
@@ -0,0 +1,83 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby:
14
+ - 2.4
15
+ - 2.5
16
+ - 2.6
17
+ - 2.7
18
+ env:
19
+ - MYSQL56=1
20
+ - MYSQL57=1
21
+ - POSTGRESQL=1
22
+ gemfile:
23
+ - gemfiles/activerecord_5.1.gemfile
24
+ - gemfiles/activerecord_5.2.gemfile
25
+ - gemfiles/activerecord_6.0.gemfile
26
+ - gemfiles/activerecord_6.1.gemfile
27
+ exclude:
28
+ - ruby: 2.4
29
+ gemfile: gemfiles/activerecord_6.0.gemfile
30
+ - ruby: 2.4
31
+ gemfile: gemfiles/activerecord_6.1.gemfile
32
+
33
+ steps:
34
+ - uses: actions/checkout@v2
35
+ - uses: actions/setup-ruby@v1
36
+ with:
37
+ ruby-version: ${{ matrix.ruby }}
38
+ - uses: actions/cache@v2
39
+ with:
40
+ path: gemfiles/vendor/bundle
41
+ key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ hashFiles('ridgepole.gemspec', '**/Gemfile', '${{ matrix.gemfile }}') }}
42
+ restore-keys: |
43
+ ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.gemfile }}-
44
+
45
+ - name: Setup dependencies
46
+ run: |
47
+ for i in {1..60}; do docker-compose up -d && break; sleep 1; done
48
+
49
+ gem install bundler
50
+ bundle config path vendor/bundle
51
+ bundle install --jobs 4 --retry 3
52
+
53
+ # Wait until database servers start
54
+ function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P 13316 -ppassword ping; }
55
+ function mysql57_ping { mysqladmin -u root -h 127.0.0.1 -P 13317 -ppassword ping; }
56
+ function pg_ping { PGPASSWORD=password pg_isready -U postgres -h 127.0.0.1 -p 15442; }
57
+ for i in {1..60}; do mysql_ping && break; sleep 1; done
58
+ for i in {1..60}; do mysql57_ping && break; sleep 1; done
59
+ for i in {1..60}; do pg_ping && break; sleep 1; done
60
+ env:
61
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
62
+
63
+ - name: Run tests
64
+ run: ${{ matrix.env }} bundle exec rake
65
+ env:
66
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
67
+
68
+ - name: Coveralls Parallel
69
+ uses: coverallsapp/github-action@v1.1.2
70
+ with:
71
+ github-token: ${{ secrets.GITHUB_TOKEN }}
72
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.env }}-${{ matrix.gemfile }}
73
+ parallel: true
74
+
75
+ finish:
76
+ needs: build
77
+ runs-on: ubuntu-latest
78
+ steps:
79
+ - name: Coveralls Finished
80
+ uses: coverallsapp/github-action@v1.1.2
81
+ with:
82
+ github-token: ${{ secrets.GITHUB_TOKEN }}
83
+ parallel-finished: true
@@ -3,6 +3,7 @@ AllCops:
3
3
  - 'gemfiles/**/*'
4
4
  - 'omnibus-ridgepole/**/*'
5
5
  TargetRubyVersion: 2.4
6
+ NewCops: enable
6
7
  Bundler/OrderedGems:
7
8
  Include:
8
9
  - 'Appraisals'
@@ -39,39 +40,13 @@ Layout/ClosingHeredocIndentation:
39
40
  Enabled: false
40
41
  Style/NumericPredicate:
41
42
  Enabled: false
42
- Layout/EmptyLinesAroundAttributeAccessor:
43
- Enabled: true
44
- Layout/SpaceAroundMethodCallOperator:
45
- Enabled: true
46
- Lint/DeprecatedOpenSSLConstant:
47
- Enabled: true
48
43
  Lint/MissingSuper:
49
44
  Enabled: false
50
- Lint/MixedRegexpCaptureTypes:
51
- Enabled: true
52
- Lint/RaiseException:
53
- Enabled: true
54
- Lint/StructNewOverride:
55
- Enabled: true
56
- Style/AccessorGrouping:
57
- Enabled: true
58
- Style/BisectedAttrAccessor:
59
- Enabled: true
60
- Style/ExponentialNotation:
61
- Enabled: true
62
- Style/HashEachMethods:
63
- Enabled: true
64
- Style/HashTransformKeys:
65
- Enabled: true
66
- Style/HashTransformValues:
67
- Enabled: true
68
- Style/RedundantAssignment:
69
- Enabled: true
70
- Style/RedundantFetchBlock:
71
- Enabled: true
72
- Style/RedundantRegexpCharacterClass:
73
- Enabled: true
74
- Style/RedundantRegexpEscape:
75
- Enabled: true
76
- Style/SlicingWithRange:
77
- Enabled: true
45
+ Style/StringConcatenation:
46
+ Enabled: false
47
+ Style/SoleNestedConditional:
48
+ Enabled: false
49
+ Lint/DuplicateBranch:
50
+ Enabled: false
51
+ Style/OptionalBooleanParameter:
52
+ Enabled: false
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.start do
4
+ # exclude directories and files
5
+ add_filter '/spec/'
6
+ end
data/Appraisals CHANGED
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'activerecord-5.0' do
4
- gem 'activerecord', '~> 5.0.1'
5
- gem 'pg', '< 1.0.0'
6
- end
7
-
8
3
  appraise 'activerecord-5.1' do
9
4
  gem 'activerecord', '~> 5.1.0'
10
5
  end
@@ -17,3 +12,7 @@ end
17
12
  appraise 'activerecord-6.0' do
18
13
  gem 'activerecord', '~> 6.0.0'
19
14
  end
15
+
16
+ appraise 'activerecord-6.1' do
17
+ gem 'activerecord', '~> 6.1.0'
18
+ end
data/README.md CHANGED
@@ -6,8 +6,9 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
6
6
  (like Chef/Puppet)
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/ridgepole.svg)](http://badge.fury.io/rb/ridgepole)
9
- [![Build Status](https://travis-ci.org/winebarrel/ridgepole.svg?branch=0.8)](https://travis-ci.org/winebarrel/ridgepole)
10
- [![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.8)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.8)
9
+ [![Unstable Version](https://img.shields.io/badge/unstable-0.9.0.beta-brightgreen.svg?longCache=true&style=flat)](https://rubygems.org/gems/ridgepole/versions/0.9.0.beta)
10
+ [![Build Status](https://github.com/winebarrel/ridgepole/workflows/test/badge.svg?branch=0.9)](https://github.com/winebarrel/ridgepole/actions)
11
+ [![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.9)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.9)
11
12
 
12
13
  <details><summary>ChangeLog</summary>
13
14
 
@@ -120,8 +121,29 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
120
121
  * `>= 0.8.9`
121
122
  * Fix unexpected differences on text types and blob types on Rails 6 ([pull#306](https://github.com/winebarrel/ridgepole/pull/306))
122
123
  * Fix unexpected warning when a foreign key is added on the primary key ([pull#307](https://github.com/winebarrel/ridgepole/pull/307))
124
+ * `>= 0.8.10`
125
+ * Raise an error if an InnoDB column has a foreign key but no index ([pull#310](https://github.com/winebarrel/ridgepole/pull/310))
126
+ * `>= 0.8.11`
127
+ * Fix FK index check support multiple PK ([pull#315](https://github.com/winebarrel/ridgepole/pull/315))
128
+ * Support t.reference() foreign_key option ([pull#316](https://github.com/winebarrel/ridgepole/pull/316))
129
+ * `>= 0.8.12`
130
+ * Pluralize column specified by `references` ([pull#317](https://github.com/winebarrel/ridgepole/pull/317))
131
+ * `>= 0.9.0`
132
+ * Remove `--mysql-alter-index` option ([pull#330](https://github.com/winebarrel/ridgepole/pull/330))
133
+ * Add `--table-hash-options` option ([pull#331](https://github.com/winebarrel/ridgepole/pull/331))
134
+ * Support Rails 6.1 ([pull#323](https://github.com/winebarrel/ridgepole/pull/323))
135
+ * Disable Rails 5.0 support ([pull#335](https://github.com/winebarrel/ridgepole/pull/335))
136
+ * Fix PK AUTO_INCREMENT change bug ([pull#334](https://github.com/winebarrel/ridgepole/pull/334))
123
137
  </details>
124
138
 
139
+ **Notice**
140
+
141
+ ActiveRecord 6.1 is supported in ridgepole v0.9, but the ActiveRecord dump has been changed, so there is a difference between ActiveRecord 5.x/6.0 format.
142
+
143
+ **If you use ActiveRecord 6.1, please modify Schemafile format**.
144
+
145
+ cf. https://github.com/winebarrel/ridgepole/pull/323
146
+
125
147
  ## Installation
126
148
 
127
149
  Add this line to your application's Gemfile:
@@ -136,26 +158,6 @@ Or install it yourself as:
136
158
 
137
159
  $ gem install ridgepole
138
160
 
139
- ## Omnibus Package (deb/rpm)
140
-
141
- see https://github.com/winebarrel/ridgepole/releases.
142
-
143
- ### Install from deb
144
-
145
- ```sh
146
- sudo dpkg -i ridgepole_x.x.x+xxx-x_amd64.deb
147
- sudo apt install build-essential libmysqlclient-dev
148
- sudo /opt/ridgepole/embedded/bin/gem install mysql2
149
- ```
150
-
151
- ### Install from rpm
152
-
153
- ```sh
154
- sudo yum install ridgepole-x.x.x+xxx-x.el7.x86_64.rpm
155
- sudo yum install make gcc mariadb-devel
156
- sudo /opt/ridgepole/embedded/bin/gem install mysql2
157
- ```
158
-
159
161
  ## Help
160
162
  ```
161
163
  Usage: ridgepole [options]
@@ -167,6 +169,7 @@ Usage: ridgepole [options]
167
169
  -f, --file SCHEMAFILE
168
170
  --dry-run
169
171
  --table-options OPTIONS
172
+ --table-hash-options OPTIONS
170
173
  --alter-extra ALTER_SPEC
171
174
  --external-script SCRIPT
172
175
  --bulk-change
@@ -187,7 +190,6 @@ Usage: ridgepole [options]
187
190
  -o, --output SCHEMAFILE
188
191
  -t, --tables TABLES
189
192
  --ignore-tables REGEX_LIST
190
- --mysql-use-alter
191
193
  --dump-without-table-options
192
194
  --dump-with-default-fk-name
193
195
  --index-removed-drop-column
@@ -397,20 +399,6 @@ Apply `Schemafile`
397
399
  -> 0.0471s
398
400
  ```
399
401
 
400
- ## Use ALTER instead of CREATE/DROP INDEX
401
-
402
- ```sh
403
- $ ridgepole -a -c database.yml --mysql-use-alter --debug
404
- Apply `Schemafile`
405
- ...
406
- -- remove_index("dept_manager", {:name=>"emp_no"})
407
- (19.2ms) ALTER TABLE `dept_manager` DROP INDEX `emp_no`
408
- -> 0.0200s
409
- -- add_index("dept_manager", ["emp_no"], {:name=>"emp_no2", :using=>:btree})
410
- (23.4ms) ALTER TABLE `dept_manager` ADD INDEX `emp_no2` USING btree (`emp_no`)
411
- -> 0.0243s
412
- ```
413
-
414
402
  ## Relation column type check
415
403
 
416
404
  ```ruby
@@ -459,6 +447,3 @@ bundle exec appraisal activerecord-5.1 rake
459
447
  * https://github.com/winebarrel/ridgepole-example
460
448
  * https://github.com/winebarrel/ridgepole-example/pull/1
461
449
  * https://github.com/winebarrel/ridgepole-example/pull/2
462
-
463
- ## Similar tools
464
- * [Codenize.tools](http://codenize.tools/)
@@ -86,6 +86,19 @@ ARGV.options do |opt|
86
86
  opt.on('-f', '--file SCHEMAFILE') { |v| file = v }
87
87
  opt.on('', '--dry-run') { options[:dry_run] = true }
88
88
  opt.on('', '--table-options OPTIONS') { |v| options[:table_options] = v }
89
+ opt.on('', '--table-hash-options OPTIONS') do |v|
90
+ # NOTE: Ruby2.4 doesn't support `symbolize_names: true`
91
+ hash = YAML.safe_load(v).deep_symbolize_keys
92
+
93
+ case hash[:id]
94
+ when String
95
+ hash[:id] = hash[:id].to_sym
96
+ when Hash
97
+ hash[:id][:type] = hash[:id][:type].to_sym if hash[:id][:type]
98
+ end
99
+
100
+ options[:table_hash_options] = hash
101
+ end
89
102
  opt.on('', '--alter-extra ALTER_SPEC') { |v| options[:alter_extra] = v }
90
103
  opt.on('', '--external-script SCRIPT') { |v| options[:external_script] = v }
91
104
  opt.on('', '--bulk-change') do
@@ -121,7 +134,6 @@ ARGV.options do |opt|
121
134
  opt.on('-o', '--output SCHEMAFILE') { |v| output_file = v }
122
135
  opt.on('-t', '--tables TABLES', Array) { |v| options[:tables] = v }
123
136
  opt.on('', '--ignore-tables REGEX_LIST', Array) { |v| options[:ignore_tables] = v.map { |i| Regexp.new(i) } }
124
- opt.on('', '--mysql-use-alter') { options[:mysql_use_alter] = true }
125
137
  opt.on('', '--dump-without-table-options') { options[:dump_without_table_options] = true }
126
138
  opt.on('', '--dump-with-default-fk-name') { options[:dump_with_default_fk_name] = true }
127
139
  opt.on('', '--index-removed-drop-column') { options[:index_removed_drop_column] = true }
@@ -135,8 +147,6 @@ ARGV.options do |opt|
135
147
  opt.on('', '--create-table-with-index') { options[:create_table_with_index] = true }
136
148
 
137
149
  opt.on('', '--mysql-dump-auto-increment') do
138
- raise OptionParser::InvalidOption, '`mysql-dump-auto-increment` is not available in `activerecord < 5.1`' if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('5.1')
139
-
140
150
  options[:mysql_dump_auto_increment] = true
141
151
  end
142
152
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 5.0.1"
6
- gem "pg", "< 1.0.0"
5
+ gem "activerecord", "~> 6.1.0"
7
6
 
8
7
  gemspec path: "../"
@@ -15,8 +15,6 @@ module Ridgepole
15
15
  @parser = Ridgepole::DSLParser.new(@options)
16
16
  @diff = Ridgepole::Diff.new(@options)
17
17
 
18
- require 'ridgepole/ext/abstract_mysql_adapter/use_alter_index' if @options[:mysql_use_alter]
19
-
20
18
  require 'ridgepole/ext/abstract_mysql_adapter/dump_auto_increment' if @options[:mysql_dump_auto_increment]
21
19
  end
22
20
 
@@ -32,7 +30,7 @@ module Ridgepole
32
30
  logger.verbose_info('# Parse DSL')
33
31
  expected_definition, expected_execute = @parser.parse(dsl, opts)
34
32
  expected_definition.each do |_table, definition|
35
- definition[:options][:options] ||= @options[:table_options] if @options[:table_options]
33
+ merge_table_options(definition)
36
34
  end
37
35
  logger.verbose_info('# Load tables')
38
36
  current_definition, _current_execute = @parser.parse(@dumper.dump, opts)
@@ -40,6 +38,13 @@ module Ridgepole
40
38
  @diff.diff(current_definition, expected_definition, execute: expected_execute)
41
39
  end
42
40
 
41
+ private
42
+
43
+ def merge_table_options(definition)
44
+ definition[:options].reverse_merge!(@options[:table_hash_options]) if @options[:table_hash_options]
45
+ definition[:options][:options] ||= @options[:table_options] if @options[:table_options]
46
+ end
47
+
43
48
  class << self
44
49
  def diff(dsl_or_config1, dsl_or_config2, options = {})
45
50
  logger = Ridgepole::Logger.instance
@@ -23,7 +23,7 @@ module Ridgepole
23
23
  end
24
24
 
25
25
  def adapter
26
- ActiveRecord::Base.connection_config.fetch(:adapter).to_sym
26
+ ActiveRecord::Base.connection.adapter_name.downcase.to_sym
27
27
  rescue ActiveRecord::ConnectionNotEstablished
28
28
  nil
29
29
  end
@@ -292,6 +292,19 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
292
292
  buf.puts
293
293
  end
294
294
 
295
+ def append_change_table_raw_options(table_name, raw_table_options, table_charset, table_collation, buf)
296
+ if raw_table_options.blank? && ActiveRecord.gem_version >= Gem::Version.new('6.1.0')
297
+ # Implicit engine is InnoDB in 6.1.0
298
+ # related: https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R441
299
+ raw_table_options = +'ENGINE=InnoDB'
300
+ end
301
+
302
+ raw_table_options << " DEFAULT CHARSET=#{table_charset}" if table_charset
303
+ raw_table_options << " COLLATE=#{table_collation}" if table_collation
304
+
305
+ append_change_table_options(table_name, raw_table_options, buf)
306
+ end
307
+
295
308
  def append_change_table_comment(table_name, table_comment, buf)
296
309
  comment_literal = "COMMENT=#{ActiveRecord::Base.connection.quote(table_comment)}"
297
310
  append_change_table_options(table_name, comment_literal, buf)
@@ -303,6 +316,8 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
303
316
  indices = attrs[:indices] || {}
304
317
  foreign_keys = attrs[:foreign_keys] || {}
305
318
  table_options = attrs[:table_options]
319
+ table_charset = attrs[:table_charset]
320
+ table_collation = attrs[:table_collation]
306
321
  table_comment = attrs[:table_comment]
307
322
 
308
323
  if !definition.empty? || !indices.empty? || !primary_key_definition.empty?
@@ -316,7 +331,7 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
316
331
 
317
332
  append_change_foreign_keys(table_name, foreign_keys, pre_buf_for_fk, post_buf_for_fk, @options) unless foreign_keys.empty?
318
333
 
319
- append_change_table_options(table_name, table_options, buf) if table_options
334
+ append_change_table_raw_options(table_name, table_options, table_charset, table_collation, buf) if table_options || table_charset || table_collation
320
335
 
321
336
  append_change_table_comment(table_name, table_comment, buf) if table_comment
322
337
 
@@ -114,23 +114,33 @@ module Ridgepole
114
114
 
115
115
  normalize_default_proc_options!(from, to)
116
116
 
117
- from_options = from[:options] || {}
118
- to_options = to[:options] || {}
119
-
120
117
  if @options[:ignore_table_comment]
121
118
  from.delete(:comment)
122
119
  to.delete(:comment)
123
120
  end
124
121
 
125
- [from, to].each do |table_attrs|
126
- table_attrs.delete(:default) if table_attrs.key?(:default) && table_attrs[:default].nil?
127
- end
128
-
129
122
  if Ridgepole::ConnectionAdapters.mysql?
130
- if @options[:mysql_change_table_options] && (from_options != to_options)
131
- from.delete(:options)
132
- to.delete(:options)
133
- table_delta[:table_options] = to_options
123
+ if @options[:mysql_change_table_options]
124
+ from_options = from[:options] || {}
125
+ to_options = to[:options] || {}
126
+
127
+ if from_options != to_options
128
+ table_delta[:table_options] = to_options
129
+ from.delete(:options)
130
+ to.delete(:options)
131
+ end
132
+
133
+ if from[:charset] != to[:charset]
134
+ table_delta[:table_charset] = to[:charset]
135
+ from.delete(:charset)
136
+ to.delete(:charset)
137
+ end
138
+
139
+ if from[:collation] != to[:collation]
140
+ table_delta[:table_collation] = to[:collation]
141
+ from.delete(:collation)
142
+ to.delete(:collation)
143
+ end
134
144
  end
135
145
 
136
146
  if @options[:mysql_change_table_comment] && (from[:comment] != to[:comment])
@@ -142,10 +152,14 @@ module Ridgepole
142
152
 
143
153
  if @options[:dump_without_table_options]
144
154
  from.delete(:options)
155
+ from.delete(:charset)
156
+ from.delete(:collation)
145
157
  to.delete(:options)
158
+ to.delete(:charset)
159
+ to.delete(:collation)
146
160
  end
147
161
 
148
- pk_attrs = build_primary_key_attrs_if_changed(from, to, table_name)
162
+ pk_attrs = build_primary_key_attrs_if_changed(from, to)
149
163
  if pk_attrs
150
164
  if @options[:allow_pk_change]
151
165
  if from[:id] == false
@@ -177,33 +191,36 @@ module Ridgepole
177
191
  end
178
192
 
179
193
  def convert_to_primary_key_attrs(column_options)
180
- options = column_options.dup
181
-
182
- type = if options[:id]
183
- options.delete(:id)
184
- else
185
- Ridgepole::DSLParser::TableDefinition::DEFAULT_PRIMARY_KEY_TYPE
186
- end
194
+ type = Ridgepole::DSLParser::TableDefinition::DEFAULT_PRIMARY_KEY_TYPE
195
+ options = column_options.deep_dup
196
+
197
+ if options[:id].is_a?(Hash)
198
+ options_id = options.delete(:id)
199
+ type = options_id.delete(:type) if options_id[:type]
200
+ options.merge!(options_id.slice(*PRIMARY_KEY_OPTIONS))
201
+ elsif options[:id]
202
+ type = options.delete(:id)
203
+ end
187
204
 
188
205
  options[:auto_increment] = true if %i[integer bigint].include?(type) && !options.key?(:default) && !Ridgepole::ConnectionAdapters.postgresql?
189
206
 
190
207
  { type: type, options: options }
191
208
  end
192
209
 
193
- def build_attrs_if_changed(to_attrs, from_attrs, table_name, primary_key: false)
210
+ def build_attrs_if_changed(to_attrs, from_attrs, primary_key: false)
194
211
  normalize_column_options!(from_attrs, primary_key)
195
212
  normalize_column_options!(to_attrs, primary_key)
196
213
 
197
- new_to_attrs = fix_change_column_options(table_name, from_attrs, to_attrs) unless compare_column_attrs(from_attrs, to_attrs)
214
+ new_to_attrs = fix_change_column_options(from_attrs, to_attrs) unless compare_column_attrs(from_attrs, to_attrs)
198
215
  new_to_attrs
199
216
  end
200
217
 
201
- def build_primary_key_attrs_if_changed(from, to, table_name)
218
+ def build_primary_key_attrs_if_changed(from, to)
202
219
  from_column_attrs = convert_to_primary_key_attrs(from.slice(*PRIMARY_KEY_OPTIONS))
203
220
  to_column_attrs = convert_to_primary_key_attrs(to.slice(*PRIMARY_KEY_OPTIONS))
204
221
  return if from_column_attrs == to_column_attrs
205
222
 
206
- build_attrs_if_changed(to_column_attrs, from_column_attrs, table_name, primary_key: true)
223
+ build_attrs_if_changed(to_column_attrs, from_column_attrs, primary_key: true)
207
224
  end
208
225
 
209
226
  def scan_definition_change(from, to, from_indices, table_name, table_options, table_delta)
@@ -225,7 +242,7 @@ module Ridgepole
225
242
  next if ignore_column
226
243
 
227
244
  if from_attrs
228
- to_attrs = build_attrs_if_changed(to_attrs, from_attrs, table_name)
245
+ to_attrs = build_attrs_if_changed(to_attrs, from_attrs)
229
246
  if to_attrs
230
247
  definition_delta[:change] ||= {}
231
248
  definition_delta[:change][column_name] = to_attrs
@@ -454,7 +471,7 @@ module Ridgepole
454
471
  # XXX: MySQL only?
455
472
  # https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L760
456
473
  # https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb#L102
457
- def fix_change_column_options(table_name, from_attrs, to_attrs)
474
+ def fix_change_column_options(from_attrs, to_attrs)
458
475
  # default: 0, null: false -> default: nil, null: false | default: nil
459
476
  # default: 0, null: false -> null: false | default: nil
460
477
  # default: 0, null: false -> default: nil, null: true | default: nil, null: true
@@ -469,10 +486,6 @@ module Ridgepole
469
486
  to_attrs[:options].delete(:null)
470
487
  end
471
488
 
472
- if Ridgepole::ConnectionAdapters.mysql? && ActiveRecord::VERSION::STRING.start_with?('5.0.')
473
- Ridgepole::Logger.instance.warn("[WARNING] Table `#{table_name}`: `default: nil` is ignored when `null: false`. Please apply twice") if to_attrs[:options][:default].nil? && (to_attrs[:options][:null] == false)
474
- end
475
-
476
489
  to_attrs
477
490
  end
478
491
 
@@ -551,9 +564,15 @@ module Ridgepole
551
564
  table_options = parent_table_info.fetch(:options)
552
565
  next if table_options[:id] == false
553
566
 
567
+ options_id = table_options[:id]
568
+ parent_type, parent_unsigned = if options_id.is_a?(Hash)
569
+ [options_id[:type], options_id[:unsigned]]
570
+ else
571
+ [table_options[:id], table_options[:unsigned]]
572
+ end
554
573
  parent_column_info = {
555
- type: table_options[:id] || @options[:check_relation_type].to_sym,
556
- unsigned: table_options[:unsigned],
574
+ type: parent_type || @options[:check_relation_type].to_sym,
575
+ unsigned: parent_unsigned,
557
576
  }
558
577
 
559
578
  child_column_info = {