declare_schema 1.4.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a00635546beea8512ef5678ea8d182612f6a6e5b099d6a13c4287e52312e8490
4
- data.tar.gz: f5ba19f1fd2dc5d3c66923dda796e413f4a3bcd4586764b254c4345602ebb984
3
+ metadata.gz: 92f1ec3624f575f6cbf8fb884b726c2957661f3d77078a467ca78e42dd95bdb2
4
+ data.tar.gz: 8735c888f46d675e49d06e56a37629e9cdf633218ce956ab111defc00013971f
5
5
  SHA512:
6
- metadata.gz: 4cd37d8cf76460b9af36e1f05c7e5c42f370eae8fec0936e563a6dcd74e7176d1d8c66e6fa464d7e58429be220be0dbb5b6a7f5bf7c19dfb0ff834e53771e806
7
- data.tar.gz: '0870d0173821829d81c8033fda33921c8de00f7b1ec5aa2b9da56fb15b7d73b716a14058be0dc2ad595bc2bf2a6b9b66c8cdcbb612dd91fd21d88c0992b0e057'
6
+ metadata.gz: c874389f98b8b7e6a5128a97324ad3a00597dc0892673f6d13c7b95611bb286d64afc40bee89cf992f71ba998a67fcd366ee2bd3527b71eb4113df8514ffe00d
7
+ data.tar.gz: 2a815e79364ae5eeb718488fa246adbf0730f0d9c4d92db802eedc2b9795c95a4061ca1d2a07014104a83f50a1dd6befb65ae49990e09f42e05a7b7e64fc0849
@@ -10,10 +10,19 @@ jobs:
10
10
  strategy:
11
11
  fail-fast: false
12
12
  matrix:
13
- ruby: [2.7, '3.0', 3.1, 3.2]
13
+ ruby: ['3.0', 3.1, 3.2, 3.3]
14
14
  gemfile:
15
- - gemfiles/rails_6_mysql.gemfile
16
- - gemfiles/rails_6_sqlite.gemfile
15
+ - gemfiles/rails_6_1_mysql2.gemfile
16
+ - gemfiles/rails_6_1_sqlite3.gemfile
17
+ - gemfiles/rails_7_0_mysql2.gemfile
18
+ - gemfiles/rails_7_0_sqlite3.gemfile
19
+ - gemfiles/rails_7_1_mysql2.gemfile
20
+ - gemfiles/rails_7_1_sqlite3.gemfile
21
+ exclude:
22
+ - ruby: 3.3
23
+ gemfile: gemfiles/rails_6_1_mysql2.gemfile
24
+ - ruby: 3.3
25
+ gemfile: gemfiles/rails_6_1_sqlite3.gemfile
17
26
 
18
27
  env:
19
28
  BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
data/Appraisals CHANGED
@@ -1,12 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'rails-6-sqlite' do
4
- gem 'rails', '~> 6.1'
5
- gem 'sqlite3'
3
+ require 'json'
4
+ require 'open-uri'
5
+
6
+ MIN_RAILS_VERSION = Gem::Version.new('6.1.0')
7
+ DB_ADAPTERS = {
8
+ sqlite3: '~> 1.4',
9
+ mysql2: '~> 0.5',
10
+ }.freeze
11
+
12
+ rails_versions_to_test = Set.new
13
+
14
+ URI.parse('https://rubygems.org/api/v1/versions/rails.json').open do |raw_version_data|
15
+ JSON.parse(raw_version_data.read).each do |version_data|
16
+ version = Gem::Version.new(version_data['number'])
17
+
18
+ rails_versions_to_test << version.segments[0..1].join('.') if version >= MIN_RAILS_VERSION && !version.prerelease?
19
+ end
6
20
  end
7
21
 
8
- appraise 'rails-6-mysql' do
9
- gem 'rails', '~> 6.1'
10
- gem 'mysql2'
11
- remove_gem 'sqlite3'
22
+ rails_versions_to_test.each do |version|
23
+ DB_ADAPTERS.each do |adapter, adapter_version|
24
+ appraise "rails-#{version.gsub('.', '_')}-#{adapter}" do
25
+ gem 'rails', "~> #{version}.0"
26
+ remove_gem 'sqlite3' # To make sure that the adapter only exists when we're testing against sqlite3
27
+ gem adapter, adapter_version
28
+ end
29
+ end
12
30
  end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ 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.0.0] - 2024-05-14
8
+ ### Added
9
+ - Added support for Rails 7.0 and 7.1
10
+ - Add support for automatic enum scopes for each value in the `:limit` array
11
+ ### Removed
12
+ - Removed support for Rails < 6.0
13
+
7
14
  ## [1.4.0] - 2024-01-24
8
15
  ### Added
9
16
  - Added support for partial indexes with `length:` option.
data/Gemfile.lock CHANGED
@@ -1,98 +1,98 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.4.0)
5
- rails (>= 5.0)
4
+ declare_schema (2.0.0)
5
+ rails (>= 6.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (6.1.7.4)
11
- actionpack (= 6.1.7.4)
12
- activesupport (= 6.1.7.4)
10
+ actioncable (6.1.7.7)
11
+ actionpack (= 6.1.7.7)
12
+ activesupport (= 6.1.7.7)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailbox (6.1.7.4)
16
- actionpack (= 6.1.7.4)
17
- activejob (= 6.1.7.4)
18
- activerecord (= 6.1.7.4)
19
- activestorage (= 6.1.7.4)
20
- activesupport (= 6.1.7.4)
15
+ actionmailbox (6.1.7.7)
16
+ actionpack (= 6.1.7.7)
17
+ activejob (= 6.1.7.7)
18
+ activerecord (= 6.1.7.7)
19
+ activestorage (= 6.1.7.7)
20
+ activesupport (= 6.1.7.7)
21
21
  mail (>= 2.7.1)
22
- actionmailer (6.1.7.4)
23
- actionpack (= 6.1.7.4)
24
- actionview (= 6.1.7.4)
25
- activejob (= 6.1.7.4)
26
- activesupport (= 6.1.7.4)
22
+ actionmailer (6.1.7.7)
23
+ actionpack (= 6.1.7.7)
24
+ actionview (= 6.1.7.7)
25
+ activejob (= 6.1.7.7)
26
+ activesupport (= 6.1.7.7)
27
27
  mail (~> 2.5, >= 2.5.4)
28
28
  rails-dom-testing (~> 2.0)
29
- actionpack (6.1.7.4)
30
- actionview (= 6.1.7.4)
31
- activesupport (= 6.1.7.4)
29
+ actionpack (6.1.7.7)
30
+ actionview (= 6.1.7.7)
31
+ activesupport (= 6.1.7.7)
32
32
  rack (~> 2.0, >= 2.0.9)
33
33
  rack-test (>= 0.6.3)
34
34
  rails-dom-testing (~> 2.0)
35
35
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
- actiontext (6.1.7.4)
37
- actionpack (= 6.1.7.4)
38
- activerecord (= 6.1.7.4)
39
- activestorage (= 6.1.7.4)
40
- activesupport (= 6.1.7.4)
36
+ actiontext (6.1.7.7)
37
+ actionpack (= 6.1.7.7)
38
+ activerecord (= 6.1.7.7)
39
+ activestorage (= 6.1.7.7)
40
+ activesupport (= 6.1.7.7)
41
41
  nokogiri (>= 1.8.5)
42
- actionview (6.1.7.4)
43
- activesupport (= 6.1.7.4)
42
+ actionview (6.1.7.7)
43
+ activesupport (= 6.1.7.7)
44
44
  builder (~> 3.1)
45
45
  erubi (~> 1.4)
46
46
  rails-dom-testing (~> 2.0)
47
47
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
- activejob (6.1.7.4)
49
- activesupport (= 6.1.7.4)
48
+ activejob (6.1.7.7)
49
+ activesupport (= 6.1.7.7)
50
50
  globalid (>= 0.3.6)
51
- activemodel (6.1.7.4)
52
- activesupport (= 6.1.7.4)
53
- activerecord (6.1.7.4)
54
- activemodel (= 6.1.7.4)
55
- activesupport (= 6.1.7.4)
56
- activestorage (6.1.7.4)
57
- actionpack (= 6.1.7.4)
58
- activejob (= 6.1.7.4)
59
- activerecord (= 6.1.7.4)
60
- activesupport (= 6.1.7.4)
51
+ activemodel (6.1.7.7)
52
+ activesupport (= 6.1.7.7)
53
+ activerecord (6.1.7.7)
54
+ activemodel (= 6.1.7.7)
55
+ activesupport (= 6.1.7.7)
56
+ activestorage (6.1.7.7)
57
+ actionpack (= 6.1.7.7)
58
+ activejob (= 6.1.7.7)
59
+ activerecord (= 6.1.7.7)
60
+ activesupport (= 6.1.7.7)
61
61
  marcel (~> 1.0)
62
62
  mini_mime (>= 1.1.0)
63
- activesupport (6.1.7.4)
63
+ activesupport (6.1.7.7)
64
64
  concurrent-ruby (~> 1.0, >= 1.0.2)
65
65
  i18n (>= 1.6, < 2)
66
66
  minitest (>= 5.1)
67
67
  tzinfo (~> 2.0)
68
68
  zeitwerk (~> 2.3)
69
- appraisal (2.4.1)
69
+ appraisal (2.5.0)
70
70
  bundler
71
71
  rake
72
72
  thor (>= 0.14.0)
73
73
  ast (2.4.2)
74
- bootsnap (1.16.0)
74
+ bootsnap (1.18.3)
75
75
  msgpack (~> 1.2)
76
76
  builder (3.2.4)
77
77
  byebug (11.1.3)
78
78
  climate_control (0.2.0)
79
79
  coderay (1.1.3)
80
- concurrent-ruby (1.2.2)
80
+ concurrent-ruby (1.2.3)
81
81
  crass (1.0.6)
82
- date (3.3.3)
83
- diff-lcs (1.5.0)
82
+ date (3.3.4)
83
+ diff-lcs (1.5.1)
84
84
  erubi (1.12.0)
85
- ffi (1.15.5)
86
- globalid (1.1.0)
87
- activesupport (>= 5.0)
88
- i18n (1.14.1)
85
+ ffi (1.16.3)
86
+ globalid (1.2.1)
87
+ activesupport (>= 6.1)
88
+ i18n (1.14.5)
89
89
  concurrent-ruby (~> 1.0)
90
- json (2.6.3)
90
+ json (2.7.2)
91
91
  language_server-protocol (3.17.0.3)
92
- listen (3.8.0)
92
+ listen (3.9.0)
93
93
  rb-fsevent (~> 0.10, >= 0.10.3)
94
94
  rb-inotify (~> 0.9, >= 0.9.10)
95
- loofah (2.21.3)
95
+ loofah (2.22.0)
96
96
  crass (~> 1.0.2)
97
97
  nokogiri (>= 1.12.0)
98
98
  mail (2.8.1)
@@ -100,27 +100,27 @@ GEM
100
100
  net-imap
101
101
  net-pop
102
102
  net-smtp
103
- marcel (1.0.2)
104
- method_source (1.0.0)
105
- mini_mime (1.1.2)
106
- mini_portile2 (2.8.2)
107
- minitest (5.18.1)
108
- msgpack (1.7.1)
109
- net-imap (0.3.6)
103
+ marcel (1.0.4)
104
+ method_source (1.1.0)
105
+ mini_mime (1.1.5)
106
+ mini_portile2 (2.8.6)
107
+ minitest (5.22.3)
108
+ msgpack (1.7.2)
109
+ net-imap (0.4.11)
110
110
  date
111
111
  net-protocol
112
112
  net-pop (0.1.2)
113
113
  net-protocol
114
- net-protocol (0.2.1)
114
+ net-protocol (0.2.2)
115
115
  timeout
116
- net-smtp (0.3.3)
116
+ net-smtp (0.5.0)
117
117
  net-protocol
118
- nio4r (2.5.9)
119
- nokogiri (1.15.2)
118
+ nio4r (2.7.3)
119
+ nokogiri (1.16.4)
120
120
  mini_portile2 (~> 2.8.2)
121
121
  racc (~> 1.4)
122
- parallel (1.23.0)
123
- parser (3.2.2.3)
122
+ parallel (1.24.0)
123
+ parser (3.3.1.0)
124
124
  ast (~> 2.4.1)
125
125
  racc
126
126
  pry (0.14.2)
@@ -129,94 +129,94 @@ GEM
129
129
  pry-byebug (3.10.1)
130
130
  byebug (~> 11.0)
131
131
  pry (>= 0.13, < 0.15)
132
- racc (1.7.1)
133
- rack (2.2.7)
132
+ racc (1.7.3)
133
+ rack (2.2.9)
134
134
  rack-test (2.1.0)
135
135
  rack (>= 1.3)
136
- rails (6.1.7.4)
137
- actioncable (= 6.1.7.4)
138
- actionmailbox (= 6.1.7.4)
139
- actionmailer (= 6.1.7.4)
140
- actionpack (= 6.1.7.4)
141
- actiontext (= 6.1.7.4)
142
- actionview (= 6.1.7.4)
143
- activejob (= 6.1.7.4)
144
- activemodel (= 6.1.7.4)
145
- activerecord (= 6.1.7.4)
146
- activestorage (= 6.1.7.4)
147
- activesupport (= 6.1.7.4)
136
+ rails (6.1.7.7)
137
+ actioncable (= 6.1.7.7)
138
+ actionmailbox (= 6.1.7.7)
139
+ actionmailer (= 6.1.7.7)
140
+ actionpack (= 6.1.7.7)
141
+ actiontext (= 6.1.7.7)
142
+ actionview (= 6.1.7.7)
143
+ activejob (= 6.1.7.7)
144
+ activemodel (= 6.1.7.7)
145
+ activerecord (= 6.1.7.7)
146
+ activestorage (= 6.1.7.7)
147
+ activesupport (= 6.1.7.7)
148
148
  bundler (>= 1.15.0)
149
- railties (= 6.1.7.4)
149
+ railties (= 6.1.7.7)
150
150
  sprockets-rails (>= 2.0.0)
151
- rails-dom-testing (2.1.1)
151
+ rails-dom-testing (2.2.0)
152
152
  activesupport (>= 5.0.0)
153
153
  minitest
154
154
  nokogiri (>= 1.6)
155
155
  rails-html-sanitizer (1.6.0)
156
156
  loofah (~> 2.21)
157
157
  nokogiri (~> 1.14)
158
- railties (6.1.7.4)
159
- actionpack (= 6.1.7.4)
160
- activesupport (= 6.1.7.4)
158
+ railties (6.1.7.7)
159
+ actionpack (= 6.1.7.7)
160
+ activesupport (= 6.1.7.7)
161
161
  method_source
162
162
  rake (>= 12.2)
163
163
  thor (~> 1.0)
164
164
  rainbow (3.1.1)
165
- rake (13.0.6)
165
+ rake (13.2.1)
166
166
  rb-fsevent (0.11.2)
167
167
  rb-inotify (0.10.1)
168
168
  ffi (~> 1.0)
169
- regexp_parser (2.8.1)
170
- responders (3.1.0)
169
+ regexp_parser (2.9.1)
170
+ responders (3.1.1)
171
171
  actionpack (>= 5.2)
172
172
  railties (>= 5.2)
173
- rexml (3.2.5)
174
- rspec (3.12.0)
175
- rspec-core (~> 3.12.0)
176
- rspec-expectations (~> 3.12.0)
177
- rspec-mocks (~> 3.12.0)
178
- rspec-core (3.12.2)
179
- rspec-support (~> 3.12.0)
180
- rspec-expectations (3.12.3)
173
+ rexml (3.2.6)
174
+ rspec (3.13.0)
175
+ rspec-core (~> 3.13.0)
176
+ rspec-expectations (~> 3.13.0)
177
+ rspec-mocks (~> 3.13.0)
178
+ rspec-core (3.13.0)
179
+ rspec-support (~> 3.13.0)
180
+ rspec-expectations (3.13.0)
181
181
  diff-lcs (>= 1.2.0, < 2.0)
182
- rspec-support (~> 3.12.0)
183
- rspec-mocks (3.12.5)
182
+ rspec-support (~> 3.13.0)
183
+ rspec-mocks (3.13.1)
184
184
  diff-lcs (>= 1.2.0, < 2.0)
185
- rspec-support (~> 3.12.0)
186
- rspec-support (3.12.1)
187
- rubocop (1.54.0)
185
+ rspec-support (~> 3.13.0)
186
+ rspec-support (3.13.1)
187
+ rubocop (1.63.5)
188
188
  json (~> 2.3)
189
189
  language_server-protocol (>= 3.17.0)
190
190
  parallel (~> 1.10)
191
- parser (>= 3.2.2.3)
191
+ parser (>= 3.3.0.2)
192
192
  rainbow (>= 2.2.2, < 4.0)
193
193
  regexp_parser (>= 1.8, < 3.0)
194
194
  rexml (>= 3.2.5, < 4.0)
195
- rubocop-ast (>= 1.28.0, < 2.0)
195
+ rubocop-ast (>= 1.31.1, < 2.0)
196
196
  ruby-progressbar (~> 1.7)
197
197
  unicode-display_width (>= 2.4.0, < 3.0)
198
- rubocop-ast (1.29.0)
199
- parser (>= 3.2.1.0)
198
+ rubocop-ast (1.31.3)
199
+ parser (>= 3.3.1.0)
200
200
  ruby-progressbar (1.13.0)
201
- sprockets (4.2.0)
201
+ sprockets (4.2.1)
202
202
  concurrent-ruby (~> 1.0)
203
203
  rack (>= 2.2.4, < 4)
204
204
  sprockets-rails (3.4.2)
205
205
  actionpack (>= 5.2)
206
206
  activesupport (>= 5.2)
207
207
  sprockets (>= 3.0.0)
208
- sqlite3 (1.6.3)
208
+ sqlite3 (1.7.3)
209
209
  mini_portile2 (~> 2.8.0)
210
- thor (1.2.2)
211
- timeout (0.4.0)
210
+ thor (1.3.1)
211
+ timeout (0.4.1)
212
212
  tzinfo (2.0.6)
213
213
  concurrent-ruby (~> 1.0)
214
- unicode-display_width (2.4.2)
215
- websocket-driver (0.7.5)
214
+ unicode-display_width (2.5.0)
215
+ websocket-driver (0.7.6)
216
216
  websocket-extensions (>= 0.1.0)
217
217
  websocket-extensions (0.1.5)
218
- yard (0.9.34)
219
- zeitwerk (2.6.8)
218
+ yard (0.9.36)
219
+ zeitwerk (2.6.13)
220
220
 
221
221
  PLATFORMS
222
222
  ruby
data/Rakefile CHANGED
@@ -29,7 +29,7 @@ namespace "test" do
29
29
  task :prepare_testapp, :force do |_t, args|
30
30
  if args.force || !File.directory?(TESTAPP_PATH)
31
31
  FileUtils.remove_entry_secure(TESTAPP_PATH, true)
32
- sh %(#{BIN} new #{TESTAPP_PATH} --skip-wizard --skip-bundle)
32
+ sh %(#{BIN} new #{TESTAPP_PATH} --skip-wizard --skip-bundle --api)
33
33
  FileUtils.chdir(TESTAPP_PATH)
34
34
  begin
35
35
  require 'mysql2'
@@ -51,7 +51,7 @@ namespace "test" do
51
51
  sh "echo '' > app/models/.gitignore" # because git reset --hard would rm the dir
52
52
  rm ".gitignore" # we need to reset everything in a testapp
53
53
  sh "git init && git add . && git commit -nm \"initial commit\""
54
- sh "rake db:create"
54
+ sh "bin/rails db:create"
55
55
  puts "The testapp has been created in '#{TESTAPP_PATH}'"
56
56
  else
57
57
  FileUtils.chdir(TESTAPP_PATH)
@@ -21,5 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.required_rubygems_version = ">= 1.3.6"
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_dependency 'rails', '>= 5.0'
24
+ s.add_dependency 'rails', '>= 6.0'
25
25
  end
@@ -8,12 +8,12 @@ gem "mail"
8
8
  gem "net-smtp"
9
9
  gem "pry"
10
10
  gem "pry-byebug"
11
- gem "rails", "~> 6.1"
11
+ gem "rails", "~> 6.1.0"
12
12
  gem "responders"
13
13
  gem "rspec"
14
14
  gem "rubocop"
15
15
  gem "yard"
16
- gem "mysql2"
16
+ gem "mysql2", "~> 0.5"
17
17
 
18
18
  group :testapp do
19
19
  gem "bootsnap", ">= 1.1.0", require: false
@@ -0,0 +1,23 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "climate_control", "~> 0.2"
7
+ gem "mail"
8
+ gem "net-smtp"
9
+ gem "pry"
10
+ gem "pry-byebug"
11
+ gem "rails", "~> 6.1.0"
12
+ gem "responders"
13
+ gem "rspec"
14
+ gem "rubocop"
15
+ gem "yard"
16
+ gem "sqlite3", "~> 1.4"
17
+
18
+ group :testapp do
19
+ gem "bootsnap", ">= 1.1.0", require: false
20
+ gem "listen"
21
+ end
22
+
23
+ gemspec path: "../"
@@ -8,12 +8,12 @@ gem "mail"
8
8
  gem "net-smtp"
9
9
  gem "pry"
10
10
  gem "pry-byebug"
11
- gem "rails", "~> 6.1"
11
+ gem "rails", "~> 7.0.0"
12
12
  gem "responders"
13
13
  gem "rspec"
14
14
  gem "rubocop"
15
15
  gem "yard"
16
- gem "sqlite3"
16
+ gem "mysql2", "~> 0.5"
17
17
 
18
18
  group :testapp do
19
19
  gem "bootsnap", ">= 1.1.0", require: false
@@ -0,0 +1,23 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "climate_control", "~> 0.2"
7
+ gem "mail"
8
+ gem "net-smtp"
9
+ gem "pry"
10
+ gem "pry-byebug"
11
+ gem "rails", "~> 7.0.0"
12
+ gem "responders"
13
+ gem "rspec"
14
+ gem "rubocop"
15
+ gem "yard"
16
+ gem "sqlite3", "~> 1.4"
17
+
18
+ group :testapp do
19
+ gem "bootsnap", ">= 1.1.0", require: false
20
+ gem "listen"
21
+ end
22
+
23
+ gemspec path: "../"
@@ -0,0 +1,23 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "climate_control", "~> 0.2"
7
+ gem "mail"
8
+ gem "net-smtp"
9
+ gem "pry"
10
+ gem "pry-byebug"
11
+ gem "rails", "~> 7.1.0"
12
+ gem "responders"
13
+ gem "rspec"
14
+ gem "rubocop"
15
+ gem "yard"
16
+ gem "mysql2", "~> 0.5"
17
+
18
+ group :testapp do
19
+ gem "bootsnap", ">= 1.1.0", require: false
20
+ gem "listen"
21
+ end
22
+
23
+ gemspec path: "../"
@@ -0,0 +1,23 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "climate_control", "~> 0.2"
7
+ gem "mail"
8
+ gem "net-smtp"
9
+ gem "pry"
10
+ gem "pry-byebug"
11
+ gem "rails", "~> 7.1.0"
12
+ gem "responders"
13
+ gem "rspec"
14
+ gem "rubocop"
15
+ gem "yard"
16
+ gem "sqlite3", "~> 1.4"
17
+
18
+ group :testapp do
19
+ gem "bootsnap", ">= 1.1.0", require: false
20
+ gem "listen"
21
+ end
22
+
23
+ gemspec path: "../"
@@ -99,6 +99,7 @@ module DeclareSchema
99
99
  _add_formatting_for_field(name, type)
100
100
  _add_validations_for_field(name, type, args, options)
101
101
  _add_index_for_field(name, args, **options)
102
+ _add_scopes_for_field(name, type, **options)
102
103
  field_specs[name] = ::DeclareSchema::Model::FieldSpec.new(self, name, type, position: field_specs.size, **options)
103
104
  attr_order << name unless attr_order.include?(name)
104
105
  end
@@ -263,9 +264,13 @@ module DeclareSchema
263
264
  # unlike the `primary_key` method, DOES NOT query the database to find the actual primary key in use right now
264
265
  # if no explicit primary key set, returns the _default_declared_primary_key
265
266
  def _declared_primary_key
266
- if defined?(@primary_key)
267
+ if !defined?(@primary_key) ||
268
+ (ActiveSupport.version >= Gem::Version.new('7.1.0') &&
269
+ @primary_key == ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods::PRIMARY_KEY_NOT_SET)
270
+ _default_declared_primary_key
271
+ else
267
272
  @primary_key&.to_s
268
- end || _default_declared_primary_key
273
+ end
269
274
  end
270
275
 
271
276
  private
@@ -314,6 +319,16 @@ module DeclareSchema
314
319
  end
315
320
  end
316
321
 
322
+ def _add_scopes_for_field(field_name, field_type, options)
323
+ if field_type == :enum && options[:scopes]
324
+ scope_prefix = options[:scopes].is_a?(Hash) ? options[:scopes][:prefix] : nil
325
+ options[:limit].each do |enum_value|
326
+ scope_name = scope_prefix ? "#{scope_prefix}_#{enum_value}" : enum_value
327
+ scope scope_name, -> { where(field_name => enum_value) }
328
+ end
329
+ end
330
+ end
331
+
317
332
  def _add_serialize_for_field(name, type, options)
318
333
  if (serialize_class = options.delete(:serialize))
319
334
  type == :string || type == :text or raise ArgumentError, "serialize field type must be :string or :text"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.4.0"
4
+ VERSION = "2.0.0"
5
5
  end
@@ -94,18 +94,7 @@ module DeclareSchema
94
94
  private
95
95
 
96
96
  def migrations_pending?
97
- migrations = case ActiveSupport::VERSION::MAJOR
98
- when 5
99
- ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).migrations
100
- else
101
- ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths, ActiveRecord::SchemaMigration).migrations
102
- end
103
- pending_migrations = case ActiveSupport::VERSION::MAJOR
104
- when 5
105
- ActiveRecord::Migrator.new(:up, migrations).pending_migrations
106
- else
107
- ActiveRecord::Migrator.new(:up, migrations, ActiveRecord::SchemaMigration).pending_migrations
108
- end
97
+ pending_migrations = load_pending_migrations
109
98
 
110
99
  pending_migrations.any?.tap do |any|
111
100
  if any
@@ -117,6 +106,32 @@ module DeclareSchema
117
106
  end
118
107
  end
119
108
 
109
+ def load_migrations
110
+ if ActiveSupport.version >= Gem::Version.new('7.1.0')
111
+ ActiveRecord::MigrationContext.new(
112
+ ActiveRecord::Migrator.migrations_paths,
113
+ ActiveRecord::Base.connection.schema_migration,
114
+ ActiveRecord::Base.connection.internal_metadata
115
+ ).migrations
116
+ else
117
+ ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths, ActiveRecord::SchemaMigration).migrations
118
+ end
119
+ end
120
+
121
+ def load_pending_migrations
122
+ migrations = load_migrations
123
+ if ActiveSupport.version >= Gem::Version.new('7.1.0')
124
+ ActiveRecord::Migrator.new(
125
+ :up,
126
+ migrations,
127
+ ActiveRecord::Base.connection.schema_migration,
128
+ ActiveRecord::Base.connection.internal_metadata
129
+ ).pending_migrations
130
+ else
131
+ ActiveRecord::Migrator.new(:up, migrations, ActiveRecord::SchemaMigration).pending_migrations
132
+ end
133
+ end
134
+
120
135
  def extract_renames!(to_create, to_drop, kind_str, name_prefix = "")
121
136
  to_rename = {}
122
137
 
@@ -39,10 +39,6 @@ RSpec.describe 'DeclareSchema API' do
39
39
 
40
40
  load_models
41
41
 
42
- if ActiveSupport::VERSION::MAJOR == 5
43
- generate_migrations '-n', '-m'
44
- end
45
-
46
42
  require 'advert'
47
43
  Advert.reset_primary_key
48
44
 
@@ -22,64 +22,34 @@ RSpec.describe 'DeclareSchema Migration Generator' do
22
22
  expect_model_definition_to_eq('alpha', <<~EOS)
23
23
  module Alpha
24
24
  def self.table_name_prefix
25
- 'alpha_'
25
+ #{ActiveSupport::VERSION::MAJOR >= 7 ? '"alpha_"' : "'alpha_'"}
26
26
  end
27
27
  end
28
28
  EOS
29
29
 
30
- case ActiveSupport::VERSION::MAJOR
31
- when 5
32
- expect_test_definition_to_eq('alpha/beta', <<~EOS)
33
- require "test_helper"
30
+ expect_test_definition_to_eq('alpha/beta', <<~EOS)
31
+ require "test_helper"
34
32
 
35
- class Alpha::BetaTest < ActiveSupport::TestCase
36
- # test "the truth" do
37
- # assert true
38
- # end
39
- end
40
- EOS
41
- else
42
- expect_test_definition_to_eq('alpha/beta', <<~EOS)
43
- require "test_helper"
44
-
45
- class Alpha::BetaTest < ActiveSupport::TestCase
46
- # test "the truth" do
47
- # assert true
48
- # end
49
- end
50
- EOS
51
- end
33
+ class Alpha::BetaTest < ActiveSupport::TestCase
34
+ # test "the truth" do
35
+ # assert true
36
+ # end
37
+ end
38
+ EOS
52
39
 
53
- case ActiveSupport::VERSION::MAJOR
54
- when 5
55
- expect_test_fixture_to_eq('alpha/beta', <<~EOS)
56
- # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
57
-
58
- # This model initially had no columns defined. If you add columns to the
59
- # model remove the '{}' from the fixture names and add the columns immediately
60
- # below each fixture, per the syntax in the comments below
61
- #
62
- one: {}
63
- # column: value
64
- #
65
- two: {}
66
- # column: value
67
- EOS
68
- when 6
69
- expect_test_fixture_to_eq('alpha/beta', <<~EOS)
70
- # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
71
-
72
- # This model initially had no columns defined. If you add columns to the
73
- # model remove the '{}' from the fixture names and add the columns immediately
74
- # below each fixture, per the syntax in the comments below
75
- #
76
- one: {}
77
- # column: value
78
- #
79
- two: {}
80
- # column: value
81
- EOS
82
- end
40
+ expect_test_fixture_to_eq('alpha/beta', <<~EOS)
41
+ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
42
+
43
+ # This model initially had no columns defined. If you add columns to the
44
+ # model remove the #{ActiveSupport::VERSION::MAJOR >= 7 ? '"{}"' : "'{}'"} from the fixture names and add the columns immediately
45
+ # below each fixture, per the syntax in the comments below
46
+ #
47
+ one: {}
48
+ # column: value
49
+ #
50
+ two: {}
51
+ # column: value
52
+ EOS
83
53
 
