declare_schema 1.4.0.colin.11 → 1.4.0

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: 13075fb086e36e6be6818fd28620cb9015c257083e994f68c216ca790e463896
4
- data.tar.gz: 4668a054c8d87a7612ba739e3937a4faf817b3ac558083c8e0af59668aa1c42a
3
+ metadata.gz: a00635546beea8512ef5678ea8d182612f6a6e5b099d6a13c4287e52312e8490
4
+ data.tar.gz: f5ba19f1fd2dc5d3c66923dda796e413f4a3bcd4586764b254c4345602ebb984
5
5
  SHA512:
6
- metadata.gz: 86d9f02bb9cabbb23ecec2eb68098b625b753b04890811858e4a43963d111ac54e5d2e10cd5468dfbdc2c6af39d1cab779002b033dbcbc05e869e4f0bc11f151
7
- data.tar.gz: fbc233f25183279a309a23dc9afb395b4c4a47e52a95661126c99d9a9109100c5bd5ac3b200171fca479bd9c569f1a9aa34dbe15c79e8cfe50a95387f683ab7e
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] - Unreleased
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.4.0.colin.11)
4
+ declare_schema (1.4.0)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.4.0.colin.11"
4
+ VERSION = "1.4.0"
5
5
  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.4.0.colin.11
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-23 00:00:00.000000000 Z
11
+ date: 2024-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails