generated_schema_validations 0.5.3 → 0.5.5

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: fe8baf27b9a18a5f82773b9aaea380a777a0c04a8b6d1367dcec8460797bba07
4
- data.tar.gz: 1c9dc3a8855e5643092d016e8adcf049abcc06433e9e5483fc6a4715e4b10fcb
3
+ metadata.gz: 5132d3be501617c0096cedc576b6d9167643b90c7fcca7023fb21117e78ecc42
4
+ data.tar.gz: '095f22b4ff3e06758bf03a1c271cf27d3c504370bafc41c5f47710ac9ba626c3'
5
5
  SHA512:
6
- metadata.gz: 49786698613eb20f5e25601f14cd40d339c53ddab70b67fec79990e1bf51d6370117ba7050c0db862c14c081e7d8dd9010ab96d9470cba316f8f83b1c1a2844e
7
- data.tar.gz: 298bfe17880ec5b6682ea85ba6e47afa7baeca4f19127216ffaac998dabe7e394442212989452a6374a384e634df97332524ad2bd2a40369d37902d5bc8c1f14
6
+ metadata.gz: a227d2c716e5b9c05cd6349305b1dbaed35f567bfc72ee35d0ba0490e112016a4e4392f0e84792ab733b86b17e61385b271408cdd2af4808465ebc2b4110c40a
7
+ data.tar.gz: 4f329cd8c928056756df0dba6048e94c34b0de3a310dd8abc9d2f91cda1b11351837af4b1f3cb158c5e0ba459211736a50e7e77e4c9925b17fff8cf4a14a974d
data/README.md CHANGED
@@ -105,6 +105,15 @@ You can watch changes on `schema_validations.rb` to understand the generated val
105
105
 
106
106
  ## Changelog
107
107
 
108
+ ### 0.5.5
109
+
110
+ * ignore geography fields
111
+
112
+ ### 0.5.4
113
+
114
+ * adds support for time fields
115
+ * fix errors on overflowing column values
116
+
108
117
  ### 0.5.3
109
118
 
110
119
  * adds support for Rails 7.2
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'generated_schema_validations'
5
- spec.version = '0.5.3'
5
+ spec.version = '0.5.5'
6
6
  spec.authors = ['Georg Limbach']
7
7
  spec.email = ['georg.limbach@lichtbit.com']
8
8
 
@@ -15,7 +15,7 @@ class GeneratedSchemaValidations::DumpChecker < GeneratedSchemaValidations::Dump
15
15
  stream
16
16
  )
17
17
  end
18
-
18
+
19
19
  stream.rewind
20
20
  stream.read
21
21
  end
@@ -104,6 +104,11 @@ class GeneratedSchemaValidations::Table
104
104
  validates name, :date_in_db_range
105
105
  end
106
106
 
107
+ def time(name, column_options = {})
108
+ null_validation(:time, name, column_options)
109
+ validates name, :time_in_db_range
110
+ end
111
+
107
112
  def boolean(name, column_options = {})
108
113
  null_validation(:boolean, name, column_options)
109
114
  end
@@ -163,4 +168,8 @@ class GeneratedSchemaValidations::Table
163
168
  @unique_indexes.push(names.map(&:to_s))
164
169
  end
165
170
  end
171
+
172
+ def geography(*)
173
+ # do nothing
174
+ end
166
175
  end
@@ -106,7 +106,7 @@ module SchemaValidations
106
106
  return unless value.is_a?(DateTime) || value.is_a?(Time)
107
107
  return if value.year.between?(-4711, 294_275) # see https://www.postgresql.org/docs/9.3/datatype-datetime.html
108
108
 
109
- record.errors.add(attr_name, :invalid, options)
109
+ record.errors.add(attr_name, :invalid)
110
110
  end
111
111
  end
112
112
 
@@ -116,7 +116,23 @@ module SchemaValidations
116
116
  return unless value.is_a?(Date)
117
117
  return if value.year.between?(-4711, 5_874_896) # see https://www.postgresql.org/docs/9.3/datatype-datetime.html
118
118
 
119
- record.errors.add(attr_name, :invalid, options)
119
+ record.errors.add(attr_name, :invalid)
120
+ end
121
+ end
122
+
123
+ class TimeInDbRangeValidator < ActiveModel::EachValidator
124
+ def validate_each(record, attr_name, value)
125
+ return if value.nil?
126
+
127
+ unless value.is_a?(Time) || value.is_a?(ActiveSupport::TimeWithZone)
128
+ record.errors.add(attr_name, :invalid)
129
+ return
130
+ end
131
+
132
+ # PostgreSQL allows only times in one day
133
+ return if value.to_date == Date.new(2000, 1, 1)
134
+
135
+ record.errors.add(attr_name, :invalid)
120
136
  end
121
137
  end
122
138
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generated_schema_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Limbach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-12-23 00:00:00.000000000 Z
11
+ date: 2026-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: After each migration it generates a file with some validations. Each
14
14
  active record should include this file and can uns generated validations.