84
54
  $LOAD_PATH << "#{TESTAPP_PATH}/app/models"
85
55
 
@@ -88,7 +58,11 @@ RSpec.describe 'DeclareSchema Migration Generator' do
88
58
  expect(File.exist?('db/schema.rb')).to be_truthy
89
59
 
90
60
  if defined?(SQLite3)
91
- expect(File.exist?("db/development.sqlite3") || File.exist?("db/test.sqlite3")).to be_truthy
61
+ if ActiveSupport.version >= Gem::Version.new('7.1.0')
62
+ expect(File.exist?("storage/development.sqlite3") || File.exist?("storage/test.sqlite3")).to be_truthy
63
+ else
64
+ expect(File.exist?("db/development.sqlite3") || File.exist?("db/test.sqlite3")).to be_truthy
65
+ end
92
66
  end
93
67
 
94
68
  module Alpha; end
@@ -30,18 +30,15 @@ RSpec.describe 'DeclareSchema Migration Generator' do
30
30
  end
31
31
  end
32
32
  let(:datetime_precision) do
33
- if defined?(Mysql2)
33
+ if ActiveSupport::VERSION::MAJOR >= 7
34
+ ', precision: 6'
35
+ elsif defined?(Mysql2)
34
36
  ', precision: 0'
35
37
  end
