declare_schema 2.3.1 → 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/.github/workflows/{declare_schema_build.yml → pipeline.yml} +7 -21
- data/Appraisals +1 -1
- data/CHANGELOG.md +13 -1
- data/Gemfile +7 -0
- data/Gemfile.lock +8 -1
- data/catalog-info.yaml +2 -0
- data/gemfiles/rails_7_0.gemfile +4 -0
- data/gemfiles/rails_7_1.gemfile +4 -0
- data/gemfiles/rails_7_2.gemfile +4 -0
- data/gemfiles/{rails_6_1.gemfile → rails_8_0.gemfile} +5 -1
- data/lib/declare_schema/dsl.rb +3 -5
- data/lib/declare_schema/field_declaration_dsl.rb +0 -2
- 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 +32 -3
- data/spec/lib/declare_schema/model/table_options_definition_spec.rb +10 -2
- metadata +5 -5
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
|
@@ -4,39 +4,25 @@ on: [push]
|
|
4
4
|
name: DeclareSchema Build
|
5
5
|
|
6
6
|
jobs:
|
7
|
-
|
7
|
+
tests:
|
8
8
|
name: DeclareSchema Build
|
9
9
|
runs-on: ubuntu-latest
|
10
10
|
strategy:
|
11
11
|
fail-fast: false
|
12
12
|
matrix:
|
13
13
|
adapter: [mysql, postgresql, sqlite3]
|
14
|
-
ruby: [
|
14
|
+
ruby: [3.1, 3.2, 3.3, 3.4]
|
15
15
|
gemfile:
|
16
|
-
- gemfiles/rails_6_1.gemfile
|
17
16
|
- gemfiles/rails_7_0.gemfile
|
18
17
|
- gemfiles/rails_7_1.gemfile
|
19
18
|
- gemfiles/rails_7_2.gemfile
|
19
|
+
- gemfiles/rails_8_0.gemfile
|
20
20
|
exclude:
|
21
|
-
-
|
22
|
-
|
23
|
-
|
24
|
-
- adapter: postgresql
|
25
|
-
ruby: 3.3
|
26
|
-
gemfile: gemfiles/rails_6_1.gemfile
|
21
|
+
- ruby: 3.1
|
22
|
+
gemfile: gemfiles/rails_8_0.gemfile
|
23
|
+
# TODO: Support SQLite3 with Rails 8.0
|
27
24
|
- adapter: sqlite3
|
28
|
-
|
29
|
-
gemfile: gemfiles/rails_6_1.gemfile
|
30
|
-
- adapter: mysql
|
31
|
-
ruby: '3.0'
|
32
|
-
gemfile: gemfiles/rails_7_2.gemfile
|
33
|
-
- adapter: postgresql
|
34
|
-
ruby: '3.0'
|
35
|
-
gemfile: gemfiles/rails_7_2.gemfile
|
36
|
-
- adapter: sqlite3
|
37
|
-
ruby: '3.0'
|
38
|
-
gemfile: gemfiles/rails_7_2.gemfile
|
39
|
-
|
25
|
+
gemfile: gemfiles/rails_8_0.gemfile
|
40
26
|
env:
|
41
27
|
BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
|
42
28
|
MYSQL_HOST: 127.0.0.1
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,19 @@ 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.
|
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
|
+
|
15
|
+
## [2.3.2] - 2025-02-21
|
16
|
+
### Fixed
|
17
|
+
- Removed require of `activesupport/proxy_object` which is removed in Rails 8.0
|
18
|
+
|
19
|
+
## [2.3.1] - 2024-12-10
|
8
20
|
### Fixed
|
9
21
|
- Fixed bug where a new model with `belongs_to :owner, polymorphic: true` would cause
|
10
22
|
a "Mysql2::Error: Table '<new table>' doesn't exist:" exception when generating a migration.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
declare_schema (2.3.1)
|
4
|
+
declare_schema (2.3.3.pre.1)
|
5
5
|
rails (>= 6.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -71,6 +71,8 @@ GEM
|
|
71
71
|
rake
|
72
72
|
thor (>= 0.14.0)
|
73
73
|
ast (2.4.2)
|
74
|
+
base64 (0.2.0)
|
75
|
+
bigdecimal (3.1.9)
|
74
76
|
bootsnap (1.18.4)
|
75
77
|
msgpack (~> 1.2)
|
76
78
|
builder (3.3.0)
|
@@ -106,6 +108,7 @@ GEM
|
|
106
108
|
mini_portile2 (2.8.7)
|
107
109
|
minitest (5.25.0)
|
108
110
|
msgpack (1.7.2)
|
111
|
+
mutex_m (0.3.0)
|
109
112
|
mysql2 (0.5.6)
|
110
113
|
net-imap (0.4.14)
|
111
114
|
date
|
@@ -228,11 +231,15 @@ PLATFORMS
|
|
228
231
|
|
229
232
|
DEPENDENCIES
|
230
233
|
appraisal
|
234
|
+
base64 (>= 0.2.0)
|
235
|
+
bigdecimal (>= 3.1)
|
231
236
|
bootsnap (>= 1.1.0)
|
232
237
|
climate_control (~> 0.2)
|
238
|
+
concurrent-ruby (~> 1.3, < 1.3.5)
|
233
239
|
declare_schema!
|
234
240
|
listen
|
235
241
|
mail
|
242
|
+
mutex_m (>= 0.3.0)
|
236
243
|
mysql2 (~> 0.5)
|
237
244
|
net-smtp
|
238
245
|
pg (~> 1.1)
|
data/catalog-info.yaml
CHANGED
data/gemfiles/rails_7_0.gemfile
CHANGED
@@ -17,6 +17,10 @@ gem "yard"
|
|
17
17
|
gem "mysql2", "~> 0.5"
|
18
18
|
gem "pg", "~> 1.1"
|
19
19
|
gem "sqlite3", "~> 1.4"
|
20
|
+
gem "concurrent-ruby", "~> 1.3", "< 1.3.5"
|
21
|
+
gem "base64", ">= 0.2.0"
|
22
|
+
gem "bigdecimal", ">= 3.1"
|
23
|
+
gem "mutex_m", ">= 0.3.0"
|
20
24
|
|
21
25
|
group :testapp do
|
22
26
|
gem "bootsnap", ">= 1.1.0", require: false
|
data/gemfiles/rails_7_1.gemfile
CHANGED
@@ -17,6 +17,10 @@ gem "yard"
|
|
17
17
|
gem "mysql2", "~> 0.5"
|
18
18
|
gem "pg", "~> 1.1"
|
19
19
|
gem "sqlite3", "~> 1.4"
|
20
|
+
gem "concurrent-ruby", "~> 1.3", "< 1.3.5"
|
21
|
+
gem "base64", ">= 0.2.0"
|
22
|
+
gem "bigdecimal", ">= 3.1"
|
23
|
+
gem "mutex_m", ">= 0.3.0"
|
20
24
|
|
21
25
|
group :testapp do
|
22
26
|
gem "bootsnap", ">= 1.1.0", require: false
|
data/gemfiles/rails_7_2.gemfile
CHANGED
@@ -17,6 +17,10 @@ gem "yard"
|
|
17
17
|
gem "mysql2", "~> 0.5"
|
18
18
|
gem "pg", "~> 1.1"
|
19
19
|
gem "sqlite3", "~> 1.4"
|
20
|
+
gem "concurrent-ruby", "~> 1.3", "< 1.3.5"
|
21
|
+
gem "base64", ">= 0.2.0"
|
22
|
+
gem "bigdecimal", ">= 3.1"
|
23
|
+
gem "mutex_m", ">= 0.3.0"
|
20
24
|
|
21
25
|
group :testapp do
|
22
26
|
gem "bootsnap", ">= 1.1.0", require: false
|
@@ -8,7 +8,7 @@ gem "mail"
|
|
8
8
|
gem "net-smtp"
|
9
9
|
gem "pry"
|
10
10
|
gem "pry-byebug"
|
11
|
-
gem "rails", "~>
|
11
|
+
gem "rails", "~> 8.0.0"
|
12
12
|
gem "responders"
|
13
13
|
gem "rspec"
|
14
14
|
gem "rspec-its"
|
@@ -17,6 +17,10 @@ gem "yard"
|
|
17
17
|
gem "mysql2", "~> 0.5"
|
18
18
|
gem "pg", "~> 1.1"
|
19
19
|
gem "sqlite3", "~> 1.4"
|
20
|
+
gem "concurrent-ruby", "~> 1.3", "< 1.3.5"
|
21
|
+
gem "base64", ">= 0.2.0"
|
22
|
+
gem "bigdecimal", ">= 3.1"
|
23
|
+
gem "mutex_m", ">= 0.3.0"
|
20
24
|
|
21
25
|
group :testapp do
|
22
26
|
gem "bootsnap", ">= 1.1.0", require: false
|
data/lib/declare_schema/dsl.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'active_support/proxy_object'
|
4
|
-
|
5
3
|
module DeclareSchema
|
6
4
|
class Dsl < BasicObject # avoid Object because that gets extended by lots of gems
|
7
5
|
include ::Kernel # but we need the basic class methods
|
@@ -19,9 +17,9 @@ module DeclareSchema
|
|
19
17
|
|
20
18
|
attr_reader :model
|
21
19
|
|
22
|
-
def timestamps
|
23
|
-
field(:created_at, :datetime, null:
|
24
|
-
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)
|
25
23
|
end
|
26
24
|
|
27
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
|
@@ -899,7 +923,12 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
899
923
|
end
|
900
924
|
up, _down = Generators::DeclareSchema::Migration::Migrator.run
|
901
925
|
ActiveRecord::Migration.class_eval(up)
|
902
|
-
|
926
|
+
|
927
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.4")
|
928
|
+
expect(Ad.field_specs['company'].options[:validates].inspect).to eq("{:presence=>true, :uniqueness=>{:case_sensitive=>false}}")
|
929
|
+
else
|
930
|
+
expect(Ad.field_specs['company'].options[:validates].inspect).to eq("{presence: true, uniqueness: {case_sensitive: false}}")
|
931
|
+
end
|
903
932
|
|
904
933
|
# DeclareSchema supports has_and_belongs_to_many relationships and generates the intersection ("join") table
|
905
934
|
# with appropriate primary key, indexes, and foreign keys.
|
@@ -24,7 +24,11 @@ RSpec.describe DeclareSchema::Model::TableOptionsDefinition do
|
|
24
24
|
|
25
25
|
describe '#to_key' do
|
26
26
|
subject { model.to_key }
|
27
|
-
|
27
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.4")
|
28
|
+
it { is_expected.to eq(['table_options_definition_test_models', "{:charset=>#{charset.inspect}, :collation=>#{collation.inspect}}"]) }
|
29
|
+
else
|
30
|
+
it { is_expected.to eq(['table_options_definition_test_models', "{charset: #{charset.inspect}, collation: #{collation.inspect}}"]) }
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
describe '#settings' do
|
@@ -56,7 +60,11 @@ RSpec.describe DeclareSchema::Model::TableOptionsDefinition do
|
|
56
60
|
|
57
61
|
describe '#hash' do
|
58
62
|
subject { model.hash }
|
59
|
-
|
63
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.4")
|
64
|
+
it { is_expected.to eq(['table_options_definition_test_models', "{:charset=>#{charset.inspect}, :collation=>#{collation.inspect}}"].hash) }
|
65
|
+
else
|
66
|
+
it { is_expected.to eq(['table_options_definition_test_models', "{charset: #{charset.inspect}, collation: #{collation.inspect}}"].hash) }
|
67
|
+
end
|
60
68
|
end
|
61
69
|
|
62
70
|
describe '#to_s' do
|
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.1
|
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:
|
11
|
+
date: 2025-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -37,8 +37,8 @@ files:
|
|
37
37
|
- ".devcontainer/devcontainer.json"
|
38
38
|
- ".devcontainer/docker-compose.yml"
|
39
39
|
- ".github/CODEOWNERS"
|
40
|
-
- ".github/workflows/declare_schema_build.yml"
|
41
40
|
- ".github/workflows/gem_release.yml"
|
41
|
+
- ".github/workflows/pipeline.yml"
|
42
42
|
- ".gitignore"
|
43
43
|
- ".rspec"
|
44
44
|
- ".rubocop.yml"
|
@@ -57,10 +57,10 @@ files:
|
|
57
57
|
- config/brakeman.ignore
|
58
58
|
- declare_schema.gemspec
|
59
59
|
- gemfiles/.bundle/config
|
60
|
-
- gemfiles/rails_6_1.gemfile
|
61
60
|
- gemfiles/rails_7_0.gemfile
|
62
61
|
- gemfiles/rails_7_1.gemfile
|
63
62
|
- gemfiles/rails_7_2.gemfile
|
63
|
+
- gemfiles/rails_8_0.gemfile
|
64
64
|
- lib/declare_schema.rb
|
65
65
|
- lib/declare_schema/command.rb
|
66
66
|
- lib/declare_schema/dsl.rb
|
@@ -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.4.
|
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
|