ridgepole 0.9.0.beta → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +24 -19
  3. data/.rubocop.yml +5 -4
  4. data/.simplecov +6 -0
  5. data/README.md +15 -30
  6. data/bin/ridgepole +0 -2
  7. data/lib/ridgepole/diff.rb +14 -14
  8. data/lib/ridgepole/dsl_parser/table_definition.rb +8 -1
  9. data/lib/ridgepole/version.rb +1 -1
  10. data/ridgepole.gemspec +3 -2
  11. data/spec/erb_helper.rb +1 -5
  12. data/spec/mysql/bigint_pk/int_pk_spec.rb +1 -1
  13. data/spec/mysql/collation/collation_spec.rb +14 -14
  14. data/spec/mysql/comment/comment_spec.rb +9 -9
  15. data/spec/mysql/diff/diff2_spec.rb +5 -5
  16. data/spec/mysql/diff/diff_spec.rb +3 -3
  17. data/spec/mysql/dump/dump_class_method_spec.rb +12 -12
  18. data/spec/mysql/dump/dump_some_tables_spec.rb +4 -4
  19. data/spec/mysql/dump/dump_spec.rb +12 -12
  20. data/spec/mysql/dump/dump_unknown_column_type_spec.rb +2 -2
  21. data/spec/mysql/dump/dump_without_table_options_spec.rb +1 -1
  22. data/spec/mysql/fk/migrate_change_fk2_spec.rb +2 -2
  23. data/spec/mysql/fk/migrate_change_fk_spec.rb +88 -20
  24. data/spec/mysql/fk/migrate_create_fk_spec.rb +73 -18
  25. data/spec/mysql/fk/migrate_drop_fk_spec.rb +81 -26
  26. data/spec/mysql/fk/migrate_fk_with_column_spec.rb +16 -16
  27. data/spec/mysql/fk/migrate_ignore_fk_spec.rb +6 -6
  28. data/spec/mysql/migrate/migrate_add_column_order_spec.rb +2 -2
  29. data/spec/mysql/migrate/migrate_add_column_spec.rb +18 -18
  30. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +21 -21
  31. data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +18 -18
  32. data/spec/mysql/migrate/migrate_change_column2_spec.rb +5 -5
  33. data/spec/mysql/migrate/migrate_change_column3_spec.rb +10 -10
  34. data/spec/mysql/migrate/migrate_change_column5_spec.rb +3 -3
  35. data/spec/mysql/migrate/migrate_change_column6_spec.rb +7 -7
  36. data/spec/mysql/migrate/migrate_change_column7_spec.rb +11 -2
  37. data/spec/mysql/migrate/migrate_change_column_default_spec.rb +2 -14
  38. data/spec/mysql/migrate/migrate_change_column_spec.rb +21 -21
  39. data/spec/mysql/migrate/migrate_change_index2_spec.rb +5 -5
  40. data/spec/mysql/migrate/migrate_change_index3_spec.rb +7 -7
  41. data/spec/mysql/migrate/migrate_change_index4_spec.rb +6 -6
  42. data/spec/mysql/migrate/migrate_change_index5_spec.rb +4 -4
  43. data/spec/mysql/migrate/migrate_change_index6_spec.rb +27 -27
  44. data/spec/mysql/migrate/migrate_change_index7_spec.rb +4 -4
  45. data/spec/mysql/migrate/migrate_change_index8_spec.rb +4 -4
  46. data/spec/mysql/migrate/migrate_change_index_spec.rb +27 -27
  47. data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +1 -1
  48. data/spec/mysql/migrate/migrate_create_index2_spec.rb +24 -24
  49. data/spec/mysql/migrate/migrate_create_index_spec.rb +78 -18
  50. data/spec/mysql/migrate/migrate_create_table_spec.rb +16 -16
  51. data/spec/mysql/migrate/migrate_create_table_with_ignore_spec.rb +4 -4
  52. data/spec/mysql/migrate/migrate_create_table_with_index_spec.rb +4 -4
  53. data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +16 -16
  54. data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +18 -18
  55. data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +16 -16
  56. data/spec/mysql/migrate/migrate_drop_column_and_unique_index_spec.rb +1 -1
  57. data/spec/mysql/migrate/migrate_drop_column_spec.rb +18 -18
  58. data/spec/mysql/migrate/migrate_drop_index_spec.rb +15 -15
  59. data/spec/mysql/migrate/migrate_drop_table_spec.rb +16 -16
  60. data/spec/mysql/migrate/migrate_empty_spec.rb +9 -9
  61. data/spec/mysql/migrate/migrate_execute_spec.rb +32 -32
  62. data/spec/mysql/migrate/migrate_ignore_column_spec.rb +4 -4
  63. data/spec/mysql/migrate/migrate_ignore_index_spec.rb +5 -5
  64. data/spec/mysql/migrate/migrate_log_file_spec.rb +16 -16
  65. data/spec/mysql/migrate/migrate_merge_mode_spec.rb +18 -18
  66. data/spec/mysql/migrate/migrate_noop_spec.rb +12 -12
  67. data/spec/mysql/migrate/migrate_primary_key_spec.rb +1 -1
  68. data/spec/mysql/migrate/migrate_rename_column_spec.rb +18 -18
  69. data/spec/mysql/migrate/migrate_rename_table_spec.rb +22 -22
  70. data/spec/mysql/migrate/migrate_same_spec.rb +12 -12
  71. data/spec/mysql/migrate/migrate_skip_column_comment_change_spec.rb +2 -2
  72. data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +18 -18
  73. data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +18 -18
  74. data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +18 -18
  75. data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +18 -18
  76. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +1 -1
  77. data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +6 -6
  78. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +9 -9
  79. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +8 -8
  80. data/spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb +5 -5
  81. data/spec/mysql57/json/add_json_column_spec.rb +2 -2
  82. data/spec/mysql57/json/change_json_column_spec.rb +6 -6
  83. data/spec/mysql57/json/drop_json_column_spec.rb +2 -2
  84. data/spec/mysql57/virtual/add_virtual_column_spec.rb +1 -1
  85. data/spec/mysql57/virtual/change_virtual_column_spec.rb +1 -1
  86. data/spec/mysql57/virtual/drop_virtual_column_spec.rb +1 -1
  87. data/spec/postgresql/dump/dump_spec.rb +12 -12
  88. data/spec/postgresql/fk/migrate_change_fk_spec.rb +6 -6
  89. data/spec/postgresql/fk/migrate_create_fk_spec.rb +5 -5
  90. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +8 -8
  91. data/spec/postgresql/migrate/migrate_add_column_spec.rb +16 -16
  92. data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +1 -1
  93. data/spec/postgresql/migrate/migrate_change_column_spec.rb +16 -16
  94. data/spec/postgresql/migrate/migrate_change_index_spec.rb +18 -18
  95. data/spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb +1 -1
  96. data/spec/postgresql/migrate/migrate_create_table_spec.rb +14 -14
  97. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +18 -18
  98. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +17 -17
  99. data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +3 -3
  100. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +15 -15
  101. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +16 -16
  102. data/spec/postgresql/migrate/migrate_primary_key2_spec.rb +1 -1
  103. data/spec/postgresql/migrate/migrate_primary_key_spec.rb +1 -1
  104. data/spec/postgresql/migrate/migrate_references_spec.rb +6 -6
  105. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +18 -18
  106. data/spec/postgresql/migrate/migrate_rename_table_spec.rb +20 -20
  107. data/spec/postgresql/migrate/migrate_same_spec.rb +12 -12
  108. data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +3 -3
  109. data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +4 -4
  110. data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +4 -4
  111. data/spec/processing_for_ci.rb +13 -0
  112. data/spec/spec_const.rb +1 -1
  113. data/spec/spec_helper.rb +2 -1
  114. metadata +39 -37
  115. data/omnibus-ridgepole/.gitignore +0 -10
  116. data/omnibus-ridgepole/Dockerfile.centos +0 -25
  117. data/omnibus-ridgepole/Dockerfile.ubuntu +0 -21
  118. data/omnibus-ridgepole/Gemfile +0 -24
  119. data/omnibus-ridgepole/README.md +0 -15
  120. data/omnibus-ridgepole/Rakefile +0 -38
  121. data/omnibus-ridgepole/config/projects/ridgepole.rb +0 -27
  122. data/omnibus-ridgepole/config/software/ridgepole.rb +0 -13
  123. data/omnibus-ridgepole/omnibus.rb +0 -54
  124. data/omnibus-ridgepole/package-scripts/ridgepole/postinst +0 -1
  125. data/omnibus-ridgepole/package-scripts/ridgepole/postrm +0 -1
  126. data/spec/mysql/bigint_pk/bigint_pk_spec.rb +0 -47
  127. data/spec/processing_for_travis.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df81adabc9afddf2d409c647190e217dd71a3948b8d3b9c3753f36c8519df701
