sequelize-rails 0.2.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/CHANGELOG.md +3 -2
- data/Gemfile.lock +105 -103
- data/README.md +203 -26
- data/lib/sequel/rails/generators/application_record/application_record_generator.rb +26 -0
- data/lib/sequel/rails/generators/migration/migration_generator.rb +23 -0
- data/lib/sequel/rails/generators/model/model_generator.rb +11 -0
- data/lib/sequel/rails/minitest.rb +24 -0
- data/lib/sequel/rails/railtie.rb +69 -0
- data/lib/sequel/rails/railties/controller_runtime.rb +48 -0
- data/lib/sequel/rails/railties/log_subscriber.rb +155 -0
- data/lib/sequel/rails/translation_support.rb +15 -0
- data/lib/sequel/rails/version.rb +7 -0
- data/lib/sequel/rails.rb +38 -0
- data/lib/{tasks.rake → sequel/tasks.rake} +6 -6
- data/lib/sequelize-rails.rb +1 -1
- data/lib/sequelize_rails.rb +1 -29
- data/sequelize-rails.gemspec +2 -2
- data/sig/sequelize_rails.rbs +5 -3
- metadata +18 -15
- data/lib/sequelize_rails/generators/application_record/application_record_generator.rb +0 -24
- data/lib/sequelize_rails/generators/migration/migration_generator.rb +0 -21
- data/lib/sequelize_rails/generators/model/model_generator.rb +0 -9
- data/lib/sequelize_rails/railtie.rb +0 -66
- data/lib/sequelize_rails/railties/controller_runtime.rb +0 -46
- data/lib/sequelize_rails/railties/log_subscriber.rb +0 -153
- data/lib/sequelize_rails/translation_support.rb +0 -13
- data/lib/sequelize_rails/version.rb +0 -5
- /data/lib/{sequelize_rails → sequel/rails}/db_console.rb +0 -0
- /data/lib/{sequelize_rails → sequel/rails}/generators/application_record/templates/application_record.rb.tt +0 -0
- /data/lib/{sequelize_rails → sequel/rails}/generators/migration/templates/migration.rb.erb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d9b36457ef8b9c1cfc36554adb7b76a2c6262ac93fc9e6468a0c5e4eae74a04
|
4
|
+
data.tar.gz: 46a4e132f2d67a1c2aab16dcf1ec7fa39bb113f1dab39dbf2bb9a0e272af33da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d4ff60a438337fe2d9f9f440a74da942b8c9aad250c8a127500cab2ef6082dd5de45c15163abaa8f25e1ce26c7c6ad772fb24edf57995ac4c6c29191512bf4c
|
7
|
+
data.tar.gz: '08f935a29a8f038fc824d407cb8d988f0d1c0745f9465e01dbbfe870c9a4c97f021a251b3750a7b4b74e91865846d4a51121039d6aac2c2a10ddce312e72a697'
|
data/.DS_Store
ADDED
Binary file
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sequelize-rails (0.
|
4
|
+
sequelize-rails (0.3.0)
|
5
5
|
activerecord (>= 6.0.0)
|
6
6
|
rails (>= 6.0.0)
|
7
7
|
sequel (>= 5.0.0)
|
@@ -9,67 +9,67 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actioncable (7.0.3)
|
13
|
-
actionpack (= 7.0.3)
|
14
|
-
activesupport (= 7.0.3)
|
12
|
+
actioncable (7.0.4.3)
|
13
|
+
actionpack (= 7.0.4.3)
|
14
|
+
activesupport (= 7.0.4.3)
|
15
15
|
nio4r (~> 2.0)
|
16
16
|
websocket-driver (>= 0.6.1)
|
17
|
-
actionmailbox (7.0.3)
|
18
|
-
actionpack (= 7.0.3)
|
19
|
-
activejob (= 7.0.3)
|
20
|
-
activerecord (= 7.0.3)
|
21
|
-
activestorage (= 7.0.3)
|
22
|
-
activesupport (= 7.0.3)
|
17
|
+
actionmailbox (7.0.4.3)
|
18
|
+
actionpack (= 7.0.4.3)
|
19
|
+
activejob (= 7.0.4.3)
|
20
|
+
activerecord (= 7.0.4.3)
|
21
|
+
activestorage (= 7.0.4.3)
|
22
|
+
activesupport (= 7.0.4.3)
|
23
23
|
mail (>= 2.7.1)
|
24
24
|
net-imap
|
25
25
|
net-pop
|
26
26
|
net-smtp
|
27
|
-
actionmailer (7.0.3)
|
28
|
-
actionpack (= 7.0.3)
|
29
|
-
actionview (= 7.0.3)
|
30
|
-
activejob (= 7.0.3)
|
31
|
-
activesupport (= 7.0.3)
|
27
|
+
actionmailer (7.0.4.3)
|
28
|
+
actionpack (= 7.0.4.3)
|
29
|
+
actionview (= 7.0.4.3)
|
30
|
+
activejob (= 7.0.4.3)
|
31
|
+
activesupport (= 7.0.4.3)
|
32
32
|
mail (~> 2.5, >= 2.5.4)
|
33
33
|
net-imap
|
34
34
|
net-pop
|
35
35
|
net-smtp
|
36
36
|
rails-dom-testing (~> 2.0)
|
37
|
-
actionpack (7.0.3)
|
38
|
-
actionview (= 7.0.3)
|
39
|
-
activesupport (= 7.0.3)
|
37
|
+
actionpack (7.0.4.3)
|
38
|
+
actionview (= 7.0.4.3)
|
39
|
+
activesupport (= 7.0.4.3)
|
40
40
|
rack (~> 2.0, >= 2.2.0)
|
41
41
|
rack-test (>= 0.6.3)
|
42
42
|
rails-dom-testing (~> 2.0)
|
43
43
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
44
|
-
actiontext (7.0.3)
|
45
|
-
actionpack (= 7.0.3)
|
46
|
-
activerecord (= 7.0.3)
|
47
|
-
activestorage (= 7.0.3)
|
48
|
-
activesupport (= 7.0.3)
|
44
|
+
actiontext (7.0.4.3)
|
45
|
+
actionpack (= 7.0.4.3)
|
46
|
+
activerecord (= 7.0.4.3)
|
47
|
+
activestorage (= 7.0.4.3)
|
48
|
+
activesupport (= 7.0.4.3)
|
49
49
|
globalid (>= 0.6.0)
|
50
50
|
nokogiri (>= 1.8.5)
|
51
|
-
actionview (7.0.3)
|
52
|
-
activesupport (= 7.0.3)
|
51
|
+
actionview (7.0.4.3)
|
52
|
+
activesupport (= 7.0.4.3)
|
53
53
|
builder (~> 3.1)
|
54
54
|
erubi (~> 1.4)
|
55
55
|
rails-dom-testing (~> 2.0)
|
56
56
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
57
|
-
activejob (7.0.3)
|
58
|
-
activesupport (= 7.0.3)
|
57
|
+
activejob (7.0.4.3)
|
58
|
+
activesupport (= 7.0.4.3)
|
59
59
|
globalid (>= 0.3.6)
|
60
|
-
activemodel (7.0.3)
|
61
|
-
activesupport (= 7.0.3)
|
62
|
-
activerecord (7.0.3)
|
63
|
-
activemodel (= 7.0.3)
|
64
|
-
activesupport (= 7.0.3)
|
65
|
-
activestorage (7.0.3)
|
66
|
-
actionpack (= 7.0.3)
|
67
|
-
activejob (= 7.0.3)
|
68
|
-
activerecord (= 7.0.3)
|
69
|
-
activesupport (= 7.0.3)
|
60
|
+
activemodel (7.0.4.3)
|
61
|
+
activesupport (= 7.0.4.3)
|
62
|
+
activerecord (7.0.4.3)
|
63
|
+
activemodel (= 7.0.4.3)
|
64
|
+
activesupport (= 7.0.4.3)
|
65
|
+
activestorage (7.0.4.3)
|
66
|
+
actionpack (= 7.0.4.3)
|
67
|
+
activejob (= 7.0.4.3)
|
68
|
+
activerecord (= 7.0.4.3)
|
69
|
+
activesupport (= 7.0.4.3)
|
70
70
|
marcel (~> 1.0)
|
71
71
|
mini_mime (>= 1.1.0)
|
72
|
-
activesupport (7.0.3)
|
72
|
+
activesupport (7.0.4.3)
|
73
73
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
74
74
|
i18n (>= 1.6, < 2)
|
75
75
|
minitest (>= 5.1)
|
@@ -82,118 +82,120 @@ GEM
|
|
82
82
|
ast (2.4.2)
|
83
83
|
builder (3.2.4)
|
84
84
|
coderay (1.1.3)
|
85
|
-
concurrent-ruby (1.
|
85
|
+
concurrent-ruby (1.2.2)
|
86
86
|
crass (1.0.6)
|
87
|
-
|
88
|
-
erubi (1.
|
89
|
-
globalid (1.
|
87
|
+
date (3.3.3)
|
88
|
+
erubi (1.12.0)
|
89
|
+
globalid (1.1.0)
|
90
90
|
activesupport (>= 5.0)
|
91
|
-
i18n (1.
|
91
|
+
i18n (1.12.0)
|
92
92
|
concurrent-ruby (~> 1.0)
|
93
|
-
|
93
|
+
json (2.6.3)
|
94
|
+
language_server-protocol (3.17.0.3)
|
95
|
+
loofah (2.19.1)
|
94
96
|
crass (~> 1.0.2)
|
95
97
|
nokogiri (>= 1.5.9)
|
96
|
-
mail (2.
|
98
|
+
mail (2.8.1)
|
97
99
|
mini_mime (>= 0.1.1)
|
100
|
+
net-imap
|
101
|
+
net-pop
|
102
|
+
net-smtp
|
98
103
|
marcel (1.0.2)
|
99
104
|
method_source (1.0.0)
|
100
105
|
mini_mime (1.1.2)
|
101
|
-
mini_portile2 (2.8.
|
102
|
-
minitest (5.
|
103
|
-
minitest-reporters (1.
|
106
|
+
mini_portile2 (2.8.1)
|
107
|
+
minitest (5.18.0)
|
108
|
+
minitest-reporters (1.6.0)
|
104
109
|
ansi
|
105
110
|
builder
|
106
111
|
minitest (>= 5.0)
|
107
112
|
ruby-progressbar
|
108
|
-
net-imap (0.
|
109
|
-
|
113
|
+
net-imap (0.3.4)
|
114
|
+
date
|
110
115
|
net-protocol
|
111
|
-
|
112
|
-
net-pop (0.1.1)
|
113
|
-
digest
|
116
|
+
net-pop (0.1.2)
|
114
117
|
net-protocol
|
118
|
+
net-protocol (0.2.1)
|
115
119
|
timeout
|
116
|
-
net-
|
117
|
-
timeout
|
118
|
-
net-smtp (0.3.1)
|
119
|
-
digest
|
120
|
+
net-smtp (0.3.3)
|
120
121
|
net-protocol
|
121
|
-
timeout
|
122
122
|
nio4r (2.5.8)
|
123
|
-
nokogiri (1.
|
123
|
+
nokogiri (1.14.2)
|
124
124
|
mini_portile2 (~> 2.8.0)
|
125
125
|
racc (~> 1.4)
|
126
126
|
parallel (1.22.1)
|
127
|
-
parser (3.1.
|
127
|
+
parser (3.2.1.1)
|
128
128
|
ast (~> 2.4.1)
|
129
|
-
pg (1.
|
130
|
-
pry (0.14.
|
129
|
+
pg (1.4.6)
|
130
|
+
pry (0.14.2)
|
131
131
|
coderay (~> 1.1)
|
132
132
|
method_source (~> 1.0)
|
133
|
-
racc (1.6.
|
134
|
-
rack (2.2.
|
135
|
-
rack-test (
|
136
|
-
rack (>= 1.
|
137
|
-
rails (7.0.3)
|
138
|
-
actioncable (= 7.0.3)
|
139
|
-
actionmailbox (= 7.0.3)
|
140
|
-
actionmailer (= 7.0.3)
|
141
|
-
actionpack (= 7.0.3)
|
142
|
-
actiontext (= 7.0.3)
|
143
|
-
actionview (= 7.0.3)
|
144
|
-
activejob (= 7.0.3)
|
145
|
-
activemodel (= 7.0.3)
|
146
|
-
activerecord (= 7.0.3)
|
147
|
-
activestorage (= 7.0.3)
|
148
|
-
activesupport (= 7.0.3)
|
133
|
+
racc (1.6.2)
|
134
|
+
rack (2.2.6.4)
|
135
|
+
rack-test (2.1.0)
|
136
|
+
rack (>= 1.3)
|
137
|
+
rails (7.0.4.3)
|
138
|
+
actioncable (= 7.0.4.3)
|
139
|
+
actionmailbox (= 7.0.4.3)
|
140
|
+
actionmailer (= 7.0.4.3)
|
141
|
+
actionpack (= 7.0.4.3)
|
142
|
+
actiontext (= 7.0.4.3)
|
143
|
+
actionview (= 7.0.4.3)
|
144
|
+
activejob (= 7.0.4.3)
|
145
|
+
activemodel (= 7.0.4.3)
|
146
|
+
activerecord (= 7.0.4.3)
|
147
|
+
activestorage (= 7.0.4.3)
|
148
|
+
activesupport (= 7.0.4.3)
|
149
149
|
bundler (>= 1.15.0)
|
150
|
-
railties (= 7.0.3)
|
150
|
+
railties (= 7.0.4.3)
|
151
151
|
rails-dom-testing (2.0.3)
|
152
152
|
activesupport (>= 4.2.0)
|
153
153
|
nokogiri (>= 1.6)
|
154
|
-
rails-html-sanitizer (1.
|
155
|
-
loofah (~> 2.
|
156
|
-
railties (7.0.3)
|
157
|
-
actionpack (= 7.0.3)
|
158
|
-
activesupport (= 7.0.3)
|
154
|
+
rails-html-sanitizer (1.5.0)
|
155
|
+
loofah (~> 2.19, >= 2.19.1)
|
156
|
+
railties (7.0.4.3)
|
157
|
+
actionpack (= 7.0.4.3)
|
158
|
+
activesupport (= 7.0.4.3)
|
159
159
|
method_source
|
160
160
|
rake (>= 12.2)
|
161
161
|
thor (~> 1.0)
|
162
162
|
zeitwerk (~> 2.5)
|
163
163
|
rainbow (3.1.1)
|
164
164
|
rake (13.0.6)
|
165
|
-
regexp_parser (2.
|
165
|
+
regexp_parser (2.7.0)
|
166
166
|
rexml (3.2.5)
|
167
|
-
rubocop (1.
|
167
|
+
rubocop (1.48.1)
|
168
|
+
json (~> 2.3)
|
168
169
|
parallel (~> 1.10)
|
169
|
-
parser (>= 3.
|
170
|
+
parser (>= 3.2.0.0)
|
170
171
|
rainbow (>= 2.2.2, < 4.0)
|
171
172
|
regexp_parser (>= 1.8, < 3.0)
|
172
173
|
rexml (>= 3.2.5, < 4.0)
|
173
|
-
rubocop-ast (>= 1.
|
174
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
174
175
|
ruby-progressbar (~> 1.7)
|
175
|
-
unicode-display_width (>=
|
176
|
-
rubocop-ast (1.
|
177
|
-
parser (>= 3.
|
178
|
-
rubocop-performance (1.
|
176
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
177
|
+
rubocop-ast (1.27.0)
|
178
|
+
parser (>= 3.2.1.0)
|
179
|
+
rubocop-performance (1.16.0)
|
179
180
|
rubocop (>= 1.7.0, < 2.0)
|
180
181
|
rubocop-ast (>= 0.4.0)
|
181
|
-
ruby-progressbar (1.
|
182
|
-
sequel (5.
|
183
|
-
sqlite3 (1.
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
182
|
+
ruby-progressbar (1.13.0)
|
183
|
+
sequel (5.66.0)
|
184
|
+
sqlite3 (1.6.1)
|
185
|
+
mini_portile2 (~> 2.8.0)
|
186
|
+
standard (1.25.3)
|
187
|
+
language_server-protocol (~> 3.17.0.2)
|
188
|
+
rubocop (~> 1.48.1)
|
189
|
+
rubocop-performance (~> 1.16.0)
|
188
190
|
thor (1.2.1)
|
189
|
-
timeout (0.3.
|
190
|
-
tzinfo (2.0.
|
191
|
+
timeout (0.3.2)
|
192
|
+
tzinfo (2.0.6)
|
191
193
|
concurrent-ruby (~> 1.0)
|
192
|
-
unicode-display_width (2.
|
194
|
+
unicode-display_width (2.4.2)
|
193
195
|
websocket-driver (0.7.5)
|
194
196
|
websocket-extensions (>= 0.1.0)
|
195
197
|
websocket-extensions (0.1.5)
|
196
|
-
zeitwerk (2.6.
|
198
|
+
zeitwerk (2.6.7)
|
197
199
|
|
198
200
|
PLATFORMS
|
199
201
|
ruby
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# sequelize-rails
|
2
2
|
|
3
|
-
|
3
|
+
![Gem Version](https://badge.fury.io/rb/sequelize-rails.svg)
|
4
|
+
![Build Status](https://github.com/kenaniah/sequelize-rails/actions/workflows/ci.yml/badge.svg)
|
5
|
+
![Code Climate](https://codeclimate.com/github/kenaniah/sequelize-rails.svg)
|
4
6
|
|
5
|
-
|
7
|
+
This gem provides support for using [Sequel](https://sequel.jeremyevans.net/) as an ORM for Rails applications by providing features that are similar to ActiveRecord's integration with Rails. It is an alternative to [sequel-rails](https://github.com/TalentBox/sequel-rails).
|
6
8
|
|
7
|
-
##
|
9
|
+
## Using sequelize-rails
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
10
12
|
|
@@ -16,38 +18,213 @@ And then execute:
|
|
16
18
|
|
17
19
|
$ bundle install
|
18
20
|
|
19
|
-
|
21
|
+
If you are looking to replace ActiveRecord entirely, you may need to either generate your Rails app using `--skip-active-record` or manually remove references to ActiveRecord in your `Gemfile`, `config/application.rb`, and `config/environments/*.rb` files.
|
20
22
|
|
21
|
-
|
23
|
+
## Features provided by `sequelize-rails`
|
22
24
|
|
23
|
-
|
25
|
+
**Database Management**
|
24
26
|
|
25
|
-
|
27
|
+
- [x] [Connectivity](#---database-connectivity) via `config/database.yml`
|
28
|
+
- [x] [Console](#---database-console) via `rails db`
|
29
|
+
- [x] [Migrations](#---database-migrations) via `Sequel::Migration`
|
30
|
+
- [ ] [Migration Generators](#---migration-generators) via `rails generate migration` (not supported yet)
|
31
|
+
- [x] [Rake tasks](#---database-rake-tasks) via `rails db:*`
|
26
32
|
|
27
|
-
|
33
|
+
**Test Suite**
|
28
34
|
|
29
|
-
|
35
|
+
- [x] [Minitest Helpers](#---minitest-helpers)
|
30
36
|
|
31
|
-
|
37
|
+
**Rake Helpers**
|
32
38
|
|
33
|
-
|
39
|
+
- [x] Does not connect to the primary database in Rake (tasks by default)
|
40
|
+
- [x] Allows for explicit connection to the primary database by invoking `db:connection`
|
41
|
+
|
42
|
+
## ✅ - Database Connectivity
|
43
|
+
|
44
|
+
This gem will automatically use your application's `config/database.yml` file to configure the available database connection(s).
|
45
|
+
|
46
|
+
### Primary Connection
|
47
|
+
|
48
|
+
A connection to the "primary" database is automatically established when the application is loaded. This connection will by used by default for all model classes that do not specify a different connection.
|
49
|
+
|
50
|
+
The primary connection can be referenced directly via:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
Sequel::DATABASES.first # instead of ActiveRecord::Base.connection
|
54
|
+
```
|
55
|
+
|
56
|
+
A common convention within applications that use Sequel is to store the primary connection in the `DB` constant, which can be easily done within an initializer file via the following:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
# config/initializers/sequel.rb
|
60
|
+
DB = Sequel::DATABASES.first unless defined?(DB)
|
61
|
+
```
|
62
|
+
|
63
|
+
### Additional Connections
|
64
|
+
|
65
|
+
Additional connections can be configured in your `config/database.yml` file by adding additional entries to the `databases` key. For example:
|
66
|
+
|
67
|
+
```yaml
|
68
|
+
# config/database.yml
|
69
|
+
|
70
|
+
# ... snip ...
|
71
|
+
|
72
|
+
production:
|
73
|
+
<<: *default
|
74
|
+
database: <%= ENV["DATABASE_URL"] %>
|
75
|
+
|
76
|
+
my_replica:
|
77
|
+
<<: *default
|
78
|
+
database: <%= ENV["REPLICA_DATABASE_URL"] %>
|
79
|
+
|
80
|
+
```
|
81
|
+
|
82
|
+
Additional connections can be retrieved via `Sequel::Rails.connect_to`, such as within the example below:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
replica_connection = Sequel::Rails.connect_to :my_replica
|
86
|
+
```
|
87
|
+
|
88
|
+
### Database Connections in Rake Tasks
|
89
|
+
|
90
|
+
By default, this gem will not connect to the primary database when running Rake tasks. This is to prevent Rake tasks from accidentally depending on a database connection when one is not necessary. If you would like to connect to the primary database within a Rake task, you can do so by invoking the `db:connection` task, or by calling `Sequel::Rails.connect_to :primary` from within your task.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
# Rakefile
|
94
|
+
|
95
|
+
# no database connections are initialized by default
|
96
|
+
task :no_db_connection do
|
97
|
+
Sequel::DATABASES # => []
|
98
|
+
Sequel::DATABASES.length # => 0
|
99
|
+
end
|
100
|
+
|
101
|
+
# connects to the primary database explicitly
|
102
|
+
task :my_task do
|
103
|
+
db = Sequel::Rails.connect_to :primary
|
104
|
+
Sequel::DATABASES # => [db]
|
105
|
+
Sequel::DATABASES.length # => 1
|
106
|
+
end
|
107
|
+
|
108
|
+
# connects to the primary database via the db:connection task
|
109
|
+
task :my_other_task => "db:connection" do
|
110
|
+
Sequel::DATABASES # => [<primary db connection here>]
|
111
|
+
Sequel::DATABASES.length # => 1
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
## ✅ - Database Console
|
116
|
+
|
117
|
+
You can connect directly to your database via the `rails db` command. This command is similar to the `rails console` command, but instead of loading your application, it will connect directly to the database.
|
118
|
+
|
119
|
+
```bash
|
120
|
+
# connects to the primary database
|
121
|
+
$ rails db
|
122
|
+
|
123
|
+
# connects to the database of the test environment
|
124
|
+
$ rails db -e test
|
125
|
+
```
|
126
|
+
|
127
|
+
Please note that only the `-e` flag is supported at this time. Other flags such as `--database` are not supported.
|
128
|
+
|
129
|
+
## ✅ - Database Migrations
|
130
|
+
|
131
|
+
This gem provides support for using Sequel's migration system. Migrations are stored in the `db/migrate` directory and can be executed via the `rails db:migrate` command.
|
132
|
+
|
133
|
+
More information about Sequel's migration system can be found in the [Sequel documentation](https://sequel.jeremyevans.net/rdoc/files/doc/migration_rdoc.html).
|
134
|
+
|
135
|
+
## 🚧 - Migration Generators
|
136
|
+
|
137
|
+
Rails supports the generation of migrations via the `rails generate migration` command. This gem does not currently support this feature, but pull requests are welcome.
|
138
|
+
|
139
|
+
## ✅ - Database Rake Tasks
|
140
|
+
|
141
|
+
This gem provides a set of rake tasks that are similar to the ActiveRecord tasks. These tasks can be used to create, drop, migrate, and seed your database.
|
142
|
+
|
143
|
+
| Task | Description |
|
144
|
+
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
145
|
+
| `rails db:create` | Creates the database from `DATABASE_URL` or `config/database.yml` for the current `RAILS_ENV` (use `db:create:all` to create all databases in the config). |
|
146
|
+
| `rails db:drop` | Drops the database from `DATABASE_URL` or `config/database.yml` for the current `RAILS_ENV` (use `db:drop:all` to drop all databases in the config). |
|
147
|
+
| `rails db:migrate` | Runs database migrations |
|
148
|
+
| `rails db:migrate:redo` | Rolls back the last migration and re-runs it |
|
149
|
+
| `rails db:migrate:status` | Displays the status of the database migrations |
|
150
|
+
| `rails db:prepare` | Runs `db:setup` if the database does not exist or `db:migrate` if it does |
|
151
|
+
| `rails db:reset` | Runs `db:drop`, `db:setup` |
|
152
|
+
| `rails db:rollback` | Rolls back the last migration |
|
153
|
+
| `rails db:setup` | Runs the `db:create`, `db:migrate`, `db:seed` tasks |
|
154
|
+
|
155
|
+
## ✅ - Minitest Helpers
|
156
|
+
|
157
|
+
### `assert_num_queries`
|
158
|
+
|
159
|
+
This helper can be used to assert that a specific number of database queries are executed within the given block of code.
|
160
|
+
|
161
|
+
Example:
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
# asserts that exactly 2 queries are executed
|
165
|
+
assert_num_queries(2) do
|
166
|
+
u = User[id: 1234]
|
167
|
+
u.update(name: "Random User")
|
168
|
+
end
|
169
|
+
|
170
|
+
# asserts that 0 queries are executed
|
171
|
+
assert_num_queries(0) do
|
172
|
+
some_hopefully_cached_method
|
173
|
+
end
|
174
|
+
|
175
|
+
# asserts that 1 to 3 queries are executed
|
176
|
+
assert_num_queries(1..3) do
|
177
|
+
u = User.find_or_create(name: "Random User")
|
178
|
+
end
|
179
|
+
|
180
|
+
# asserts that at least 3 queries are executed
|
181
|
+
assert_num_queries(3..) do
|
182
|
+
stuff_here
|
183
|
+
end
|
184
|
+
|
185
|
+
# asserts that no more than 2 queries are executed
|
186
|
+
assert_num_queries(..2) do
|
187
|
+
other_stuff_here
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
191
|
+
### `assert_no_queries`
|
192
|
+
|
193
|
+
This helper can be used to assert that no database queries are executed within the given block of code.
|
194
|
+
|
195
|
+
Example:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
# asserts that no queries are executed
|
199
|
+
assert_no_queries do
|
200
|
+
some_hopefully_cached_method
|
201
|
+
end
|
202
|
+
```
|
203
|
+
|
204
|
+
# Contributing
|
34
205
|
|
35
206
|
Bug reports and pull requests are welcome on GitHub at https://github.com/kenaniah/sequelize-rails.
|
36
207
|
|
37
|
-
|
208
|
+
This repository contains a handful of commands that can be used to facilitate this gem's development. These are:
|
209
|
+
|
210
|
+
| Command | Description |
|
211
|
+
| -------------------------- | ---------------------------------------------------------------------------------------- |
|
212
|
+
| `bin/setup` | Installs the gem's development dependencies |
|
213
|
+
| `bin/test` | Runs the test suite for each supported Rails version |
|
214
|
+
| `bin/console` | Starts an interactive console within the gem's test Rails app (located in `test/dummy/`) |
|
215
|
+
| `bundle exec rake release` | Creates a new release of the gem (version number should be bumped first) |
|
216
|
+
|
217
|
+
# License
|
38
218
|
|
39
219
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
220
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
- [ ] Support PostgreSQL custom format for dump & restore
|
52
|
-
- [ ] Support generators (including orm)
|
53
|
-
- [ ] Support migration generator (and parsed attributes)
|
221
|
+
# Roadmap
|
222
|
+
|
223
|
+
- [ ] Support `rails console --sandbox` (auto rollback all transactions)
|
224
|
+
- [ ] Support logging
|
225
|
+
- [ ] Support db rake tasks
|
226
|
+
- [ ] Support reloading (disconnect all connections)
|
227
|
+
- [ ] Support ActiveRecord plugins / conventions (shims)
|
228
|
+
- [ ] Support PostgreSQL custom format for dump & restore
|
229
|
+
- [ ] Support generators (including orm)
|
230
|
+
- [ ] Support migration generator (and parsed attributes)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sequel
|
4
|
+
module Rails
|
5
|
+
module Generators
|
6
|
+
class ApplicationRecordGenerator < ::Rails::Generators::Base
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
def create_application_record
|
10
|
+
template "application_record.rb", application_record_file_name
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def application_record_file_name
|
16
|
+
@application_record_file_name ||=
|
17
|
+
if namespaced?
|
18
|
+
"app/models/#{namespaced_path}/application_record.rb"
|
19
|
+
else
|
20
|
+
"app/models/application_record.rb"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sequel
|
4
|
+
module Rails
|
5
|
+
module Generators
|
6
|
+
class MigrationGenerator < ::Rails::Generators::NamedBase
|
7
|
+
include ::Rails::Generators::Migration
|
8
|
+
|
9
|
+
source_root File.expand_path("templates", __dir__)
|
10
|
+
|
11
|
+
argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
|
12
|
+
|
13
|
+
def self.next_migration_number _dirname
|
14
|
+
Time.now.strftime "%Y%m%d%H%M%S"
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_migration_file
|
18
|
+
migration_template "migration.rb.erb", "db/migrate/#{file_name}.rb"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Minitest
|
2
|
+
module Assertions
|
3
|
+
def assert_num_queries(num, &block)
|
4
|
+
before = ::Sequel::Rails::Railties::LogSubscriber.count
|
5
|
+
res = yield
|
6
|
+
after = ::Sequel::Rails::Railties::LogSubscriber.count
|
7
|
+
|
8
|
+
case num
|
9
|
+
when Range
|
10
|
+
assert num.include?(after - before), "The number of database queries did not match expectations...\nExpected: #{num} (range)\n Actual: #{after - before}"
|
11
|
+
when Integer
|
12
|
+
assert num == after - before, "The number of database queries did not match expectations...\nExpected: #{num}\n Actual: #{after - before}"
|
13
|
+
else
|
14
|
+
raise ArgumentError, "Invalid argument passed to assert_num_queries: expected a Range or Integer value, but received #{num.inspect} instead."
|
15
|
+
end
|
16
|
+
|
17
|
+
res
|
18
|
+
end
|
19
|
+
|
20
|
+
def assert_no_queries(&block)
|
21
|
+
assert_num_queries(0, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|