request_migrations 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +59 -13
- data/SECURITY.md +4 -3
- data/lib/request_migrations/configuration.rb +10 -7
- data/lib/request_migrations/gem.rb +1 -1
- data/lib/request_migrations/testing.rb +1 -4
- data/lib/request_migrations.rb +3 -6
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a4bcd66e61c3fbda8dd1a2d68c84953bd44cfb2b1c9fed79e90a0965cb1853d
|
|
4
|
+
data.tar.gz: b772558c45d89f41d9c0eceab0b118e141fd93f31d40e037b810b669f2dfc997
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d6727a31da8a3bbf69d013af4c68a873ff7c1c09a17f407906f27469df8c822aa070207e9ab6fa39299e3ef2960c8184efa954f9417c6678c3f242808add7cfa
|
|
7
|
+
data.tar.gz: 7086a2c8604219bef3d9b7040897f0faa30cb2ff19d800ea1ab9011db3dad2d11b25d8e77b2e98b09175b90e2ad93180664278c60ea5af9d47fbe4c52c6b8388
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.2
|
|
4
|
+
|
|
5
|
+
- Remove deprecated `ActiveSupport::Configurable`.
|
|
6
|
+
|
|
7
|
+
## 1.1.1
|
|
8
|
+
|
|
9
|
+
- Fix minimum required Ruby version from v3.0 to v3.1.
|
|
10
|
+
|
|
11
|
+
## 1.1.0
|
|
12
|
+
|
|
13
|
+
- Add `request_migrations/testing` for unit testing migrations.
|
|
14
|
+
|
|
3
15
|
## 1.0.1
|
|
4
16
|
|
|
5
17
|
- Fix application order of `request` migrations.
|
data/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# request_migrations
|
|
2
2
|
|
|
3
|
+
[](https://github.com/keygen-sh/request_migrations/actions)
|
|
3
4
|
[](https://badge.fury.io/rb/request_migrations)
|
|
4
5
|
|
|
5
6
|
**Make breaking API changes without breaking things!** Use `request_migrations` to craft
|
|
@@ -13,9 +14,32 @@ to serve millions of API requests per day.
|
|
|
13
14
|
|
|
14
15
|
Sponsored by:
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
<a href="https://keygen.sh?ref=request_migrations">
|
|
18
|
+
<div>
|
|
19
|
+
<img src="https://keygen.sh/images/logo-pill.png" width="200" alt="Keygen">
|
|
20
|
+
</div>
|
|
21
|
+
</a>
|
|
22
|
+
|
|
23
|
+
_A fair source software licensing and distribution API._
|
|
24
|
+
|
|
25
|
+
Links:
|
|
26
|
+
|
|
27
|
+
- [Installing request_migrations](#installation)
|
|
28
|
+
- [Supported Ruby versions](#supported-rubies)
|
|
29
|
+
- [RubyDoc](#documentation)
|
|
30
|
+
- [Usage](#usage)
|
|
31
|
+
- [Response migrations](#response-migrations)
|
|
32
|
+
- [Request migrations](#request-migrations)
|
|
33
|
+
- [Data migrations](#data-migrations)
|
|
34
|
+
- [Routing constraints](#routing-constraints)
|
|
35
|
+
- [Configuration](#configuration)
|
|
36
|
+
- [Version formats](#version-formats)
|
|
37
|
+
- [Testing](#testing)
|
|
38
|
+
- [Tips and tricks](#tips-and-tricks)
|
|
39
|
+
- [Examples](#examples)
|
|
40
|
+
- [Credits](#credits)
|
|
41
|
+
- [Contributing](#contributing)
|
|
42
|
+
- [License](#license)
|
|
19
43
|
|
|
20
44
|
## Installation
|
|
21
45
|
|
|
@@ -39,8 +63,9 @@ $ gem install request_migrations
|
|
|
39
63
|
|
|
40
64
|
## Supported Rubies
|
|
41
65
|
|
|
42
|
-
|
|
43
|
-
version. Ruby 3 provides a lot of great features, like better pattern matching
|
|
66
|
+
**`request_migrations` supports Ruby 3.1 and above.** We encourage you to upgrade if you're on an older
|
|
67
|
+
version. Ruby 3 provides a lot of great features, like better pattern matching and a new shorthand
|
|
68
|
+
hash syntax.
|
|
44
69
|
|
|
45
70
|
## Documentation
|
|
46
71
|
|
|
@@ -124,8 +149,8 @@ end
|
|
|
124
149
|
|
|
125
150
|
As you can see, with pattern matching, it makes creating migrations for certain
|
|
126
151
|
resources simple. Here, we've defined a migration that only runs for the `users#show`
|
|
127
|
-
|
|
128
|
-
|
|
152
|
+
resource, and only when the response is successful. In addition, the data is
|
|
153
|
+
only migrated when the response body contains a user.
|
|
129
154
|
|
|
130
155
|
Next, we'll need to configure `request_migrations` via an initializer under
|
|
131
156
|
`initializers/request_migrations.rb`:
|
|
@@ -198,6 +223,8 @@ The gem makes no assumption on a response's content type or what the migration
|
|
|
198
223
|
will do. You could, for example, migrate the response body, or mutate the
|
|
199
224
|
headers, or even change the response's status code.
|
|
200
225
|
|
|
226
|
+
The `response` method can be used multiple times per-migration.
|
|
227
|
+
|
|
201
228
|
### Request migrations
|
|
202
229
|
|
|
203
230
|
Request migrations define a change on a request. For example, modifying a request's
|
|
@@ -225,6 +252,8 @@ headers. It's up to you, all it does is provide the request.
|
|
|
225
252
|
|
|
226
253
|
Request migrations should [avoid using the `migrate` method](#avoid-migrate-for-request-migrations).
|
|
227
254
|
|
|
255
|
+
The `request` method can be used multiple times.
|
|
256
|
+
|
|
228
257
|
### Data migrations
|
|
229
258
|
|
|
230
259
|
In our first scenario, where we combined our user's name attributes, we defined
|
|
@@ -292,10 +321,15 @@ end
|
|
|
292
321
|
|
|
293
322
|
This will apply the block defined in `migrate` onto our data. With that,
|
|
294
323
|
we've successfully applied a migration to both our API responses, as well
|
|
295
|
-
as to the webhook events we send. In this case, if our
|
|
296
|
-
our
|
|
324
|
+
as to the webhook events we send. In this case, if our event data matches
|
|
325
|
+
our expected data shape, e.g. `type: 'user'`, then the migration will
|
|
326
|
+
be applied.
|
|
297
327
|
|
|
298
|
-
In addition to data migrations, this allows for easier testing.
|
|
328
|
+
In addition to data migrations, this allows for easier [testing](#testing).
|
|
329
|
+
|
|
330
|
+
The `migrate` method can be used multiple times per-migration to e.g.
|
|
331
|
+
match and migrate on different shapes of data. For a JSON:API app,
|
|
332
|
+
for example, you could migrate on `data: [*]` and `includes: [*]`.
|
|
299
333
|
|
|
300
334
|
### Routing constraints
|
|
301
335
|
|
|
@@ -406,9 +440,11 @@ end
|
|
|
406
440
|
```
|
|
407
441
|
|
|
408
442
|
To avoid polluting the global configuration, you can use `RequestMigrations::Testing`
|
|
409
|
-
within your application's `spec/rails_helper.rb
|
|
443
|
+
within your application's `spec/rails_helper.rb`, or a similar spec helper:
|
|
410
444
|
|
|
411
445
|
```ruby
|
|
446
|
+
require 'request_migrations/testing'
|
|
447
|
+
|
|
412
448
|
Rspec.configure do |config|
|
|
413
449
|
config.before :each do
|
|
414
450
|
RequestMigrations::Testing.setup!
|
|
@@ -420,6 +456,9 @@ Rspec.configure do |config|
|
|
|
420
456
|
end
|
|
421
457
|
```
|
|
422
458
|
|
|
459
|
+
This will setup a new test configuration, and then restore the previous global configuration
|
|
460
|
+
after each spec.
|
|
461
|
+
|
|
423
462
|
## Tips and tricks
|
|
424
463
|
|
|
425
464
|
Over the years, we're learned a thing or two about versioning an API. We'll share tips here.
|
|
@@ -502,7 +541,7 @@ end
|
|
|
502
541
|
And for a response containing a collection of users:
|
|
503
542
|
|
|
504
543
|
```ruby
|
|
505
|
-
class
|
|
544
|
+
class CombineNamesForUsersMigration < RequestMigrations::Migration
|
|
506
545
|
description %(transforms a collection of users' first and last names to a combined name attribute)
|
|
507
546
|
|
|
508
547
|
migrate if: -> data { data in [*, { type: 'user' }, *] do |data|
|
|
@@ -603,7 +642,7 @@ end
|
|
|
603
642
|
|
|
604
643
|
Avoid using routing version constraints that remove functionality. They can be a headache
|
|
605
644
|
during upgrades. Consider only making _additive_ changes. Instead, consider removing or
|
|
606
|
-
hiding the
|
|
645
|
+
hiding the documentation for old or deprecated endpoints, to limit any new usage.
|
|
607
646
|
|
|
608
647
|
```ruby
|
|
609
648
|
Rails.application.routes.draw do
|
|
@@ -680,6 +719,13 @@ to get the data we need in order to complete the migration.
|
|
|
680
719
|
|
|
681
720
|
Have a tip of your own? Open a pull request!
|
|
682
721
|
|
|
722
|
+
## Examples
|
|
723
|
+
|
|
724
|
+
Below are some real-world examples of request migrations:
|
|
725
|
+
|
|
726
|
+
- Migrations: https://github.com/keygen-sh/keygen-api/tree/master/app/migrations
|
|
727
|
+
- Tests: https://github.com/keygen-sh/keygen-api/tree/master/spec/migrations
|
|
728
|
+
|
|
683
729
|
## Is it any good?
|
|
684
730
|
|
|
685
731
|
Yes.
|
data/SECURITY.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Security Policy
|
|
2
2
|
|
|
3
|
-
## Reporting a
|
|
3
|
+
## Reporting a vulnerability
|
|
4
4
|
|
|
5
5
|
If you find a vulnerability in `request_migrations`, please contact Keygen via
|
|
6
|
-
[email](mailto:security@keygen.sh).
|
|
7
|
-
|
|
6
|
+
[email](mailto:security@keygen.sh).
|
|
7
|
+
|
|
8
|
+
You will be given public credit for your disclosure.
|
|
@@ -2,37 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
module RequestMigrations
|
|
4
4
|
class Configuration
|
|
5
|
-
include ActiveSupport::Configurable
|
|
6
|
-
|
|
7
5
|
##
|
|
8
6
|
# logger defines the logger used by request_migrations.
|
|
9
7
|
#
|
|
10
8
|
# @return [Logger] the logger.
|
|
11
|
-
|
|
9
|
+
class_attribute :logger
|
|
10
|
+
self.logger = Logger.new("/dev/null")
|
|
12
11
|
|
|
13
12
|
##
|
|
14
13
|
# request_version_resolver defines how request_migrations should resolve the
|
|
15
14
|
# current version of a request.
|
|
16
15
|
#
|
|
17
16
|
# @return [Proc] the request version resolver.
|
|
18
|
-
|
|
17
|
+
class_attribute :request_version_resolver
|
|
18
|
+
self.request_version_resolver = -> req { self.current_version }
|
|
19
19
|
|
|
20
20
|
##
|
|
21
21
|
# version_format defines the version format.
|
|
22
22
|
#
|
|
23
23
|
# @return [Symbol] format
|
|
24
|
-
|
|
24
|
+
class_attribute :version_format
|
|
25
|
+
self.version_format = :semver
|
|
25
26
|
|
|
26
27
|
##
|
|
27
28
|
# current_version defines the latest version.
|
|
28
29
|
#
|
|
29
30
|
# @return [String, Integer, Float, nil] the current version.
|
|
30
|
-
|
|
31
|
+
class_attribute :current_version
|
|
32
|
+
self.current_version = nil
|
|
31
33
|
|
|
32
34
|
##
|
|
33
35
|
# versions defines past versions and their migrations.
|
|
34
36
|
#
|
|
35
37
|
# @return [Hash<String, Array<Symbol, String, Class>>] past versions.
|
|
36
|
-
|
|
38
|
+
class_attribute :versions
|
|
39
|
+
self.versions = {}
|
|
37
40
|
end
|
|
38
41
|
end
|
|
@@ -9,10 +9,7 @@ module RequestMigrations
|
|
|
9
9
|
def self.setup!
|
|
10
10
|
@@config = RequestMigrations.config
|
|
11
11
|
|
|
12
|
-
RequestMigrations.
|
|
13
|
-
RequestMigrations.configure do |config|
|
|
14
|
-
@@config.config.each { |(k, v)| config.config[k] = v }
|
|
15
|
-
end
|
|
12
|
+
RequestMigrations.config = @@config.dup
|
|
16
13
|
end
|
|
17
14
|
|
|
18
15
|
##
|
data/lib/request_migrations.rb
CHANGED
|
@@ -46,13 +46,10 @@ module RequestMigrations
|
|
|
46
46
|
##
|
|
47
47
|
# @private
|
|
48
48
|
def self.config=(cfg)
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
raise ArgumentError, 'invalid config provided' unless
|
|
50
|
+
cfg.is_a?(Configuration)
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
# @private
|
|
54
|
-
def self.reset!
|
|
55
|
-
@config = RequestMigrations::Configuration.new
|
|
52
|
+
@config = cfg
|
|
56
53
|
end
|
|
57
54
|
|
|
58
55
|
##
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: request_migrations
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Zeke Gabrielse
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -80,7 +80,7 @@ homepage: https://github.com/keygen-sh/request_migrations
|
|
|
80
80
|
licenses:
|
|
81
81
|
- MIT
|
|
82
82
|
metadata: {}
|
|
83
|
-
post_install_message:
|
|
83
|
+
post_install_message:
|
|
84
84
|
rdoc_options: []
|
|
85
85
|
require_paths:
|
|
86
86
|
- lib
|
|
@@ -88,15 +88,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
88
88
|
requirements:
|
|
89
89
|
- - ">="
|
|
90
90
|
- !ruby/object:Gem::Version
|
|
91
|
-
version: '3.
|
|
91
|
+
version: '3.1'
|
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
97
|
requirements: []
|
|
98
|
-
rubygems_version: 3.
|
|
99
|
-
signing_key:
|
|
98
|
+
rubygems_version: 3.5.11
|
|
99
|
+
signing_key:
|
|
100
100
|
specification_version: 4
|
|
101
101
|
summary: Write request and response migrations for your Ruby on Rails API.
|
|
102
102
|
test_files: []
|