ridgepole 3.0.0 → 3.0.1

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
  SHA256:
3
- metadata.gz: 2f47329a42a0f1fae570e9c37d7ac12b21b2d542dd1f2a461c43e6f14813dd44
4
- data.tar.gz: 1c0b84ce805e2aecb9fd12b5fdb5be9f9657468ba1f80bc6cee8d0611863458c
3
+ metadata.gz: cccf60348e4baf7ac0988edb6e68bc14b0cbb945a167e4a2e6d9ef71d5e35c8a
4
+ data.tar.gz: 9ff98ff1c8a823fe988129816db0bcc4dac1c9f1a5c565faa47ef8aa3852507b
5
5
  SHA512:
6
- metadata.gz: 396a8059a3db35168cda1fba372e923561356230a7f8ffa8e0ee50bfbf51960c3f39b3e6469c34f0b2221d855954ecad20893f5d3d4b9f292893de38b5f758ba
7
- data.tar.gz: f3a4bad14973e545a1a35593b08d26717f15fe5b7b9a32c2178efb84e8b6e99058dd377ae9a7f2ab54737b6cda7d8e678070362c6cce7f4dadc3ca37f7153319
6
+ metadata.gz: f0dc88f6715d8500bb4edfa106140ea7ca6cd1c207edd51cf65d12a76453ed2eb3d575ee8b73d7d96a0e386c4dec3e34ff985bf81bcc7a8026529946c3b40f74
7
+ data.tar.gz: 750a855f189b49cafbc35db15d227b2b2cbf8f2a545075b46a390697f768b3b9c606d9c6403c74c3491fdc76a408944aba2a3a2f7781dd475d096b82ec6f330a
data/.rubocop.yml CHANGED
@@ -58,3 +58,5 @@ Style/OptionalBooleanParameter:
58
58
  Enabled: false
59
59
  Gemspec/DevelopmentDependencies:
60
60
  Enabled: false
61
+ Lint/LiteralInInterpolation:
62
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## 3.0
4
4
 
