declare_schema 1.3.1 → 1.3.2

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: 3d5e780d92cb93c57b69a6c7641f7dd20fc52114b0b25a2e47ad662039457290
4
- data.tar.gz: a976df026f62e9a0512d71957898bddd077aa2ab8a63d63ddb8c114211df7060
3
+ metadata.gz: 474856e02a14224230a41cc4ef32234b8d20b69a647a30f810bce457c220261e
4
+ data.tar.gz: 13994a873d83d5bce533b71f36c3057a0a0caf8c7559f809091a7dc6627f5f7c
5
5
  SHA512:
6
- metadata.gz: 9845c4bf47ac17b28b4b4b4eb6070cdaf6a66102bee5649af99ad8de8ed8a151eb76e5b49cbf9322997d7b1a62db3c3104eafc497ff7b81d7245825813c9bb48
7
- data.tar.gz: 15eb4cc2bf1181bf8b2cd7152a203ceb6fc568920f0bf185a52dca4d5f65e1ead26ca29424c448834739b03fde489f74b7efe13ef01d9e643a6d0e4819691d52
6
+ metadata.gz: 7b298b54b826e8bb464c544ab2015ddca0a761cda03f03724598158617b89cef0b0f19521a103898e92157cad11d32e9feb71c1293a36bbc2c3a666c123d444f
7
+ data.tar.gz: 5e0c12a370ed83eeb31f398e124597a00dd7b5872d08b8c47e1eb2fb5842c6b295b251d2b58ff26619af8c92ca0342ac8bf585652c9822409dfab40798d0f086
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 3.2.2
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ 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.2] - 2024-01-12
8
+ ### Fixed
9
+ - Fix bug in migrator when table option definitions differ
10
+
7
11
  ## [1.3.1] - 2023-10-12
8
12
  ### Fixed
9
13
  - Fix bug in default index name when table name + __ + column suffix exceeds `DeclareSchema.max_index_and_constraint_name_length`.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.3.1)
4
+ declare_schema (1.3.2)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -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"
4
+ VERSION = "1.3.2"
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
@@ -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
4
+ version: 1.3.2
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-12 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