36
38
  end
37
39
  let(:table_options) do
38
40
  if defined?(Mysql2)
39
- ", options: \"#{'ENGINE=InnoDB ' if ActiveSupport::VERSION::MAJOR == 5}DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\"" +
40
- if ActiveSupport::VERSION::MAJOR >= 6
41
- ', charset: "utf8mb4", collation: "utf8mb4_bin"'
42
- else
43
- ''
44
- end
41
+ ', options: "DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", charset: "utf8mb4", collation: "utf8mb4_bin"'
45
42
  else
46
43
  ", id: :integer"
47
44
  end
@@ -860,21 +857,39 @@ RSpec.describe 'DeclareSchema Migration Generator' do
860
857
  end
861
858
 
862
859
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
863
- migrate_up(<<~EOS.strip)
864
- create_table :advertisers, id: :bigint#{create_table_charset_and_collation} do |t|
865
- t.string :name, limit: 250, null: false#{charset_and_collation}
866
- end
867
- create_table :advertisers_creatives, primary_key: [:advertiser_id, :creative_id]#{create_table_charset_and_collation} do |t|
868
- t.integer :advertiser_id, limit: 8, null: false
869
- t.integer :creative_id, limit: 8, null: false
870
- end
871
- create_table :creatives, id: :bigint#{create_table_charset_and_collation} do |t|
872
- t.string :url, limit: 500, null: false#{charset_and_collation}
873
- end
874
- add_index :advertisers_creatives, [:creative_id], name: :index_advertisers_creatives_on_creative_id
875
- add_foreign_key :advertisers_creatives, :advertisers, column: :advertiser_id, name: :advertisers_creatives_FK1
876
- add_foreign_key :advertisers_creatives, :creatives, column: :creative_id, name: :advertisers_creatives_FK2
877
- EOS
860
+ if ActiveSupport.version >= Gem::Version.new('7.0.0') && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
861
+ migrate_up(<<~EOS.strip)
862
+ create_table :advertisers_creatives, primary_key: [:advertiser_id, :creative_id]#{create_table_charset_and_collation} do |t|
863
+ t.integer :advertiser_id, limit: 8, null: false
864
+ t.integer :creative_id, limit: 8, null: false
865
+ end
866
+ create_table :creatives, id: :bigint#{create_table_charset_and_collation} do |t|
867
+ t.string :url, limit: 500, null: false#{charset_and_collation}
868
+ end
869
+ create_table :advertisers, id: :bigint#{create_table_charset_and_collation} do |t|
870
+ t.string :name, limit: 250, null: false#{charset_and_collation}
871
+ end
872
+ add_index :advertisers_creatives, [:creative_id], name: :index_advertisers_creatives_on_creative_id
873
+ add_foreign_key :advertisers_creatives, :advertisers, column: :advertiser_id, name: :advertisers_creatives_FK1
874
+ add_foreign_key :advertisers_creatives, :creatives, column: :creative_id, name: :advertisers_creatives_FK2
875
+ EOS
876
+ else
877
+ migrate_up(<<~EOS.strip)
878
+ create_table :advertisers, id: :bigint#{create_table_charset_and_collation} do |t|
879
+ t.string :name, limit: 250, null: false#{charset_and_collation}
880
+ end
881
+ create_table :advertisers_creatives, primary_key: [:advertiser_id, :creative_id]#{create_table_charset_and_collation} do |t|
882
+ t.integer :advertiser_id, limit: 8, null: false
883
+ t.integer :creative_id, limit: 8, null: false
884
+ end
885
+ create_table :creatives, id: :bigint#{create_table_charset_and_collation} do |t|
886
+ t.string :url, limit: 500, null: false#{charset_and_collation}
887
+ end
888
+ add_index :advertisers_creatives, [:creative_id], name: :index_advertisers_creatives_on_creative_id
889
+ add_foreign_key :advertisers_creatives, :advertisers, column: :advertiser_id, name: :advertisers_creatives_FK1
890
+ add_foreign_key :advertisers_creatives, :creatives, column: :creative_id, name: :advertisers_creatives_FK2
891
+ EOS
892
+ end
878
893
  )