4
- data.tar.gz: 3df1478fbdaa3ef5ac2ac192cf1a022901753f1f4adac72f20b93f17b49dcb2d
3
+ metadata.gz: 3453e48af2d76cbb35301fcc70d7177f0016c47f4279593b6adbf269190d0b01
4
+ data.tar.gz: e4e61ed5bbbfae92a0660244a4e021fc387d945ccd5e85971d20c1ff184dc79f
5
5
  SHA512:
6
- metadata.gz: ae3fa69120a6ba5103f512092694abd151073ae3e7ed27c23677aa9f617b4a986565c29e6088fbb0f4ae1a0da0cfc425b5c67c8e8b1b19b956164dd8c7fcdf87
7
- data.tar.gz: bce34561a3ac8489bbc3466e7d63fd0c4c4a557659e28751bfc06fe3f058d3725493c34426cab2a1171ea86e1e35d4fdde8be3b1e31186599a73748a3a2563a3
6
+ metadata.gz: aa213105207d7a0a73adae7254885966fb06b0e0cc22cec7e2e44f7bd2082f7a6b10b2e7d8b5c5822c57b333447cd8ebb591db691b95a541f1493adcf3d46153
7
+ data.tar.gz: 3e1a1c8bbcde1f7d313df1a151d5ca3096e1bba911a099cc4e8969b877941dd85061d2c3d18c17afff976c5119d3cc00f9c9966f9037af5365d8d5b0c87243c0
@@ -29,37 +29,42 @@ jobs:
29
29
  gemfile: gemfiles/activerecord_6.0.gemfile
