declare_schema 1.3.5.colin.1 → 1.3.6.colin.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/declare_schema/model/habtm_model_shim.rb +8 -5
- data/lib/declare_schema/schema_change/column_add.rb +4 -2
- data/lib/declare_schema/version.rb +1 -1
- data/lib/declare_schema.rb +2 -2
- data/lib/generators/declare_schema/migration/migrator.rb +3 -3
- data/spec/lib/declare_schema/model/habtm_model_shim_spec.rb +4 -4
- data/spec/lib/declare_schema_spec.rb +4 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d91f7885d45e678a5bb4a5c97cfae29fd6333df27b516981de61f5056050b29
|
4
|
+
data.tar.gz: b4662bc25edc345d3321a2ef364b18b0c13d9e774a5155dfde7d378a61c12a24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b332e00969056fcf3e94da639e4c7b5aa4c0e4dceca8edce19a69577c98644c0330ca218825b66af032dba0040ba470800169c651749b04ac5d7de769ef593f5
|
7
|
+
data.tar.gz: b218aadc7d9bbc961281c2854c2ea0debeef971c59af2370a4244c1df5db5a36d542d18cf4b063529af5345a32e1b02cd14e51e37e6b44cc5cf3920b825df335
|
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.6] - 2024-01-22
|
8
|
+
### Fixed
|
9
|
+
- Add missing commits around connection: and Array check for composite declared primary key.
|
10
|
+
|
7
11
|
## [1.3.5] - 2024-01-22
|
8
12
|
### Fixed
|
9
13
|
- Make `default_charset=` and `default_collation=` lazy so they don't use the database connection to check the
|
data/Gemfile.lock
CHANGED
@@ -4,15 +4,17 @@ module DeclareSchema
|
|
4
4
|
module Model
|
5
5
|
class HabtmModelShim
|
6
6
|
class << self
|
7
|
-
def from_reflection(
|
8
|
-
new(
|
9
|
-
|
7
|
+
def from_reflection(reflection)
|
8
|
+
new(reflection.join_table,
|
9
|
+
[reflection.foreign_key, reflection.association_foreign_key],
|
10
|
+
[reflection.active_record.table_name, reflection.klass.table_name],
|
11
|
+
connection: reflection.active_record.connection)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
attr_reader :join_table, :foreign_keys, :parent_table_names
|
15
|
+
attr_reader :join_table, :foreign_keys, :parent_table_names, :connection
|
14
16
|
|
15
|
-
def initialize(join_table, foreign_keys, parent_table_names)
|
17
|
+
def initialize(join_table, foreign_keys, parent_table_names, connection:)
|
16
18
|
foreign_keys.is_a?(Array) && foreign_keys.size == 2 or
|
17
19
|
raise ArgumentError, "foreign_keys must be <Array[2]>; got #{foreign_keys.inspect}"
|
18
20
|
parent_table_names.is_a?(Array) && parent_table_names.size == 2 or
|
@@ -20,6 +22,7 @@ module DeclareSchema
|
|
20
22
|
@join_table = join_table
|
21
23
|
@foreign_keys = foreign_keys.sort # Rails requires these be in alphabetical order
|
22
24
|
@parent_table_names = @foreign_keys == foreign_keys ? parent_table_names : parent_table_names.reverse # match the above sort
|
25
|
+
@connection = connection
|
23
26
|
end
|
24
27
|
|
25
28
|
def _table_options
|
@@ -6,8 +6,10 @@ module DeclareSchema
|
|
6
6
|
module SchemaChange
|
7
7
|
class ColumnAdd < Base
|
8
8
|
def initialize(table_name, column_name, column_type, **column_options)
|
9
|
-
|
10
|
-
|
9
|
+
table_name.is_a?(String) || table_name.is_a?(Symbol) or raise ArgumentError, "must provide String|Symbol table_name; got #{table_name.inspect}"
|
10
|
+
column_name.is_a?(String) || column_name.is_a?(Symbol) or raise ArgumentError, "must provide String|Symbol column_name; got #{column_name.inspect}"
|
11
|
+
@table_name = table_name
|
12
|
+
@column_name = column_name
|
11
13
|
@column_type = column_type or raise ArgumentError, "must provide column_type"
|
12
14
|
@column_options = column_options
|
13
15
|
end
|
data/lib/declare_schema.rb
CHANGED
@@ -86,7 +86,7 @@ module DeclareSchema
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def default_charset
|
89
|
-
@default_charset
|
89
|
+
@default_charset ||= normalize_charset(@default_charset_before_normalization)
|
90
90
|
end
|
91
91
|
|
92
92
|
def default_collation=(collation)
|
@@ -96,7 +96,7 @@ module DeclareSchema
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def default_collation
|
99
|
-
@default_collation
|
99
|
+
@default_collation ||= normalize_collation(@default_collation_before_normalization)
|
100
100
|
end
|
101
101
|
|
102
102
|
def default_text_limit=(text_limit)
|
@@ -204,8 +204,8 @@ module Generators
|
|
204
204
|
end
|
205
205
|
end
|
206
206
|
# generate shims for HABTM models
|
207
|
-
habtm_tables.each do |name,
|
208
|
-
models_by_table_name[name] = ::DeclareSchema::Model::HabtmModelShim.from_reflection(
|
207
|
+
habtm_tables.each do |name, reflections|
|
208
|
+
models_by_table_name[name] = ::DeclareSchema::Model::HabtmModelShim.from_reflection(reflections.first)
|
209
209
|
end
|
210
210
|
model_table_names = models_by_table_name.keys
|
211
211
|
|
@@ -352,7 +352,7 @@ module Generators
|
|
352
352
|
|
353
353
|
db_columns = model.connection.columns(current_table_name).index_by(&:name)
|
354
354
|
if (pk = model._declared_primary_key.presence)
|
355
|
-
pk_was_in_db_columns = db_columns.delete(pk)
|
355
|
+
pk_was_in_db_columns = pk.is_a?(Array) || db_columns.delete(pk)
|
356
356
|
end
|
357
357
|
|
358
358
|
model_column_names = model.field_specs.keys.map(&:to_s)
|
@@ -11,6 +11,7 @@ RSpec.describe DeclareSchema::Model::HabtmModelShim do
|
|
11
11
|
let(:join_table) { "customers_users" }
|
12
12
|
let(:foreign_keys) { ["user_id", "customer_id"] }
|
13
13
|
let(:parent_table_names) { ["users", "customers"] }
|
14
|
+
let(:connection) { instance_double(ActiveRecord::Base.connection.class, "connection") }
|
14
15
|
|
15
16
|
before do
|
16
17
|
load File.expand_path('../prepare_testapp.rb', __dir__)
|
@@ -30,7 +31,8 @@ RSpec.describe DeclareSchema::Model::HabtmModelShim do
|
|
30
31
|
foreign_key: foreign_keys.first,
|
31
32
|
association_foreign_key: foreign_keys.last,
|
32
33
|
active_record: User,
|
33
|
-
class_name: 'Customer'
|
34
|
+
class_name: 'Customer',
|
35
|
+
klass: Customer) }
|
34
36
|
it 'returns a new object' do
|
35
37
|
result = described_class.from_reflection(reflection)
|
36
38
|
|
@@ -42,9 +44,7 @@ RSpec.describe DeclareSchema::Model::HabtmModelShim do
|
|
42
44
|
end
|
43
45
|
|
44
46
|
describe 'instance methods' do
|
45
|
-
|
46
|
-
|
47
|
-
subject { described_class.new(join_table, foreign_keys, parent_table_names) }
|
47
|
+
subject { described_class.new(join_table, foreign_keys, parent_table_names, connection: connection) }
|
48
48
|
|
49
49
|
describe '#initialize' do
|
50
50
|
it 'stores initialization attributes' do
|
@@ -46,15 +46,14 @@ RSpec.describe DeclareSchema do
|
|
46
46
|
let(:connection) { double("connection", select_value: "8.0.21") }
|
47
47
|
|
48
48
|
it "is lazy, so it doesn't use the database connection until read" do
|
49
|
-
@connection_called = false
|
50
49
|
expect(ActiveRecord::Base).to receive(:connection) do
|
51
50
|
@connection_called = true
|
52
51
|
connection
|
53
52
|
end
|
54
53
|
described_class.default_charset = "utf8"
|
55
|
-
expect(@connection_called).to
|
54
|
+
expect(@connection_called).to be_falsey
|
56
55
|
described_class.default_charset
|
57
|
-
expect(@connection_called).to
|
56
|
+
expect(@connection_called).to be_truthy
|
58
57
|
end
|
59
58
|
end
|
60
59
|
end
|
@@ -111,15 +110,14 @@ RSpec.describe DeclareSchema do
|
|
111
110
|
let(:connection) { double("connection", select_value: "8.0.21") }
|
112
111
|
|
113
112
|
it "is lazy, so it doesn't use the database connection until read" do
|
114
|
-
@connection_called = false
|
115
113
|
expect(ActiveRecord::Base).to receive(:connection) do
|
116
114
|
@connection_called = true
|
117
115
|
connection
|
118
116
|
end
|
119
117
|
described_class.default_collation = "utf8_general_ci"
|
120
|
-
expect(@connection_called).to
|
118
|
+
expect(@connection_called).to be_falsey
|
121
119
|
described_class.default_collation
|
122
|
-
expect(@connection_called).to
|
120
|
+
expect(@connection_called).to be_truthy
|
123
121
|
end
|
124
122
|
end
|
125
123
|
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.6.colin.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: 2024-01-
|
11
|
+
date: 2024-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|