Skip to content

Commit

Permalink
Merge pull request #51 from Scalingo/feat/db_api/db_upgrade
Browse files Browse the repository at this point in the history
feat(databases): add support for upgrade endpoint
  • Loading branch information
EtienneM authored Jan 16, 2023
2 parents dd5b157 + 11293b4 commit df89ad4
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

* New: Add support for database API upgrade endpoint ([#51](https://github.com/Scalingo/scalingo-ruby-api/pull/51))

## 3.3.0 - 2023-01-03

* Bugfix: response of Backups#create was not properly unpacked ([#44](https://github.com/Scalingo/scalingo-ruby-api/issues/44))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ bundle
### Run tests

```bash
bundle exec rake test
bundle exec rspec
```

### Release a new version
Expand Down
13 changes: 13 additions & 0 deletions lib/scalingo/regional_database/databases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,18 @@ def find(id, headers = nil, &block)

unpack(:database) { response }
end

def upgrade(id, headers = nil, &block)
data = nil

response = database_connection(id).post(
"databases/#{id}/upgrade",
data,
headers,
&block
)

unpack(:database) { response }
end
end
end
2 changes: 1 addition & 1 deletion samples/regional_database/backups/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"addon_id": "ad-5ed10967884fef000f5e4fff",
"addon_id": "63bfe3b600deff4f0516cc12",
"backup_id": "5bb95a904ffb096e9a2831b8"
}
4 changes: 2 additions & 2 deletions samples/regional_database/backups/archive-200.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"path": "/databases/ad-5ed10967884fef000f5e4fff/backups/5bb95a904ffb096e9a2831b8/archive",
"path": "/databases/63bfe3b600deff4f0516cc12/backups/5bb95a904ffb096e9a2831b8/archive",
"method": "get",
"request": {
"headers": {
Expand All @@ -18,7 +18,7 @@
"Referrer-Policy": "strict-origin-when-cross-origin"
},
"json_body": {
"download_url": "https://regional-database.scalingo.test/databases/ad-5ed10967884fef000f5e4fff/backups/5bb95a904ffb096e9a2831b8/download?token=token1234"
"download_url": "https://regional-database.scalingo.test/databases/63bfe3b600deff4f0516cc12/backups/5bb95a904ffb096e9a2831b8/download?token=token1234"
}
}
}
2 changes: 1 addition & 1 deletion samples/regional_database/backups/archive-400.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"path": "/databases/ad-5ed10967884fef000f5e4fff/backups/5bb95a904ffb096e9a2831b8/archive",
"path": "/databases/63bfe3b600deff4f0516cc12/backups/5bb95a904ffb096e9a2831b8/archive",
"method": "get",
"request": {
"headers": {
Expand Down
2 changes: 1 addition & 1 deletion samples/regional_database/backups/create-201.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"path": "/databases/ad-5ed10967884fef000f5e4fff/backups",
"path": "/databases/63bfe3b600deff4f0516cc12/backups",
"method": "post",
"request": {
"headers": {
Expand Down
2 changes: 1 addition & 1 deletion samples/regional_database/backups/create-400.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"path": "/databases/ad-5ed10967884fef000f5e4fff/backups",
"path": "/databases/63bfe3b600deff4f0516cc12/backups",
"method": "post",
"request": {
"headers": {
Expand Down
2 changes: 1 addition & 1 deletion samples/regional_database/backups/for-200.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"path": "/databases/ad-5ed10967884fef000f5e4fff/backups",
"path": "/databases/63bfe3b600deff4f0516cc12/backups",
"method": "get",
"request": {
"headers": {
Expand Down
2 changes: 1 addition & 1 deletion samples/regional_database/backups/for-400.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"path": "/databases/ad-5ed10967884fef000f5e4fff/backups",
"path": "/databases/63bfe3b600deff4f0516cc12/backups",
"method": "get",
"request": {
"headers": {
Expand Down
2 changes: 1 addition & 1 deletion samples/regional_database/databases/_meta.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"id": "ad-5ed10967884fef000f5e4fff"
"id": "63bfe3b600deff4f0516cc12"
}
8 changes: 5 additions & 3 deletions samples/regional_database/databases/find-200.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"path": "/databases/ad-5ed10967884fef000f5e4fff",
"path": "/databases/63bfe3b600deff4f0516cc12",
"method": "get",
"request": {
"headers": {
Expand All @@ -19,7 +19,7 @@
},
"json_body": {
"database": {
"id": "ad-5ed10967884fef000f5e4fff",
"id": "63bfe3b600deff4f0516cc12",
"resource_id": "my-db-123",
"app_name": "my-app",
"created_at": "2019-02-05T15:38:14.343+01:00",
Expand All @@ -38,7 +38,9 @@
"instances": [],
"readable_version": "3.2.9-1",
"periodic_backups_enabled": true,
"periodic_backups_scheduled_at": [0]
"periodic_backups_scheduled_at": [
0
]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/regional_database/databases/find-400.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"path": "/databases/ad-5ed10967884fef000f5e4fff",
"path": "/databases/63bfe3b600deff4f0516cc12",
"method": "get",
"request": {
"headers": {
Expand Down
39 changes: 39 additions & 0 deletions samples/regional_database/databases/upgrade-202.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"path": "/databases/63bfe3b600deff4f0516cc12/upgrade",
"method": "post",
"request": {
"headers": {
"Authorization": "Bearer the-bearer-token"
}
},
"response": {
"status": 202,
"headers": {
"Date": "Fri, 29 May 2020 13:08:59 GMT",
"Etag": "W/\"a9504bb2f6f87c65ff68074ae787831e\"",
"Content-Type": "application/json; charset=utf-8",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"Cache-Control": "max-age=0, private, must-revalidate",
"Referrer-Policy": "strict-origin-when-cross-origin",
"Location": "https://db-api.osc-st-fr1.st-sc.fr/api/operations/63bef2179307d55a9658cd99"
},
"json_body": {
"message": "Database upgrade to 7.0.5-1 is pending",
"id": "6335961fb07f4c000fe7461c",
"created_at": "2022-09-29T12:57:03.372Z",
"updated_at": "2022-09-29T12:57:03.372Z",
"database_type_id": "5eea3345d6f2bd5a55e2aad0",
"major": 7,
"minor": 0,
"patch": 5,
"build": 1,
"features": [
"tls"
],
"release_number": 330,
"allowed_plugins": null,
"warning_message": ""
}
}
}
24 changes: 24 additions & 0 deletions samples/regional_database/databases/upgrade-400.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"path": "/databases/63bfe3b600deff4f0516cc12/upgrade",
"method": "post",
"request": {
"headers": {
"Authorization": "Bearer the-bearer-token"
}
},
"response": {
"status": 400,
"headers": {
"Date": "Fri, 29 May 2020 13:08:59 GMT",
"Etag": "W/\"a9504bb2f6f87c65ff68074ae787831e\"",
"Content-Type": "application/json; charset=utf-8",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"Cache-Control": "max-age=0, private, must-revalidate",
"Referrer-Policy": "strict-origin-when-cross-origin"
},
"json_body": {
"error": "unauthorized"
}
}
}
16 changes: 16 additions & 0 deletions spec/scalingo/regional_database/databases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,20 @@
it_behaves_like "a client error"
end
end

describe_method "upgrade" do
context "success" do
let(:arguments) { [meta[:id]] }
let(:stub_pattern) { "upgrade-202" }

it_behaves_like "a singular object response", 202
end

context "failure" do
let(:arguments) { [meta[:id]] }
let(:stub_pattern) { "upgrade-400" }

it_behaves_like "a client error"
end
end
end

0 comments on commit df89ad4

Please sign in to comment.