declare_schema 1.4.0 → 1.5.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a00635546beea8512ef5678ea8d182612f6a6e5b099d6a13c4287e52312e8490
4
- data.tar.gz: f5ba19f1fd2dc5d3c66923dda796e413f4a3bcd4586764b254c4345602ebb984
3
+ metadata.gz: 9389b7ee742afb3976a2eb8468ab59f37782cdf1b60c75e64e0cd999aa12ae8b
4
+ data.tar.gz: 778b052b3107291f4305af5eb62798d5a3f30d931a936fdaa957f8016871d1a9
5
5
  SHA512:
6
- metadata.gz: 4cd37d8cf76460b9af36e1f05c7e5c42f370eae8fec0936e563a6dcd74e7176d1d8c66e6fa464d7e58429be220be0dbb5b6a7f5bf7c19dfb0ff834e53771e806
7
- data.tar.gz: '0870d0173821829d81c8033fda33921c8de00f7b1ec5aa2b9da56fb15b7d73b716a14058be0dc2ad595bc2bf2a6b9b66c8cdcbb612dd91fd21d88c0992b0e057'
6
+ metadata.gz: 53d80c7f261bf5e646478556ae721ee6beecf8aa98446e768292aac9f6a53ec5f3270f580095aadacc8aa7a3ad60510e9589cc2dafb6756ee14770c0a86df113
7
+ data.tar.gz: dcd96a0d62da5dc3ffc4a2f48443b93b8991053fedd3a179ba6953f08b2801c649ffc893915a7fa77c75d1ffb74f8f5b468094f6e0c645b86a92dd91caaddd75
@@ -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,11 @@ 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.5.0] - Unreleased
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
+
7
12
  ## [1.4.0] - 2024-01-24
8
13
  ### Added
9
14
  - 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)
4
+ declare_schema (1.5.0.pre.1)
5
5
  rails (>= 5.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)
@@ -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 = "1.5.0.pre.1"
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,36 @@ 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
+ elsif ActiveSupport.version >= Gem::Version.new('6.0.0')
117
+ ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths, ActiveRecord::SchemaMigration).migrations
118
+ else # Rails 5.2 and earlier
119
+ ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).migrations
120
+ end
121
+ end
122
+
123
+ def load_pending_migrations
124
+ migrations = load_migrations
125
+ if ActiveSupport.version >= Gem::Version.new('7.1.0')
126
+ ActiveRecord::Migrator.new(
127
+ :up,
128
+ migrations,
129
+ ActiveRecord::Base.connection.schema_migration,
130
+ ActiveRecord::Base.connection.internal_metadata
131
+ ).pending_migrations
132
+ elsif ActiveSupport.version >= Gem::Version.new('6.0.0')
133
+ ActiveRecord::Migrator.new(:up, migrations, ActiveRecord::SchemaMigration).pending_migrations
134
+ else # Rails 5.2 and earlier
135
+ ActiveRecord::Migrator.new(:up, migrations).pending_migrations
136
+ end
137
+ end
138
+
120
139
  def extract_renames!(to_create, to_drop, kind_str, name_prefix = "")
121
140
  to_rename = {}
122
141
 
@@ -19,13 +19,23 @@ RSpec.describe 'DeclareSchema Migration Generator' do
19
19
  end
20
20
  EOS
21
21
 
22
- expect_model_definition_to_eq('alpha', <<~EOS)
23
- module Alpha
24
- def self.table_name_prefix
25
- 'alpha_'
22
+ if ActiveSupport::VERSION::MAJOR >= 7
23
+ expect_model_definition_to_eq('alpha', <<~EOS)
24
+ module Alpha
25
+ def self.table_name_prefix
26
+ "alpha_"
27
+ end
26
28
  end
27
- end
28
- EOS
29
+ EOS
30
+ else
31
+ expect_model_definition_to_eq('alpha', <<~EOS)
32
+ module Alpha
33
+ def self.table_name_prefix
34
+ 'alpha_'
35
+ end
36
+ end
37
+ EOS
38
+ end
29
39
 
30
40
  case ActiveSupport::VERSION::MAJOR
31
41
  when 5
@@ -88,7 +98,11 @@ RSpec.describe 'DeclareSchema Migration Generator' do
88
98
  expect(File.exist?('db/schema.rb')).to be_truthy
89
99
 
90
100
  if defined?(SQLite3)
91
- expect(File.exist?("db/development.sqlite3") || File.exist?("db/test.sqlite3")).to be_truthy
101
+ if ActiveSupport.version >= Gem::Version.new('7.1.0')
102
+ expect(File.exist?("storage/development.sqlite3") || File.exist?("storage/test.sqlite3")).to be_truthy
103
+ else
104
+ expect(File.exist?("db/development.sqlite3") || File.exist?("db/test.sqlite3")).to be_truthy
105
+ end
92
106
  end
93
107
 
94
108
  module Alpha; end
@@ -30,7 +30,9 @@ 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
@@ -860,21 +862,39 @@ RSpec.describe 'DeclareSchema Migration Generator' do
860
862
  end
861
863
 
862
864
  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
865
+ if ActiveSupport.version >= Gem::Version.new('7.0.0') && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
866
+ migrate_up(<<~EOS.strip)
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
+ create_table :advertisers, id: :bigint#{create_table_charset_and_collation} do |t|
875
+ t.string :name, limit: 250, null: false#{charset_and_collation}
876
+ end
877
+ add_index :advertisers_creatives, [:creative_id], name: :index_advertisers_creatives_on_creative_id
878
+ add_foreign_key :advertisers_creatives, :advertisers, column: :advertiser_id, name: :advertisers_creatives_FK1
879
+ add_foreign_key :advertisers_creatives, :creatives, column: :creative_id, name: :advertisers_creatives_FK2
880
+ EOS
881
+ else
882
+ migrate_up(<<~EOS.strip)
883
+ create_table :advertisers, id: :bigint#{create_table_charset_and_collation} do |t|
884
+ t.string :name, limit: 250, null: false#{charset_and_collation}
885
+ end
886
+ create_table :advertisers_creatives, primary_key: [:advertiser_id, :creative_id]#{create_table_charset_and_collation} do |t|
887
+ t.integer :advertiser_id, limit: 8, null: false
888
+ t.integer :creative_id, limit: 8, null: false
889
+ end
890
+ create_table :creatives, id: :bigint#{create_table_charset_and_collation} do |t|
891
+ t.string :url, limit: 500, null: false#{charset_and_collation}
892
+ end
893
+ add_index :advertisers_creatives, [:creative_id], name: :index_advertisers_creatives_on_creative_id
894
+ add_foreign_key :advertisers_creatives, :advertisers, column: :advertiser_id, name: :advertisers_creatives_FK1
895
+ add_foreign_key :advertisers_creatives, :creatives, column: :creative_id, name: :advertisers_creatives_FK2
896
+ EOS
897
+ end
878
898
  )
879
899
 
880
900
  nuke_model_class(Ad)
@@ -905,23 +925,43 @@ RSpec.describe 'DeclareSchema Migration Generator' do
905
925
 
906
926
  it 'will generate unique constraint names' do
907
927
  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
928
+ if ActiveSupport.version >= Gem::Version.new('7.0.0') && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
929
+ migrate_up(<<~EOS.strip)
930
+ create_table :affiliates, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
931
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
932
+ t.integer :category_id, limit: 8, null: false
933
+ end
934
+ create_table :advertisers, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
935
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
936
+ t.integer :category_id, limit: 8, null: false
937
+ end
938
+ create_table :categories, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
939
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
940
+ end
941
+ add_index :affiliates, [:category_id], name: :index_affiliates_on_category_id
942
+ add_index :advertisers, [:category_id], name: :index_advertisers_on_category_id
943
+ add_foreign_key :affiliates, :categories, column: :category_id, name: :index_affiliates_on_category_id
944
+ add_foreign_key :advertisers, :categories, column: :category_id, name: :index_advertisers_on_category_id
945
+ EOS
946
+ else
947
+ migrate_up(<<~EOS.strip)
948
+ create_table :categories, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
949
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
950
+ end
951
+ create_table :advertisers, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
952
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
953
+ t.integer :category_id, limit: 8, null: false
954
+ end
955
+ create_table :affiliates, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t|
956
+ t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
957
+ t.integer :category_id, limit: 8, null: false
958
+ end
959
+ add_index :advertisers, [:category_id], name: :index_advertisers_on_category_id
960
+ add_index :affiliates, [:category_id], name: :index_affiliates_on_category_id
961
+ add_foreign_key :advertisers, :categories, column: :category_id, name: :index_advertisers_on_category_id
962
+ add_foreign_key :affiliates, :categories, column: :category_id, name: :index_affiliates_on_category_id
963
+ EOS
964
+ end
925
965
  )
926
966
  migrate
927
967
 
@@ -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: 1.5.0.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: 2024-01-25 00:00:00.000000000 Z
11
+ date: 2024-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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