declare_schema 1.4.0.colin.11 → 1.4.0
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 +1 -1
- data/Gemfile.lock +1 -1
- data/lib/declare_schema/model.rb +33 -3
- data/lib/declare_schema/version.rb +1 -1
- 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: a00635546beea8512ef5678ea8d182612f6a6e5b099d6a13c4287e52312e8490
|
4
|
+
data.tar.gz: f5ba19f1fd2dc5d3c66923dda796e413f4a3bcd4586764b254c4345602ebb984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cd37d8cf76460b9af36e1f05c7e5c42f370eae8fec0936e563a6dcd74e7176d1d8c66e6fa464d7e58429be220be0dbb5b6a7f5bf7c19dfb0ff834e53771e806
|
7
|
+
data.tar.gz: '0870d0173821829d81c8033fda33921c8de00f7b1ec5aa2b9da56fb15b7d73b716a14058be0dc2ad595bc2bf2a6b9b66c8cdcbb612dd91fd21d88c0992b0e057'
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,7 @@ 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.4] -
|
7
|
+
## [1.4.0] - 2024-01-24
|
8
8
|
### Added
|
9
9
|
- Added support for partial indexes with `length:` option.
|
10
10
|
### Changed
|
data/Gemfile.lock
CHANGED
data/lib/declare_schema/model.rb
CHANGED
@@ -115,7 +115,37 @@ module DeclareSchema
|
|
115
115
|
# 1. creates a FieldSpec for the foreign key
|
116
116
|
# 2. declares an index on the foreign key (optional)
|
117
117
|
# 3. declares a foreign_key constraint (optional)
|
118
|
+
# @param name [Symbol] the name of the association to pass to super
|
119
|
+
# @param scope [Proc] the scope of the association to pass to super
|
120
|
+
# @option options [Boolean] :optional (default: false) whether the foreign key column should be nullable and whether
|
121
|
+
# ActiveRecord should validate presence of the foreign key (passed through to super)
|
122
|
+
# @option options [Boolean] :null (default: inferred from options[:optional]) whether the foreign key column should be nullable
|
123
|
+
# (`null:` should only be passed if it is the inverse of `optional:`; otherwise it is redundant)
|
124
|
+
# @option options [Integer] :limit (default: inferred from the primary key limit:) the limit of the foreign key column size (4 or 8)
|
125
|
+
# @option options [Boolean|Hash<Symbol>] :index (default: true) whether to create an index on the foreign key; can be true or false
|
126
|
+
# or a hash of options to pass to the index declaration, with keys like { name: ..., unique: ... }
|
127
|
+
# @option options [Boolean] :allow_equivalent (default: false) whether to allow an existing index with a different name
|
128
|
+
# @option options [Boolean|String] :constraint (default: true) whether to create a foreign key constraint on the foreign key;
|
129
|
+
# may be true or false or a string to use as the constraint name
|
130
|
+
# @option options [Boolean] :polymorphic (default: false) whether this is a polymorphic belongs_to with a _type column next to
|
131
|
+
# the foreign key _id column (also passed through to super)
|
132
|
+
# @option options [Boolean] :far_end_dependent (default: nil) whether to add a dependent: :delete to the far end of the foreign key
|
133
|
+
# constraint
|
134
|
+
# @option options [String] :foreign_type (default: "#{name}_type") the name prefix for the _type column for a polymorphic belongs_to
|
135
|
+
# (passed through to super)
|
136
|
+
# Other options are passed through to super
|
118
137
|
def belongs_to(name, scope = nil, **options)
|
138
|
+
if options[:null].in?([true, false]) && options[:optional] == options[:null]
|
139
|
+
STDERR.puts("[declare_schema warning] belongs_to #{name.inspect}, null: with the same value as optional: is redundant; omit null: #{options[:null]} (called from #{caller[0]})")
|
140
|
+
elsif !options.has_key?(:optional)
|
141
|
+
case options[:null]
|
142
|
+
when true
|
143
|
+
STDERR.puts("[declare_schema] belongs_to #{name.inspect}, null: true is deprecated in favor of optional: true (called from #{caller[0]})")
|
144
|
+
when false
|
145
|
+
STDERR.puts("[declare_schema] belongs_to #{name.inspect}, null: false is implied and can be omitted (called from #{caller[0]})")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
119
149
|
column_options = {}
|
120
150
|
|
121
151
|
column_options[:null] = if options.has_key?(:null)
|
@@ -140,18 +170,18 @@ module DeclareSchema
|
|
140
170
|
index_options = {} # create an index
|
141
171
|
case index_value
|
142
172
|
when String, Symbol
|
143
|
-
ActiveSupport::Deprecation.warn("belongs_to #{name.inspect}, index: 'name' is deprecated; use index: { name: 'name' } instead (in #{self.name})")
|
173
|
+
ActiveSupport::Deprecation.warn("[declare_schema] belongs_to #{name.inspect}, index: 'name' is deprecated; use index: { name: 'name' } instead (in #{self.name})")
|
144
174
|
index_options[:name] = index_value.to_s
|
145
175
|
when true
|
146
176
|
when nil
|
147
177
|
when Hash
|
148
178
|
index_options = index_value
|
149
179
|
else
|
150
|
-
raise ArgumentError, "belongs_to #{name.inspect}, index: must be true or false or a Hash; got #{index_value.inspect} (in #{self.name})"
|
180
|
+
raise ArgumentError, "[declare_schema] belongs_to #{name.inspect}, index: must be true or false or a Hash; got #{index_value.inspect} (in #{self.name})"
|
151
181
|
end
|
152
182
|
|
153
183
|
if options.has_key?(:unique)
|
154
|
-
ActiveSupport::Deprecation.warn("belongs_to #{name.inspect}, unique: true|false is deprecated; use index: { unique: true|false } instead (in #{self.name})")
|
184
|
+
ActiveSupport::Deprecation.warn("[declare_schema] belongs_to #{name.inspect}, unique: true|false is deprecated; use index: { unique: true|false } instead (in #{self.name})")
|
155
185
|
index_options[:unique] = options.delete(:unique)
|
156
186
|
end
|
157
187
|
|
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.4.0
|
4
|
+
version: 1.4.0
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|