declare_schema 1.3.1 → 1.3.2
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 +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/declare_schema/model/table_options_definition.rb +3 -0
- data/lib/declare_schema/schema_change/table_change.rb +8 -1
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +2 -2
- data/spec/lib/declare_schema/schema_change/table_change_spec.rb +41 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 474856e02a14224230a41cc4ef32234b8d20b69a647a30f810bce457c220261e
|
4
|
+
data.tar.gz: 13994a873d83d5bce533b71f36c3057a0a0caf8c7559f809091a7dc6627f5f7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b298b54b826e8bb464c544ab2015ddca0a761cda03f03724598158617b89cef0b0f19521a103898e92157cad11d32e9feb71c1293a36bbc2c3a666c123d444f
|
7
|
+
data.tar.gz: 5e0c12a370ed83eeb31f398e124597a00dd7b5872d08b8c47e1eb2fb5842c6b295b251d2b58ff26619af8c92ca0342ac8bf585652c9822409dfab40798d0f086
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.2.
|
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
@@ -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
|
-
|
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
|
@@ -548,8 +548,8 @@ module Generators
|
|
548
548
|
else
|
549
549
|
[
|
550
550
|
::DeclareSchema::SchemaChange::TableChange.new(current_table_name,
|
551
|
-
old_options_definition.
|
552
|
-
new_options_definition.
|
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)
|
11
|
-
let(:old_options)
|
12
|
-
let(:new_options)
|
13
|
-
|
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
|
-
|
17
|
-
it '
|
18
|
-
|
19
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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.
|
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:
|
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.
|
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
|