30
30
  - ruby: 2.4
31
31
  gemfile: gemfiles/activerecord_6.1.gemfile
32
-
32
+ env:
33
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
33
34
  steps:
34
35
  - uses: actions/checkout@v2
35
- - uses: actions/setup-ruby@v1
36
+ - uses: ruby/setup-ruby@v1
36
37
  with:
37
38
  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
-
39
+ bundler-cache: true
45
40
  - name: Setup dependencies
46
41
  run: |
47
42
  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
43
  # 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; }
44
+ function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P 13316 ping --ssl-mode=DISABLED; }
45
+ function mysql57_ping { mysqladmin -u root -h 127.0.0.1 -P 13317 ping --ssl-mode=DISABLED; }
56
46
  function pg_ping { PGPASSWORD=password pg_isready -U postgres -h 127.0.0.1 -p 15442; }
57
47
  for i in {1..60}; do mysql_ping && break; sleep 1; done
58
48
  for i in {1..60}; do mysql57_ping && break; sleep 1; done
59
49
  for i in {1..60}; do pg_ping && break; sleep 1; done
60
50
  env:
61
- BUNDLE_GEMFILE: ${{ matrix.gemfile }}
62
-
63
- - run: ${{ matrix.env }} bundle exec rake
51
+ MYSQL_PWD: password
52
+ - name: Run tests
53
+ run: ${{ matrix.env }} bundle exec rake
64
54
  env:
65
55
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
56
+ - name: Coveralls Parallel
57
+ uses: coverallsapp/github-action@v1.1.2
58
+ with:
59
+ github-token: ${{ secrets.GITHUB_TOKEN }}
60
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.env }}-${{ matrix.gemfile }}
61
+ parallel: true
62
+ finish:
63
+ needs: build
64
+ runs-on: ubuntu-latest
65
+ steps:
66
+ - name: Coveralls Finished
67
+ uses: coverallsapp/github-action@v1.1.2
68
+ with:
69
+ github-token: ${{ secrets.GITHUB_TOKEN }}
70
+ parallel-finished: true
data/.rubocop.yml CHANGED
@@ -1,12 +1,13 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - 'gemfiles/**/*'
4
- - 'omnibus-ridgepole/**/*'
3
+ - "gemfiles/**/*"
4
+ - "omnibus-ridgepole/**/*"
5
+ - "vendor/bundle/**/*"
5
6
  TargetRubyVersion: 2.4
