declare_schema 1.3.1.colin.1 → 1.3.2.rp.1

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
  SHA256:
3
- metadata.gz: a0f533d7dc8d88f7a84002c3f683cc4afa1a50af764fb6f478fb6d21f06d3d00
4
- data.tar.gz: a033eb5411618bf7d0e1beb51176aa682a7362820df942df52f9d87818875237
3
+ metadata.gz: 177fdef8d03843627f34a461487ec92d222e5d18efe3a4881bc1b4326a069e99
4
+ data.tar.gz: d5dac684d51bfad5e7e92214fcc9a7e1b4020a70aa4cd2fd8a5bbb0c718f1c71
5
5
  SHA512:
6
- metadata.gz: eb1c42caab31adbd01450a2c94c7a15d4c535bc1e8b89a50370f95796adad9bc21d297969c463febc77f7ba3f64ccd4a79cb68480bf02baff2f864302f435cd1
7
- data.tar.gz: f2882b79e6eadd987d064e9adb742e5d2adea31c1de9a716fdd5a05a1c6a9e54491b8d5825ef9f310038e430ca2c54af08dad0c389202ff101a659065dc6b942
6
+ metadata.gz: 7bdc6408f561f9aa70dad7e2208ae2022f8b30adce1c1350f598cae1c93b4dbd9f65f61a97324282fad9f0d2dd2126e90dda199781040f08564bc6998121c670
7
+ data.tar.gz: 1057a1c6202b77f5854b119208227c7a7341f2c3d0cab7eb7a743322ebb60bddaec4eb77671d60035e610789a9d73c7b345868262aebe0e6052ff2c17c8a6d81
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 3.2.2
data/CHANGELOG.md CHANGED
@@ -4,9 +4,13 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
5
  Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [1.3.1] - Unreleased
7
+ ## [1.3.2] - Unreleased
8
8
  ### Fixed
9
- - Fix bug in default index anme when table name + __ + column suffix exceeds `DeclareSchema.max_index_and_constraint_name_length`.
9
+ - Fix bug in migrator when table option definitions differ
10
+
11
+ ## [1.3.1] - 2023-10-12
12
+ ### Fixed
13
+ - Fix bug in default index name when table name + __ + column suffix exceeds `DeclareSchema.max_index_and_constraint_name_length`.
10
14
  In this case we truncate the table name and append part of its hash.
11
15
 
12
16
  ## [1.3.0] - 2023-07-10
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.3.1.colin.1)
4
+ declare_schema (1.3.2.rp.1)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -66,7 +66,7 @@ module DeclareSchema
66
66
  break index_name
67
67
  end
68
68
  end or raise IndexNameTooLongError,
69
- "Index '#{index_name}' exceeds configured limit of #{DeclareSchema.max_index_and_constraint_name_length} characters."
69
+ "Default index name '#{index_name}' exceeds configured limit of #{DeclareSchema.max_index_and_constraint_name_length} characters. Use the `name:` option to give it a shorter name, or adjust DeclareSchema.max_index_and_constraint_name_length if you know your database can accept longer names."
70
70
  end
71
71
 
72
72
  private
@@ -57,6 +57,9 @@ module DeclareSchema
57
57
  @key ||= [table_name, table_options].map(&:to_s)
58
58
  end
59
59
 
60
+ # Flatten out/join table options as a space-separated string
61
+ #
62
+ # @return [String] Table options as a string
60
63
  def settings
61
64
  @settings ||= table_options.map { |name, value| "#{TABLE_OPTIONS_TO_SQL_MAPPINGS[name]} #{value}" if value }.compact.join(" ")
62
65
  end
@@ -5,8 +5,15 @@ require_relative 'base'
5
5
  module DeclareSchema
6
6
  module SchemaChange
7
7
  class TableChange < Base
8
+
9
+ # @param [String] table_name The name of the table being changed
10
+ # @param [Hash] old_options The old/existing table option definitions
11
+ # @param [Hash] new_options The new/existing table option definitions
8
12
  def initialize(table_name, old_options, new_options)
9
- @table_name = table_name
13
+ old_options.is_a?(Hash) or raise ArgumentError, "old_options must be a Hash but is: #{old_options.inspect}"
14
+ new_options.is_a?(Hash) or raise ArgumentError, "new_options must be a Hash but is: #{new_options.inspect}"
15
+
16
+ @table_name = table_name
10
17
  @old_options = old_options
11
18
  @new_options = new_options
12
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.3.1.colin.1"
4
+ VERSION = "1.3.2.rp.1"
5
5
  end
@@ -548,8 +548,8 @@ module Generators
548
548
  else
549
549
  [
550
550
  ::DeclareSchema::SchemaChange::TableChange.new(current_table_name,
551
- old_options_definition.settings,
552
- new_options_definition.settings)
551
+ old_options_definition.table_options,
552
+ new_options_definition.table_options)
553
553
  ]
554
554
  end
555
555
  end
@@ -156,6 +156,7 @@ RSpec.describe DeclareSchema::Model::IndexDefinition do
156
156
  50 => 'user_domains4814__last_name_first_name_middle_name',
157
157
  51 => 'user_domains_4814__last_name_first_name_middle_name',
158
158
  52 => 'user_domains_extra__last_name_first_name_middle_name',
159
+ 53 => 'user_domains_extra__last_name_first_name_middle_name',
159
160
  }.each do |len, index_name|
160
161
  context "with max_index_and_constraint_name_length of #{len}" do
161
162
  let(:max_index_and_constraint_name_length) { len }
@@ -169,7 +170,7 @@ RSpec.describe DeclareSchema::Model::IndexDefinition do
169
170
 
170
171
  it 'raises' do
171
172
  expect { subject }.to raise_exception(DeclareSchema::Model::IndexDefinition::IndexNameTooLongError,
172
- /Index '__last_name_first_name_middle_name' exceeds configured limit of 33 characters/)
173
+ /Default index name '__last_name_first_name_middle_name' exceeds configured limit of 33 characters\. Use the `name:` option to give it a shorter name, or adjust DeclareSchema\.max_index_and_constraint_name_length/i)
173
174
  end
174
175
  end
175
176
  end
@@ -7,23 +7,52 @@ RSpec.describe DeclareSchema::SchemaChange::TableChange do
7
7
  load File.expand_path('../prepare_testapp.rb', __dir__)
8
8
  end
9
9
 
10
- let(:table_name) { 'networks' }
11
- let(:old_options) { { charset: 'utf8', collation: 'utf8_ci' } }
12
- let(:new_options) { { charset: 'utf8mb4', collation: 'utf8mb4_bin' } }
13
- subject { described_class.new(table_name, old_options, new_options) }
10
+ let(:table_name) { 'networks' }
11
+ let(:old_options) { { charset: 'utf8', collation: 'utf8_ci' } }
12
+ let(:new_options) { { charset: 'utf8mb4', collation: 'utf8mb4_bin' } }
13
+ let(:options_string) { 'CHARACTER SET utf8mb4 COLLATE utf8mb4_bin' }
14
+ subject { described_class.new(table_name, old_options, new_options) }
14
15
 
15
16
  describe '#up/down' do
16
- describe '#up' do
17
- it 'responds with command' do
18
- statement = "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name)} CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"
19
- expect(subject.up).to eq("execute #{statement.inspect}\n")
17
+ context 'when Hashes are used to construct the TableChange' do
18
+ it 'does not raise' do
19
+ described_class.new(table_name, old_options, new_options)
20
+ end
21
+
22
+ describe '#up' do
23
+ it 'responds with command' do
24
+ statement = "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name)} CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"
25
+ expect(subject.up).to eq("execute #{statement.inspect}\n")
26
+ end
27
+ end
28
+
29
+ describe '#down' do
30
+ it 'responds with command' do
31
+ statement = "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name)} CHARACTER SET utf8 COLLATE utf8_ci"
32
+ expect(subject.down).to eq("execute #{statement.inspect}\n")
33
+ end
20
34
  end
21
35
  end
22
36
 
23
- describe '#down' do
24
- it 'responds with command' do
25
- statement = "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name)} CHARACTER SET utf8 COLLATE utf8_ci"
26
- expect(subject.down).to eq("execute #{statement.inspect}\n")
37
+ context 'when Strings are used to construct the TableChange' do
38
+ context 'when old_options is a string' do
39
+ subject { described_class.new(table_name, options_string, new_options) }
40
+
41
+ it 'raises' do
42
+ expect {
43
+ subject
44
+ }.to raise_exception(ArgumentError, /old_options must be a Hash but is: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"/)
45
+ end
46
+ end
47
+
48
+ context 'when new_options is a string' do
49
+ subject { described_class.new(table_name, old_options, options_string) }
50
+
51
+ it 'raises' do
52
+ expect {
53
+ subject
54
+ }.to raise_exception(ArgumentError, /new_options must be a Hash but is: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"/)
55
+ end
27
56
  end
28
57
  end
29
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: declare_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1.colin.1
4
+ version: 1.3.2.rp.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2024-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: 1.3.6
143
143
  requirements: []
144
- rubygems_version: 3.4.6
144
+ rubygems_version: 3.4.10
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Database schema declaration and migration generator for Rails