5
+ ### 3.0.1 (2025/01/12)
6
+
7
+ - Normalize `check_constraint` [pull#512](https://github.com/ridgepole/ridgepole/pull/512)
8
+ - Support composite foreign key for non-primary key [pull#518](https://github.com/ridgepole/ridgepole/pull/518)
9
+
5
10
  ### 3.0.0 (2024/11/10)
6
11
 
7
12
  - Support Rails 8.0 [pull#504](https://github.com/ridgepole/ridgepole/pull/504)
data/README.md CHANGED
@@ -6,8 +6,8 @@ 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)](https://badge.fury.io/rb/ridgepole)
9
- [![Build Status](https://github.com/ridgepole/ridgepole/workflows/test/badge.svg?branch=1.2)](https://github.com/ridgepole/ridgepole/actions)
10
- [![Coverage Status](https://coveralls.io/repos/github/ridgepole/ridgepole/badge.svg?branch=1.2)](https://coveralls.io/github/ridgepole/ridgepole?branch=1.2)
9
+ [![test](https://github.com/ridgepole/ridgepole/actions/workflows/test.yml/badge.svg)](https://github.com/ridgepole/ridgepole/actions/workflows/test.yml)
10
+ [![Coverage Status](https://coveralls.io/repos/github/ridgepole/ridgepole/badge.svg?branch=3.0)](https://coveralls.io/github/ridgepole/ridgepole?branch=3.0)
11
11
 
12
12
  > [!note]
13
13
  > * ridgepole v3.0.0
@@ -3,6 +3,7 @@
3
3
  module Ridgepole
4
4
  class Diff
5
5
  PRIMARY_KEY_OPTIONS = %i[id limit default null precision scale collation unsigned].freeze
6
+ REGEX_COLUMN_IDENTIFIER_QUOTATION_CHARS = '"`'
6
7
 
7
8
  def initialize(options = {})
8
9
  @options = options
@@ -486,7 +487,7 @@ module Ridgepole
486
487
  from_attrs = from.delete(name)
487
488
 
488
489
  if from_attrs
489
- if from_attrs != to_attrs
490
+ if normalize_check_constraint(from_attrs) != normalize_check_constraint(to_attrs)
490
491
  check_constraints_delta[:add] ||= {}
491
492
  check_constraints_delta[:add][name] = to_attrs
492
493
 
@@ -509,6 +510,12 @@ module Ridgepole
509
510
  table_delta[:check_constraints] = check_constraints_delta unless check_constraints_delta.empty?
510
511
  end
511
512
 
513
+ def normalize_check_constraint(attr)
514
+ attr = attr.dup
515
+ attr[:expression] = attr[:expression].delete(REGEX_COLUMN_IDENTIFIER_QUOTATION_CHARS)
516
+ attr
517
+ end
518
+
512
519
  def scan_exclusion_constraints_change(from, to, table_delta)
513
520
  from = (from || {}).dup
514
521
  to = (to || {}).dup
@@ -77,8 +77,16 @@ module Ridgepole
77
77
  from_table = from_table.to_s
78
78
  to_table = to_table.to_s
79
79
  options[:name] = options[:name].to_s if options[:name]
80
- options[:primary_key] = options[:primary_key].to_s if options[:primary_key]
81
- options[:column] = options[:column].to_s if options[:column]
80
+ if options[:primary_key].is_a?(Array)
81
+ options[:primary_key] = options[:primary_key].map(&:to_s)
82
+ elsif options[:primary_key]
83
+ options[:primary_key] = options[:primary_key].to_s
84
+ end
85
+ if options[:column].is_a?(Array)
86
+ options[:column] = options[:column].map(&:to_s)
87
+ elsif options[:column]
88
+ options[:column] = options[:column].to_s
89
+ end
82
90
  @__definition[from_table] ||= {}
83
91
  @__definition[from_table][:foreign_keys] ||= {}
84
92
  idx = options[:name] || [from_table, to_table, options[:column]]
@@ -36,14 +36,22 @@ module Ridgepole
36
36
 
37
37
  attrs[:foreign_keys].each_value do |foreign_key_attrs|
38
38
  fk_index = foreign_key_attrs[:options][:column] || "#{foreign_key_attrs[:to_table].singularize}_id"
39
- next if attrs[:indices]&.any? { |_k, v| v[:column_name].first == fk_index }
40
- # NOTE: For composite primary keys, the first column of the primary key is used as the foreign key index
41
- next if Array(attrs[:options][:primary_key]).first == fk_index
39
+ next if attrs[:indices]&.any? { |_, v| match_column_name?(v[:column_name], fk_index) }
40
+ next if match_column_name?(attrs[:options][:primary_key], fk_index)
42
41
 
43
42
  raise("The column `#{fk_index}` of the table `#{table_name}` has a foreign key but no index. " \
44
43
  'Although InnoDB creates an index automatically, ' \
45
44
  'please add one explicitly in order for ridgepole to manage it.')
46
45
  end
47
46
  end
47
+
48
+ def match_column_name?(index_column_name, fk_index)
49
+ if fk_index.is_a?(Array)
50
+ index_column_name == fk_index
51
+ else
52
+ # NOTE: For composite primary keys, the first column of the primary key is used as the foreign key index
53
+ Array(index_column_name).first == fk_index
54
+ end
55
+ end
48
56
  end
49
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ridgepole
4
- VERSION = '3.0.0'
4
+ VERSION = '3.0.1'
5
5
  end
data/ridgepole.gemspec CHANGED
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency 'rspec', '>= 3.0.0'
41
41
  spec.add_development_dependency 'rspec-match_fuzzy', '>= 0.2.0'
42
42
  spec.add_development_dependency 'rspec-match_ruby', '>= 0.1.3'
43
- spec.add_development_dependency 'rubocop', '1.68.0'
43
+ spec.add_development_dependency 'rubocop', '1.69.2'
44
44
  spec.add_development_dependency 'rubocop-rake', '>= 0.5.1'
45
45
  spec.add_development_dependency 'rubocop-rspec', '>= 2.1.0'
46
46
  spec.add_development_dependency 'simplecov'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-10 00:00:00.000000000 Z
10
+ date: 2025-01-12 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -232,14 +231,14 @@ dependencies:
232
231
  requirements:
233
232
  - - '='
234
233
  - !ruby/object:Gem::Version
235
- version: 1.68.0
234
+ version: 1.69.2
236
235
  type: :development
237
236
  prerelease: false
238
237
  version_requirements: !ruby/object:Gem::Requirement
239
238
  requirements:
240
239
  - - '='
241
240
  - !ruby/object:Gem::Version
242
- version: 1.68.0
241
+ version: 1.69.2
243
242
  - !ruby/object:Gem::Dependency
244
243
  name: rubocop-rake
245
244
  requirement: !ruby/object:Gem::Requirement
@@ -363,7 +362,6 @@ licenses:
363
362
  - MIT
364
363
  metadata:
365
364
  rubygems_mfa_required: 'true'
366
- post_install_message:
367
365
  rdoc_options: []
368
366
  require_paths:
369
367
  - lib
@@ -378,8 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
378
376
  - !ruby/object:Gem::Version
379
377
  version: '0'
380
378
  requirements: []
381
- rubygems_version: 3.5.20
382
- signing_key:
379
+ rubygems_version: 3.6.2
383
380
  specification_version: 4
384
381
  summary: Ridgepole is a tool to manage DB schema.
385
382
  test_files: []