6
7
  NewCops: enable
7
8
  Bundler/OrderedGems:
8
9
  Include:
9
- - 'Appraisals'
10
+ - "Appraisals"
10
11
  Layout/HeredocIndentation:
11
12
  Enabled: false
12
13
  Metrics/AbcSize:
@@ -33,7 +34,7 @@ Style/GuardClause:
33
34
  Enabled: false
34
35
  Style/MixinUsage:
35
36
  Exclude:
36
- - 'spec/**/*'
37
+ - "spec/**/*"
37
38
  Style/TrailingCommaInHashLiteral:
38
39
  EnforcedStyleForMultiline: consistent_comma
39
40
  Layout/ClosingHeredocIndentation:
data/.simplecov ADDED
@@ -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/README.md CHANGED
@@ -7,7 +7,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/ridgepole.svg)](http://badge.fury.io/rb/ridgepole)
9
9
  [![Build Status](https://github.com/winebarrel/ridgepole/workflows/test/badge.svg?branch=0.9)](https://github.com/winebarrel/ridgepole/actions)
10
- [![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.9)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.8)
10
+ [![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.9)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.9)
11
11
 
12
12
  <details><summary>ChangeLog</summary>
13
13
 
@@ -127,12 +127,20 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
127
127
  * Support t.reference() foreign_key option ([pull#316](https://github.com/winebarrel/ridgepole/pull/316))
128
128
  * `>= 0.8.12`
129
129
  * Pluralize column specified by `references` ([pull#317](https://github.com/winebarrel/ridgepole/pull/317))
130
+ * `>= 0.8.13`
131
+ * Support `serial` and `bigserial` column types ([pull#321](https://github.com/winebarrel/ridgepole/pull/321))
130
132
  * `>= 0.9.0`
131
- * Remove `--mysql-alter-index` option ([pull#330](https://github.com/winebarrel/ridgepole/pull/330))
133
+ * Remove `--mysql-use-alter` option ([pull#330](https://github.com/winebarrel/ridgepole/pull/330))
132
134
  * Add `--table-hash-options` option ([pull#331](https://github.com/winebarrel/ridgepole/pull/331))
133
135
  * Support Rails 6.1 ([pull#323](https://github.com/winebarrel/ridgepole/pull/323))
134
- * Disable Rails 5.0 support([pull#335](https://github.com/winebarrel/ridgepole/pull/335))
135
- * Fix PK AUTO_INCREMENT change bug([pull#334](https://github.com/winebarrel/ridgepole/pull/334))
136
+ * Disable Rails 5.0 support ([pull#335](https://github.com/winebarrel/ridgepole/pull/335))
137
+ * Fix PK AUTO_INCREMENT change bug ([pull#334](https://github.com/winebarrel/ridgepole/pull/334))
138
+ * `>= 0.9.1`
139
+ * Support `t.foreign_key` ([pull#348](https://github.com/winebarrel/ridgepole/pull/348))
140
+ * `>= 0.9.2`
141
+ * Support `t.column index option` ([pull#353](https://github.com/winebarrel/ridgepole/pull/353))
142
+ * `>= 0.9.3`
143
+ * Fix `limit` option for `t.integer` ([pull#354](https://github.com/winebarrel/ridgepole/pull/453))
136
144
  </details>
137
145
 
138
146
  **Notice**
@@ -157,26 +165,6 @@ Or install it yourself as:
157
165
 
158
166
  $ gem install ridgepole
159
167
 
160
- ## Omnibus Package (deb/rpm)
161
-
162
- see https://github.com/winebarrel/ridgepole/releases.
163
-
164
- ### Install from deb
165
-
166
- ```sh
167
- sudo dpkg -i ridgepole_x.x.x+xxx-x_amd64.deb
168
- sudo apt install build-essential libmysqlclient-dev
169
- sudo /opt/ridgepole/embedded/bin/gem install mysql2
170
- ```
171
-
172
- ### Install from rpm
173
-
174
- ```sh
175
- sudo yum install ridgepole-x.x.x+xxx-x.el7.x86_64.rpm
176
- sudo yum install make gcc mariadb-devel
177
- sudo /opt/ridgepole/embedded/bin/gem install mysql2
178
- ```
179
-
180
168
  ## Help
181
169
  ```
182
170
  Usage: ridgepole [options]
@@ -314,8 +302,8 @@ create_table "parent", force: :cascade do |t|
314
302
  end
315
303
 
316
304
  create_table "child", id: false, force: :cascade do |t|
317
- t.integer "id"
318
- t.integer "parent_id"
305
+ t.bigint "id"
306
+ t.bigint "parent_id"
319
307
  end
320
308
 
321
309
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
@@ -367,7 +355,7 @@ add_index "books", ["author_id"], name: "idx_author_id", using: :btree
367
355
 
368
356
  execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
369
357
  # Execute SQL only if there is no foreign key
370
- c.raw_connection.query(<<-SQL).each.length.zero?
358
+ c.raw_connection.query(<<-SQL).each.size.zero?
371
359
  SELECT 1 FROM information_schema.key_column_usage
372
360
  WHERE TABLE_SCHEMA = 'bookshelf'
373
361
  AND CONSTRAINT_NAME = 'fk_author' LIMIT 1
@@ -466,6 +454,3 @@ bundle exec appraisal activerecord-5.1 rake
466
454
  * https://github.com/winebarrel/ridgepole-example
467
455
  * https://github.com/winebarrel/ridgepole-example/pull/1
468
456
  * https://github.com/winebarrel/ridgepole-example/pull/2
469
-
470
- ## Similar tools
471
- * [Codenize.tools](http://codenize.tools/)
data/bin/ridgepole CHANGED
@@ -147,8 +147,6 @@ ARGV.options do |opt|
147
147
  opt.on('', '--create-table-with-index') { options[:create_table_with_index] = true }
148
148
 
149
149
  opt.on('', '--mysql-dump-auto-increment') do
150
- 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')
151
-
152
150
  options[:mysql_dump_auto_increment] = true
153
151
  end
154
152
 
@@ -159,7 +159,7 @@ module Ridgepole
159
159
  to.delete(:collation)
160
160
  end
161
161
 
162
- pk_attrs = build_primary_key_attrs_if_changed(from, to, table_name)
162
+ pk_attrs = build_primary_key_attrs_if_changed(from, to)
163
163
  if pk_attrs
164
164
  if @options[:allow_pk_change]
165
165
  if from[:id] == false
@@ -207,20 +207,20 @@ module Ridgepole
207
207
  { type: type, options: options }
208
208
  end
209
209
 
210
- 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)
211
211
  normalize_column_options!(from_attrs, primary_key)
212
212
  normalize_column_options!(to_attrs, primary_key)
213
213
 
214
- 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)
215
215
  new_to_attrs
216
216
  end
217
217
 
218
- def build_primary_key_attrs_if_changed(from, to, table_name)
218
+ def build_primary_key_attrs_if_changed(from, to)
219
219
  from_column_attrs = convert_to_primary_key_attrs(from.slice(*PRIMARY_KEY_OPTIONS))
220
220
  to_column_attrs = convert_to_primary_key_attrs(to.slice(*PRIMARY_KEY_OPTIONS))
221
221
  return if from_column_attrs == to_column_attrs
222
222
 
223
- 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)
224
224
  end
225
225
 
226
226
  def scan_definition_change(from, to, from_indices, table_name, table_options, table_delta)
@@ -242,7 +242,7 @@ module Ridgepole
242
242
  next if ignore_column
243
243
 
244
244
  if from_attrs
245
- to_attrs = build_attrs_if_changed(to_attrs, from_attrs, table_name)
245
+ to_attrs = build_attrs_if_changed(to_attrs, from_attrs)
246
246
  if to_attrs
247
247
  definition_delta[:change] ||= {}
248
248
  definition_delta[:change][column_name] = to_attrs
@@ -399,9 +399,13 @@ module Ridgepole
399
399
  if Ridgepole::ConnectionAdapters.mysql?
400
400
  opts[:unsigned] = false unless opts.key?(:unsigned)
401
401
 
402
- if (attrs[:type] == :integer) && (opts[:limit] == Ridgepole::DefaultsLimit.default_limit(:bigint, @options))
403
- attrs[:type] = :bigint
404
- opts.delete(:limit)
402
+ if attrs[:type] == :integer && opts[:limit]
403
+ min = Ridgepole::DefaultsLimit.default_limit(:integer, @options)
404
+ max = Ridgepole::DefaultsLimit.default_limit(:bigint, @options)
405
+ if min < opts[:limit] && opts[:limit] <= max
406
+ attrs[:type] = :bigint
407
+ opts.delete(:limit)
408
+ end
405
409
  end
406
410
 
407
411
  if opts[:size] && (attrs[:type] == :text || attrs[:type] == :blob || attrs[:type] == :binary)
@@ -471,7 +475,7 @@ module Ridgepole
471
475
  # XXX: MySQL only?
472
476
  # https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L760
473
477
  # https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb#L102
474
- def fix_change_column_options(table_name, from_attrs, to_attrs)
478
+ def fix_change_column_options(from_attrs, to_attrs)
475
479
  # default: 0, null: false -> default: nil, null: false | default: nil
476
480
  # default: 0, null: false -> null: false | default: nil
477
481
  # default: 0, null: false -> default: nil, null: true | default: nil, null: true
@@ -486,10 +490,6 @@ module Ridgepole
486
490
  to_attrs[:options].delete(:null)
487
491
  end
488
492
 
489
- if Ridgepole::ConnectionAdapters.mysql? && ActiveRecord::VERSION::STRING.start_with?('5.0.')
490
- 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)
491
- end
492
-
493
493
  to_attrs
494
494
  end
495
495
 
@@ -13,14 +13,17 @@ module Ridgepole
13
13
 
14
14
  def column(name, type, options = {})
15
15
  name = name.to_s
16
+ index_options = options.key?(:index) ? options.delete(:index) : false
16
17
 
17
18
  @__definition[name] = {
18
19
  type: type,
19
20
  options: options,
20
21
  }
22
+
23
+ index(name, index_options.is_a?(Hash) ? index_options : {}) if index_options
21
24
  end
22
25
 
23
- DEFAULT_PRIMARY_KEY_TYPE = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.1') ? :bigint : :integer
26
+ DEFAULT_PRIMARY_KEY_TYPE = :bigint
24
27
 
25
28
  TYPES = {
26
29
  # https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L274
@@ -120,6 +123,10 @@ module Ridgepole
120
123
  @base.add_index(@table_name, name, options)
121
124
  end
122
125
 
126
+ def foreign_key(name, options = {})
127
+ @base.add_foreign_key(@table_name, name, options)
128
+ end
129
+
123
130
  def timestamps(*args)
124
131
  options = { null: false }.merge(args.extract_options!)
125
132
  column(:created_at, :datetime, options)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ridgepole
4
- VERSION = '0.9.0.beta'
4
+ VERSION = '0.9.3'
5
5
  end
data/ridgepole.gemspec CHANGED
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_development_dependency 'appraisal', '>= 2.2.0'
28
28
  spec.add_development_dependency 'bundler'
29
- spec.add_development_dependency 'coveralls'
30
29
  spec.add_development_dependency 'erbh', '>= 0.1.2'
31
30
  spec.add_development_dependency 'hash_modern_inspect', '>= 0.1.1'
32
31
  spec.add_development_dependency 'hash_order_helper', '>= 0.1.6'
@@ -36,7 +35,9 @@ Gem::Specification.new do |spec|
36
35
  spec.add_development_dependency 'rspec', '>= 3.0.0'
37
36
  spec.add_development_dependency 'rspec-match_fuzzy', '>= 0.1.3'
38
37
  spec.add_development_dependency 'rspec-match_ruby', '>= 0.1.3'
39
- spec.add_development_dependency 'rubocop', '>= 1.7.0'
38
+ spec.add_development_dependency 'rubocop', '1.9.1'
40
39
  spec.add_development_dependency 'rubocop-rake', '>= 0.5.1'
41
40
  spec.add_development_dependency 'rubocop-rspec', '>= 2.1.0'
41
+ spec.add_development_dependency 'simplecov'
42
+ spec.add_development_dependency 'simplecov-lcov'
42
43
  end
data/spec/erb_helper.rb CHANGED
@@ -14,11 +14,7 @@ ERBh.define_method(:i) do |obj|
14
14
  end
15
15
 
16
16
  ERBh.define_method(:cond) do |conds, m, e = nil|
17
- if conds.is_a?(Hash)
18
- conds.find do |c, _|
19
- condition(c)
20
- end&.last || m
21
- elsif condition(conds)
17
+ if condition(conds)
22
18
  m
23
19
  else
24
20
  e || (begin
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe 'Ridgepole::Client (with integer pk)', condition: '>= 5.1.0' do
3
+ describe 'Ridgepole::Client (with integer pk)' do
4
4
  context 'when with id:integer' do
5
5
  let(:dsl) do
6
6
  <<-RUBY
@@ -4,22 +4,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
4
4
  context 'when change column (add collation)' do
5
5
  let(:actual_dsl) do
6
6
  erbh(<<-ERB)
7
- create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
7
+ create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
8
8
  t.integer "emp_no", null: false
9
9
  t.integer "club_id", null: false, unsigned: true
10
10
  t.string "string", null: false, collation: "ascii_bin"
11
- t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false
11
+ t.text "text", null: false
12
12
  end
13
13
  ERB
14
14
  end
15
15
 
16
16
  let(:expected_dsl) do
17
17
  erbh(<<-ERB)
18
- create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
18
+ create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
19
19
  t.integer "emp_no", null: false
20
20
  t.integer "club_id", null: false, unsigned: true
21
21
  t.string "string", null: false, collation: "ascii_bin"
22
- t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false, collation: "utf8mb4_bin"
22
+ t.text "text", null: false, collation: "utf8mb4_bin"
23
23
  end
24
24
  ERB
25
25
  end
@@ -39,22 +39,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
39
39
  context 'when change column (delete collation)' do
40
40
  let(:actual_dsl) do
41
41
  erbh(<<-ERB)
42
- create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
42
+ create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
43
43
  t.integer "emp_no", null: false
44
44
  t.integer "club_id", null: false, unsigned: true
45
45
  t.string "string", null: false, collation: "ascii_bin"
46
- t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false, collation: "utf8mb4_bin"
46
+ t.text "text", null: false, collation: "utf8mb4_bin"
47
47
  end
48
48
  ERB
49
49
  end
50
50
 
51
51
  let(:expected_dsl) do
52
52
  erbh(<<-ERB)
53
- create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
53
+ create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
54
54
  t.integer "emp_no", null: false
55
55
  t.integer "club_id", null: false, unsigned: true
56
56
  t.string "string", null: false, collation: "ascii_bin"
57
- t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false
57
+ t.text "text", null: false
58
58
  end
59
59
  ERB
60
60
  end
@@ -74,22 +74,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
74
74
  context 'when change column (change collation)' do
75
75
  let(:actual_dsl) do
76
76
  erbh(<<-ERB)
77
- create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
77
+ create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
78
78
  t.integer "emp_no", null: false
79
79
  t.integer "club_id", null: false, unsigned: true
80
80
  t.string "string", null: false, collation: "ascii_bin"
81
- t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false, collation: "utf8mb4_bin"
81
+ t.text "text", null: false, collation: "utf8mb4_bin"
82
82
  end
83
83
  ERB
84
84
  end
85
85
 
86
86
  let(:expected_dsl) do
87
87
  erbh(<<-ERB)
88
- create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
88
+ create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
89
89
  t.integer "emp_no", null: false
90
90
  t.integer "club_id", null: false, unsigned: true
91
91
  t.string "string", null: false, collation: "utf8mb4_bin"
92
- t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false, collation: "ascii_bin"
92
+ t.text "text", null: false, collation: "ascii_bin"
93
93
  end
94
94
  ERB
95
95
  end
@@ -109,11 +109,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
109
109
  context 'when change column (no change collation)' do
110
110
  let(:actual_dsl) do
111
111
  erbh(<<-ERB)
112
- create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
112
+ create_table "employee_clubs", <%= i cond("< 6.1", { id: :bigint, unsigned: true }, { id: { type: :bigint, unsigned: true } }) %>, force: :cascade do |t|
113
113
  t.integer "emp_no", null: false
114
114
  t.integer "club_id", null: false, unsigned: true
115
115
  t.string "string", null: false, collation: "ascii_bin"
116
- t.text "text", <%= i cond(5.0, limit: 65535) %>, null: false, collation: "utf8mb4_bin"
116
+ t.text "text", null: false, collation: "utf8mb4_bin"
117
117
  end
118
118
  ERB
119
119
  end