declare_schema 2.3.2 → 2.3.3.pre.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/lib/declare_schema/dsl.rb +3 -3
- data/lib/declare_schema/model.rb +1 -1
- data/lib/declare_schema/version.rb +1 -1
- data/spec/lib/declare_schema/migration_generator_spec.rb +26 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97f3a5d50a7212aac5b3688c3e2a20a87d5957f6053d243eb5d2f81b5d2d8f3e
|
4
|
+
data.tar.gz: 635a2bac38835fa207cb7467de27eaf9fb30177e565b306d12644eb3d66a8953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03b085e2c18ed987e5660e1c1cabef1535a68d31d5188ab48abf8c1051c494c19c23a7fe20d23b0d47331d5738f533ee8e8e0b198a706eb932ed8dc66b2233db
|
7
|
+
data.tar.gz: 2d78ff8de5e66d958ec025912260a5f797f3b381d4b02b93cf023f822229e75760b482cebbc825217da877e356fbf01e858997b7f19e770ce8ae67ff01c909a6
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,14 @@ 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
|
+
## [2.3.3] - Unreleased
|
8
|
+
### Changed
|
9
|
+
- The `timestamps` DSL method to create `created_at` and `updated_at` columns now defaults to `null: false` for `datetime` columns
|
10
|
+
- The `timestamps` DSL method to allow additional options to be passed to the `datetime` fields
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- Fixed a bug where `#validate` methods on core object classes with required arguments were cuasing model validations to fail
|
14
|
+
|
7
15
|
## [2.3.2] - 2025-02-21
|
8
16
|
### Fixed
|
9
17
|
- Removed require of `activesupport/proxy_object` which is removed in Rails 8.0
|
data/Gemfile.lock
CHANGED
data/lib/declare_schema/dsl.rb
CHANGED
@@ -17,9 +17,9 @@ module DeclareSchema
|
|
17
17
|
|
18
18
|
attr_reader :model
|
19
19
|
|
20
|
-
def timestamps
|
21
|
-
field(:created_at, :datetime, null:
|
22
|
-
field(:updated_at, :datetime, null:
|
20
|
+
def timestamps(**options)
|
21
|
+
field(:created_at, :datetime, null: false, **options)
|
22
|
+
field(:updated_at, :datetime, null: false, **options)
|
23
23
|
end
|
24
24
|
|
25
25
|
def optimistic_lock
|
data/lib/declare_schema/model.rb
CHANGED
@@ -310,7 +310,7 @@ module DeclareSchema
|
|
310
310
|
|
311
311
|
# Support for custom validations
|
312
312
|
if (type_class = DeclareSchema.to_class(type))
|
313
|
-
if type_class.public_method_defined?("validate")
|
313
|
+
if type_class.public_method_defined?("validate") && type_class.instance_method("validate").arity.zero?
|
314
314
|
validate do |record|
|
315
315
|
v = record.send(name)&.validate
|
316
316
|
record.errors.add(name, v) if v.is_a?(String)
|
@@ -471,8 +471,8 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
471
471
|
|
472
472
|
expect(Generators::DeclareSchema::Migration::Migrator.run).to(
|
473
473
|
migrate_up(<<~EOS.strip)
|
474
|
-
add_column :adverts, :created_at, :datetime, null:
|
475
|
-
add_column :adverts, :updated_at, :datetime, null:
|
474
|
+
add_column :adverts, :created_at, :datetime, null: false
|
475
|
+
add_column :adverts, :updated_at, :datetime, null: false
|
476
476
|
add_column :adverts, :lock_version, :integer#{lock_version_limit}, null: false, default: 1
|
477
477
|
EOS
|
478
478
|
.and(migrate_down(<<~EOS.strip))
|
@@ -486,6 +486,30 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
486
486
|
Advert.field_specs.delete(:created_at)
|
487
487
|
Advert.field_specs.delete(:lock_version)
|
488
488
|
|
489
|
+
### Timestamps with null: true
|
490
|
+
|
491
|
+
# `updated_at` and `created_at` can be declared with the shorthand `timestamps` passed with null: true override
|
492
|
+
|
493
|
+
class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
|
494
|
+
declare_schema do
|
495
|
+
timestamps null: true
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
expect(Generators::DeclareSchema::Migration::Migrator.run).to(
|
500
|
+
migrate_up(<<~EOS.strip)
|
501
|
+
add_column :adverts, :created_at, :datetime, null: true
|
502
|
+
add_column :adverts, :updated_at, :datetime, null: true
|
503
|
+
EOS
|
504
|
+
.and(migrate_down(<<~EOS.strip))
|
505
|
+
remove_column :adverts, :updated_at
|
506
|
+
remove_column :adverts, :created_at
|
507
|
+
EOS
|
508
|
+
)
|
509
|
+
|
510
|
+
Advert.field_specs.delete(:updated_at)
|
511
|
+
Advert.field_specs.delete(:created_at)
|
512
|
+
|
489
513
|
### Indices
|
490
514
|
|
491
515
|
# You can add an index to a field definition
|
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: 2.3.
|
4
|
+
version: 2.3.3.pre.1
|
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: 2025-
|
11
|
+
date: 2025-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: 1.3.6
|
160
160
|
requirements: []
|
161
|
-
rubygems_version: 3.
|
161
|
+
rubygems_version: 3.4.16
|
162
162
|
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: Database schema declaration and migration generator for Rails
|