ridgepole 0.7.2 → 0.7.3.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40108f2b75644df8ce23f3d8a1aa0ee2107aa25c
4
- data.tar.gz: fa253124674f5d34a96b0db3ba0e7594cbf42fdb
3
+ metadata.gz: 3d1090705cdbaf9295339b121d07f08efd6fdbc7
4
+ data.tar.gz: 781eb9b40326854690496a54e120e51fbf98b33d
5
5
  SHA512:
6
- metadata.gz: 5a12b6e017baf87cca9aae8b817c503efa4dfffbcffc7b2ffc5ab9e96278bbbebe0d7f06d8af034da55a2dd20fae70d35a8d4ba4b70f327ae95f9690f564aff3
7
- data.tar.gz: ac5e4ef666a799b883f87238a4b35cd48d47b8e04d67152205c3ce19392f425d98126de95274ee660cb474097421f85fcfe29f0df05c7b5c40f0e15448f1ba21
6
+ metadata.gz: 6b94add224450fbc51140fe4acf7e7ce34bb654dcc88c61fcf54edabd356d4e72bdd78ec5d8a13c0d7b893e39631a3395e1af31a5f946fa28d9508358caecf4f
7
+ data.tar.gz: f9bb43e119c95da180813260fe620e2b57bd8af2d7ae0fbebd64f80c1fb65ba94856b81f1d0fefa5c064e76c68a0eb7dd17ad6fb81c530a9c4cf4f04668bf87c
data/README.md CHANGED
@@ -82,6 +82,8 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
82
82
  * Add `--mysql-dump-auto-increment` option (`rails >= 5.1`)
83
83
  * `>= 0.7.2`
84
84
  * Support Rails 5.2
85
+ * `>= 0.7.3`
86
+ * Add `--mysql-change-table-comment option` ([pull#166](https://github.com/winebarrel/ridgepole/pull/166))
85
87
 
86
88
  ## Installation
87
89
 
@@ -133,6 +135,7 @@ Usage: ridgepole [options]
133
135
  --index-removed-drop-column
134
136
  --skip-drop-table
135
137
  --mysql-change-table-options
138
+ --mysql-change-table-comment
136
139
  --check-relation-type DEF_PK
137
140
  --ignore-table-comment
138
141
  --skip-column-comment-change
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  $: << File.expand_path('../../lib', __FILE__)
3
- require 'rubygems'
4
3
  require 'yaml'
5
4
  require 'optparse'
6
5
  require 'fileutils'
@@ -121,6 +120,7 @@ ARGV.options do |opt|
121
120
  opt.on('', '--index-removed-drop-column') { options[:index_removed_drop_column] = true }
122
121
  opt.on('', '--skip-drop-table') { options[:skip_drop_table] = true }
123
122
  opt.on('', '--mysql-change-table-options') { options[:mysql_change_table_options] = true }
123
+ opt.on('', '--mysql-change-table-comment') { options[:mysql_change_table_comment] = true }
124
124
  opt.on('', '--check-relation-type DEF_PK') {|v| options[:check_relation_type] = v }
125
125
  opt.on('', '--ignore-table-comment') { options[:ignore_table_comment] = true }
126
126
  opt.on('', '--skip-column-comment-change') { options[:skip_column_comment_change] = true }
@@ -239,7 +239,7 @@ begin
239
239
  else
240
240
  logger.verbose_info('# Update schema')
241
241
 
242
- differ, out = delta.migrate(
242
+ differ, _out = delta.migrate(
243
243
  :external_script => options[:external_script],
244
244
  :alter_extra => options[:alter_extra]
245
245
  )
@@ -249,17 +249,17 @@ begin
249
249
  logger.info('No change')
250
250
  end
251
251
  when :diff
252
- diff_files = diff_files.map do |file|
253
- if File.exist?(file)
254
- file_ext = File.extname(file)
252
+ diff_files = diff_files.map do |diff_file|
253
+ if File.exist?(diff_file)
254
+ file_ext = File.extname(diff_file)
255
255
 
256
256
  if %w(.yml .yaml).include?(file_ext)
257
- Ridgepole::Config.load(file, env)
257
+ Ridgepole::Config.load(diff_file, env)
258
258
  else
259
- File.open(file)
259
+ File.open(diff_file)
260
260
  end
261
261
  else
262
- YAML.load(file)
262
+ YAML.load(diff_file)
263
263
  end
264
264
  end
265
265
 
@@ -270,7 +270,7 @@ begin
270
270
  differ = delta.differ?
271
271
 
272
272
  if differ
273
- differ, out = delta.migrate
273
+ differ, _out = delta.migrate
274
274
  end
275
275
 
276
276
  if differ
@@ -288,12 +288,18 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
288
288
  buf.puts
289
289
  end
290
290
 
291
+ def append_change_table_comment(table_name, table_comment, buf)
292
+ comment_literal = "COMMENT=#{ActiveRecord::Base.connection.quote(table_comment)}"
293
+ append_change_table_options(table_name, comment_literal, buf)
294
+ end
295
+
291
296
  def append_change(table_name, attrs, buf, pre_buf_for_fk, post_buf_for_fk)
292
297
  definition = attrs[:definition] || {}
293
298
  primary_key_definition = attrs[:primary_key_definition] || {}
294
299
  indices = attrs[:indices] || {}
295
300
  foreign_keys = attrs[:foreign_keys] || {}
296
301
  table_options = attrs[:table_options]
302
+ table_comment = attrs[:table_comment]
297
303
 
298
304
  if not definition.empty? or not indices.empty? or not primary_key_definition.empty?
299
305
  append_change_table(table_name, buf) do
@@ -312,6 +318,10 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
312
318
  append_change_table_options(table_name, table_options, buf)
313
319
  end
314
320
 
321
+ if table_comment
322
+ append_change_table_comment(table_name, table_comment, buf)
323
+ end
324
+
315
325
  buf.puts
316
326
  pre_buf_for_fk.puts
317
327
  post_buf_for_fk.puts
@@ -1,5 +1,5 @@
1
1
  class Ridgepole::Diff
2
- PRIMARY_KEY_OPTIONS = %i(id limit default null precision scale collation unsigned comment).freeze
2
+ PRIMARY_KEY_OPTIONS = %i(id limit default null precision scale collation unsigned).freeze
3
3
 
4
4
  def initialize(options = {})
5
5
  @options = options
@@ -117,10 +117,18 @@ class Ridgepole::Diff
117
117
  end
118
118
  end
119
119
 
120
- if @options[:mysql_change_table_options] and from_options != to_options and Ridgepole::ConnectionAdapters.mysql?
121
- from.delete(:options)
122
- to.delete(:options)
123
- table_delta[:table_options] = to_options
120
+ if Ridgepole::ConnectionAdapters.mysql?
121
+ if @options[:mysql_change_table_options] and from_options != to_options
122
+ from.delete(:options)
123
+ to.delete(:options)
124
+ table_delta[:table_options] = to_options
125
+ end
126
+
127
+ if @options[:mysql_change_table_comment] and from[:comment] != to[:comment]
128
+ from.delete(:comment)
129
+ to_comment = to.delete(:comment)
130
+ table_delta[:table_comment] = to_comment
131
+ end
124
132
  end
125
133
 
126
134
  if @options[:dump_without_table_options]
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.7.2'
2
+ VERSION = '0.7.3.beta'
3
3
  end
@@ -46,6 +46,7 @@ describe 'ridgepole' do
46
46
  --index-removed-drop-column
47
47
  --skip-drop-table
48
48
  --mysql-change-table-options
49
+ --mysql-change-table-comment
49
50
  --check-relation-type DEF_PK
50
51
  --ignore-table-comment
51
52
  --skip-column-comment-change
@@ -0,0 +1,70 @@
1
+ describe 'Ridgepole::Client#diff -> migrate' do
2
+ let(:actual_dsl) {
3
+ erbh(<<-EOS)
4
+ create_table "employees", force: :cascade, comment: "old comment" do |t|
5
+ t.date "birth_date", null: false
6
+ t.string "first_name", limit: 14, null: false
7
+ t.string "last_name", limit: 16, null: false
8
+ t.string "gender", limit: 1, null: false
9
+ t.date "hire_date", null: false
10
+ end
11
+ EOS
12
+ }
13
+
14
+ let(:expected_dsl) {
15
+ erbh(<<-EOS)
16
+ create_table "employees", force: :cascade, comment: "new comment" do |t|
17
+ t.date "birth_date", null: false
18
+ t.string "first_name", limit: 14, null: false
19
+ t.string "last_name", limit: 16, null: false
20
+ t.string "gender", limit: 1, null: false
21
+ t.date "hire_date", null: false
22
+ end
23
+ EOS
24
+ }
25
+
26
+ before { subject.diff(actual_dsl).migrate }
27
+
28
+ context 'when ignore_table_comment option is false' do
29
+ subject { client }
30
+
31
+ it {
32
+ expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
33
+ [WARNING] No difference of schema configuration for table `employees` but table options differ.
34
+ from: {:comment=>"old comment"}
35
+ to: {:comment=>"new comment"}
36
+ EOS
37
+ delta = subject.diff(expected_dsl)
38
+ expect(delta.differ?).to be_falsey
39
+ expect(subject.dump).to match_ruby actual_dsl
40
+ delta.migrate
41
+ expect(subject.dump).to match_ruby actual_dsl
42
+ }
43
+ end
44
+
45
+ context 'when ignore_table_comment option is true' do
46
+ subject { client(ignore_table_comment: true) }
47
+
48
+ it {
49
+ expect(Ridgepole::Logger.instance).to_not receive(:warn)
50
+ delta = subject.diff(expected_dsl)
51
+ expect(delta.differ?).to be_falsey
52
+ expect(subject.dump).to match_ruby actual_dsl
53
+ delta.migrate
54
+ expect(subject.dump).to match_ruby actual_dsl
55
+ }
56
+ end
57
+
58
+ context 'when mysql_change_table_comment option is true' do
59
+ subject { client(mysql_change_table_comment: true) }
60
+
61
+ it {
62
+ expect(Ridgepole::Logger.instance).to_not receive(:warn)
63
+ delta = subject.diff(expected_dsl)
64
+ expect(delta.differ?).to be_truthy
65
+ expect(subject.dump).to match_ruby actual_dsl
66
+ delta.migrate
67
+ expect(subject.dump).to match_ruby expected_dsl
68
+ }
69
+ end
70
+ 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.2
4
+ version: 0.7.3.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2018-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -303,6 +303,7 @@ files:
303
303
  - spec/mysql/migrate/migrate_change_index7_spec.rb
304
304
  - spec/mysql/migrate/migrate_change_index8_spec.rb
305
305
  - spec/mysql/migrate/migrate_change_index_spec.rb
306
+ - spec/mysql/migrate/migrate_change_table_comment_spec.rb
306
307
  - spec/mysql/migrate/migrate_change_table_option_spec.rb
307
308
  - spec/mysql/migrate/migrate_check_relation_column_type_spec.rb
308
309
  - spec/mysql/migrate/migrate_create_index2_spec.rb
@@ -402,9 +403,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
402
403
  version: 2.2.7
403
404
  required_rubygems_version: !ruby/object:Gem::Requirement
404
405
  requirements:
405
- - - ">="
406
+ - - ">"
406
407
  - !ruby/object:Gem::Version
407
- version: '0'
408
+ version: 1.3.1
408
409
  requirements: []
409
410
  rubyforge_project:
410
411
  rubygems_version: 2.6.13
@@ -457,6 +458,7 @@ test_files:
457
458
  - spec/mysql/migrate/migrate_change_index7_spec.rb
458
459
  - spec/mysql/migrate/migrate_change_index8_spec.rb
459
460
  - spec/mysql/migrate/migrate_change_index_spec.rb
461
+ - spec/mysql/migrate/migrate_change_table_comment_spec.rb
460
462
  - spec/mysql/migrate/migrate_change_table_option_spec.rb
461
463
  - spec/mysql/migrate/migrate_check_relation_column_type_spec.rb
462
464
  - spec/mysql/migrate/migrate_create_index2_spec.rb