879
894
 
880
895
  nuke_model_class(Ad)
@@ -905,23 +920,43 @@ RSpec.describe 'DeclareSchema Migration Generator' do
905
920
 
906
921
  it 'will generate unique constraint names' do
907
922
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
908
- migrate_up(<<~EOS.strip)
909
- create_table :categories, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
910
- t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
911
- end
912
- create_table :advertisers, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
913
- t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
914
- t.integer :category_id, limit: 8, null: false
915
- end
916
- create_table :affiliates, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
917
- t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
918
- t.integer :category_id, limit: 8, null: false
919
- end
920
- add_index :advertisers, [:category_id], name: :index_advertisers_on_category_id
921
- add_index :affiliates, [:category_id], name: :index_affiliates_on_category_id
922
- add_foreign_key :advertisers, :categories, column: :category_id, name: :index_advertisers_on_category_id
923
- add_foreign_key :affiliates, :categories, column: :category_id, name: :index_affiliates_on_category_id
924
- EOS
923
+ if ActiveSupport.version >= Gem::Version.new('7.0.0') && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
924
+ migrate_up(<<~EOS.strip)
925
+ create_table :affiliates, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
926
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
927
+ t.integer :category_id, limit: 8, null: false
928
+ end
929
+ create_table :advertisers, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
930
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
931
+ t.integer :category_id, limit: 8, null: false
932
+ end
933
+ create_table :categories, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
934
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
935
+ end
936
+ add_index :affiliates, [:category_id], name: :index_affiliates_on_category_id
937
+ add_index :advertisers, [:category_id], name: :index_advertisers_on_category_id
938
+ add_foreign_key :affiliates, :categories, column: :category_id, name: :index_affiliates_on_category_id
939
+ add_foreign_key :advertisers, :categories, column: :category_id, name: :index_advertisers_on_category_id
940
+ EOS
941
+ else
942
+ migrate_up(<<~EOS.strip)
943
+ create_table :categories, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
944
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
945
+ end
946
+ create_table :advertisers, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
947
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
948
+ t.integer :category_id, limit: 8, null: false
949
+ end
950
+ create_table :affiliates, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
951
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
952
+ t.integer :category_id, limit: 8, null: false
953
+ end
954
+ add_index :advertisers, [:category_id], name: :index_advertisers_on_category_id
955
+ add_index :affiliates, [:category_id], name: :index_affiliates_on_category_id
956
+ add_foreign_key :advertisers, :categories, column: :category_id, name: :index_advertisers_on_category_id
957
+ add_foreign_key :affiliates, :categories, column: :category_id, name: :index_affiliates_on_category_id
958
+ EOS
959
+ end
925
960
  )
