declare_schema 1.3.5 → 1.3.6
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/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/generators/declare_schema/migration/migrator.rb +3 -3
- data/spec/lib/declare_schema/model/habtm_model_shim_spec.rb +4 -4
- 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: d142143cff509bcd40c65523866ce41b01ff9e5d5eb33914cbe22446f2915d18
|
4
|
+
data.tar.gz: 01c7ab3b0a606c4b21f9b3b4f67cceff09d6b20c699ec291036bd840ca084d86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0264bf26889a2149ae448d8b874f74c32d5fc8a5877a02466e89b62dd5000e7411c4e3dcf2ea6be8534f259a5ae9ebe0bab5f514fc18e4d8629ecd203ebce68a
|
7
|
+
data.tar.gz: b454598ee79b3c3bf6677c3c9e1938931d882755861ad87c546e30f5d2e4d284356bf7fc41936a1e164193786af7ccc9dc2442d61c3af56c37ae339d8166a32b
|
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
|
@@ -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
|
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
|
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
|