declare_schema 1.3.5 → 1.3.6

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: 9d11ade44eb67c0d2afaae73dc540ee10ed09ff62494fff9feb32dcea9bfefaa
4
- data.tar.gz: 83ce51a81e9b2b11944e199972b41c4a3662323bb0ccdf5ddef08b8dec9b3480
3
+ metadata.gz: d142143cff509bcd40c65523866ce41b01ff9e5d5eb33914cbe22446f2915d18
4
+ data.tar.gz: 01c7ab3b0a606c4b21f9b3b4f67cceff09d6b20c699ec291036bd840ca084d86
5
5
  SHA512:
6
- metadata.gz: 43802ec088ddbd240c7ad04617cdd76753dc216d2cbac693bd6b6029f0809fc525545197c2ccb768a2b1e50c3d75c76ab612a9b16f1db63b0dc9b62f477325a8
7
- data.tar.gz: dd323d88fbdbf493698710ebea366e8539f4b38e7a59a31c693553082a231264e99b7dde864f833fd8c92fd01ca6c5567958532a4833d0622d235ed20594f262
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.3.5)
4
+ declare_schema (1.3.6)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -4,15 +4,17 @@ module DeclareSchema
4
4
  module Model
5
5
  class HabtmModelShim
6
6
  class << self
7
- def from_reflection(refl)
8
- new(refl.join_table, [refl.foreign_key, refl.association_foreign_key],
9
- [refl.active_record.table_name, refl.class_name.constantize.table_name])
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
- @table_name = table_name or raise ArgumentError, "must provide table_name"
10
- @column_name = column_name or raise ArgumentError, "must provide column_name"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.3.5"
4
+ VERSION = "1.3.6"
5
5
  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, refls|
208
- models_by_table_name[name] = ::DeclareSchema::Model::HabtmModelShim.from_reflection(refls.first)
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
- let(:connection) { instance_double(ActiveRecord::Base.connection.class, "connection") }
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.5
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-22 00:00:00.000000000 Z
11
+ date: 2024-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails