adjustable_schema 0.7.0 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f905a89a0f7ab6c7c5c1f1feaa92a8fdb90f5e58003b164fed5ac55096fa258
4
- data.tar.gz: cf1c34dd8cce3497e64635ab1c59f079e257961979e55e9d31b30ae1aefeb4ff
3
+ metadata.gz: 5a26450a562fbcde4b87abd3a84e85f577d3c1a7c9f8ecfdf22b79728875f1e6
4
+ data.tar.gz: b2cda5f212ae129a97b92a80440f8e053af2c44d5c54676e2358da3230cb987a
5
5
  SHA512:
6
- metadata.gz: 892d3cc2cdfa8d6cd7d2405289e1417a54be8c8767fefa557208a2d7880d346e4c362adc1a5dc911d2091be1b172a15f88e3060c0c06b29b135a61efb773f5bb
7
- data.tar.gz: 145e68868903178eb0a6a82ed224912f657cdb7004f91df9cf70bec4c9c32241b1cd216515ee913369e6914f865007214d1a7aad5b5604664b73408974f5a323
6
+ metadata.gz: 1bf5d1bcef25e17cdbfc7de6d1f4f0278571169e9416d96fa4542ae654ea236184b39fa162938870d085a5afc496beac98e8a6a48ad311e69a277a97eb2f01d8
7
+ data.tar.gz: '099e2973293293635d6a1a1cda5a3105363e5c42dedc14cc30f07fc967870b6586da29dd4443e2ab37ee7b93059e063e538a8f3c39bc98308354342f5398a3bb'
@@ -4,7 +4,7 @@ class CreateAdjustableSchemaRelationshipTables < ActiveRecord::Migration[7.1]
4
4
  primary_key_type, foreign_key_type = primary_and_foreign_key_types
5
5
 
6
6
  create_table :adjustable_schema_relationship_roles do |t|
7
- t.string :name, index: { unique: true }
7
+ t.string :name, null: false, index: { unique: true }
8
8
 
9
9
  t.timestamps
10
10
  end
@@ -17,13 +17,20 @@ class CreateAdjustableSchemaRelationshipTables < ActiveRecord::Migration[7.1]
17
17
 
18
18
  t.timestamps
19
19
 
20
- t.index %i[
20
+ %i[
21
21
  source_id source_type
22
22
  target_id target_type
23
23
  role_id
24
24
  ].tap { |columns|
25
- columns.reject! { _1.ends_with? '_type' } if foreign_key_type == :uuid # OPTIMIZATION: IDs are unique
26
- }, unique: true, name: :index_adjustable_schema_relationships_uniqueness
25
+ columns.reject! { _1.ends_with? '_type' } if foreign_key_type == :uuid # OPTIMIZATION: IDs are unique
26
+
27
+ # NULLS are DISTINCT by default.
28
+ # One can use `ADD CONSTRAINT … UNIQUE NULLS NOT DISTINCT (…)` instead
29
+ t.index columns,
30
+ unique: true, where: 'role_id IS NOT NULL', name: :index_adjustable_schema_relationships_uniqueness_with_role
31
+ t.index columns.excluding(:role_id),
32
+ unique: true, where: 'role_id IS NULL', name: :index_adjustable_schema_relationships_uniqueness_without_role
33
+ }
27
34
  end
28
35
  end
29
36
 
@@ -38,7 +38,7 @@ module AdjustableSchema
38
38
  private
39
39
 
40
40
  memoize def name_with_role
41
- if loop?
41
+ if recursive?
42
42
  {
43
43
  source: role.name,
44
44
  target: "#{role.name.passivize}_#{target_name}",
@@ -52,7 +52,7 @@ module AdjustableSchema
52
52
  end
53
53
 
54
54
  memoize def name_without_role
55
- if loop?
55
+ if recursive?
56
56
  Config.association_directions
57
57
  .self[direction]
58
58
  else
@@ -15,22 +15,24 @@ module AdjustableSchema
15
15
  class_name: target.name
16
16
  }) do
17
17
  include Scopes
18
- include Scopes::Recursive if association.loop?
18
+ include Scopes::Recursive if association.recursive?
19
19
  end
20
20
 
21
21
  define_scopes
22
22
  define_methods
23
23
 
24
24
  unless role
25
- has_many target_name.tableize.to_sym, -> { roleless }, **options if
26
- loop?
25
+ # HACK: using `try` to overcome a Rails bug
26
+ # (see https://github.com/rails/rails/issues/40109)
27
+ has_many target_name.tableize.to_sym, -> { try :roleless }, **options if
28
+ recursive?
27
29
 
28
30
  define_role_methods
29
31
  end
30
32
  end
31
33
  end
32
34
 
33
- def loop? = target == owner
35
+ def recursive? = target == owner
34
36
 
35
37
  private
36
38
 
@@ -18,5 +18,8 @@ module AdjustableSchema
18
18
  },
19
19
  },
20
20
  }
21
+
22
+ config.active_record
23
+ .automatically_invert_plural_associations = true
21
24
  end
22
25
  end
@@ -1,3 +1,3 @@
1
1
  module AdjustableSchema
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adjustable_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Senko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-25 00:00:00.000000000 Z
11
+ date: 2024-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -111,7 +111,7 @@ licenses:
111
111
  metadata:
112
112
  homepage_uri: https://github.com/Alexander-Senko/adjustable_schema
113
113
  source_code_uri: https://github.com/Alexander-Senko/adjustable_schema
114
- changelog_uri: https://github.com/Alexander-Senko/adjustable_schema/blob/v0.7.0/CHANGELOG.md
114
+ changelog_uri: https://github.com/Alexander-Senko/adjustable_schema/blob/v0.7.1/CHANGELOG.md
115
115
  post_install_message:
116
116
  rdoc_options: []
117
117
  require_paths:
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  requirements: []
130
- rubygems_version: 3.5.5
130
+ rubygems_version: 3.5.6
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Adjustable data schemas for Rails