926
961
  migrate
927
962
 
@@ -6,6 +6,7 @@ rescue LoadError
6
6
  end
7
7
  require 'rails'
8
8
  require 'rails/generators'
9
+ require 'generators/declare_schema/migration/migrator'
9
10
 
10
11
  module Generators
11
12
  module DeclareSchema
data/spec/spec_helper.rb CHANGED
@@ -39,11 +39,15 @@ RSpec.configure do |config|
39
39
  end
40
40
 
41
41
  def nuke_model_class(klass)
42
- ActiveSupport::DescendantsTracker.instance_eval do
43
- direct_descendants = class_variable_get('@@direct_descendants')
44
- direct_descendants[ActiveRecord::Base] = direct_descendants[ActiveRecord::Base].to_a.reject { |descendant| descendant == klass }
45
- if defined?(ApplicationRecord)
46
- direct_descendants[ApplicationRecord] = direct_descendants[ApplicationRecord].to_a.reject { |descendant| descendant == klass }
42
+ if ActiveSupport.version >= Gem::Version.new('7.1.0') || (ActiveSupport.version >= Gem::Version.new('7.0.0') && Class.method_defined?(:subclasses))
43
+ ActiveSupport::DescendantsTracker.clear([klass])
44
+ else
45
+ ActiveSupport::DescendantsTracker.instance_eval do
46
+ direct_descendants = class_variable_get('@@direct_descendants')
47
+ direct_descendants[ActiveRecord::Base] = direct_descendants[ActiveRecord::Base].to_a.reject { |descendant| descendant == klass }
48
+ if defined?(ApplicationRecord)
49
+ direct_descendants[ApplicationRecord] = direct_descendants[ApplicationRecord].to_a.reject { |descendant| descendant == klass }
50
+ end
47
51
  end
48
52
  end
49
53
  Object.instance_eval { remove_const(klass.name.to_sym) rescue nil }
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: 2.0.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-25 00:00:00.000000000 Z
11
+ date: 2024-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '6.0'
27
27
  description: Declare your Rails/active_record model schemas and have database migrations
28
28
  generated for you!
29
29
  email: development@invoca.com
@@ -50,8 +50,12 @@ files:
50
50
  - config/brakeman.ignore
51
51
  - declare_schema.gemspec
52
52
  - gemfiles/.bundle/config
53
- - gemfiles/rails_6_mysql.gemfile
54
- - gemfiles/rails_6_sqlite.gemfile
53
+ - gemfiles/rails_6_1_mysql2.gemfile
54
+ - gemfiles/rails_6_1_sqlite3.gemfile
55
+ - gemfiles/rails_7_0_mysql2.gemfile
56
+ - gemfiles/rails_7_0_sqlite3.gemfile
57
+ - gemfiles/rails_7_1_mysql2.gemfile
58
+ - gemfiles/rails_7_1_sqlite3.gemfile
55
59
  - lib/declare_schema.rb
56
60
  - lib/declare_schema/command.rb
57
61
  - lib/declare_schema/dsl.rb
@@ -141,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
145
  - !ruby/object:Gem::Version
142
146
  version: 1.3.6
143
147
  requirements: []
144
- rubygems_version: 3.4.10
148
+ rubygems_version: 3.4.16
145
149
  signing_key:
146
150
  specification_version: 4
147
151
  summary: Database schema declaration and migration generator for Rails