diff --git a/CHANGELOG.md b/CHANGELOG.md index 8da3920..6813ab7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/README.md b/README.md index dff0d55..90895ce 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ bundle ### Run tests ```bash -bundle exec rake test +bundle exec rspec ``` ### Release a new version diff --git a/lib/scalingo/regional_database/databases.rb b/lib/scalingo/regional_database/databases.rb index 5cb87ac..fb56f87 100644 --- a/lib/scalingo/regional_database/databases.rb +++ b/lib/scalingo/regional_database/databases.rb @@ -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 diff --git a/samples/regional_database/backups/_meta.json b/samples/regional_database/backups/_meta.json index 9e28296..2baf9c3 100644 --- a/samples/regional_database/backups/_meta.json +++ b/samples/regional_database/backups/_meta.json @@ -1,4 +1,4 @@ { - "addon_id": "ad-5ed10967884fef000f5e4fff", + "addon_id": "63bfe3b600deff4f0516cc12", "backup_id": "5bb95a904ffb096e9a2831b8" } diff --git a/samples/regional_database/backups/archive-200.json b/samples/regional_database/backups/archive-200.json index c41ca39..eab2862 100644 --- a/samples/regional_database/backups/archive-200.json +++ b/samples/regional_database/backups/archive-200.json @@ -1,5 +1,5 @@ { - "path": "/databases/ad-5ed10967884fef000f5e4fff/backups/5bb95a904ffb096e9a2831b8/archive", + "path": "/databases/63bfe3b600deff4f0516cc12/backups/5bb95a904ffb096e9a2831b8/archive", "method": "get", "request": { "headers": { @@ -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" } } } diff --git a/samples/regional_database/backups/archive-400.json b/samples/regional_database/backups/archive-400.json index 23c819d..64ab78f 100644 --- a/samples/regional_database/backups/archive-400.json +++ b/samples/regional_database/backups/archive-400.json @@ -1,5 +1,5 @@ { - "path": "/databases/ad-5ed10967884fef000f5e4fff/backups/5bb95a904ffb096e9a2831b8/archive", + "path": "/databases/63bfe3b600deff4f0516cc12/backups/5bb95a904ffb096e9a2831b8/archive", "method": "get", "request": { "headers": { diff --git a/samples/regional_database/backups/create-201.json b/samples/regional_database/backups/create-201.json index 96c1d0d..1b55e75 100644 --- a/samples/regional_database/backups/create-201.json +++ b/samples/regional_database/backups/create-201.json @@ -1,5 +1,5 @@ { - "path": "/databases/ad-5ed10967884fef000f5e4fff/backups", + "path": "/databases/63bfe3b600deff4f0516cc12/backups", "method": "post", "request": { "headers": { diff --git a/samples/regional_database/backups/create-400.json b/samples/regional_database/backups/create-400.json index 31143e2..f4f9aba 100644 --- a/samples/regional_database/backups/create-400.json +++ b/samples/regional_database/backups/create-400.json @@ -1,5 +1,5 @@ { - "path": "/databases/ad-5ed10967884fef000f5e4fff/backups", + "path": "/databases/63bfe3b600deff4f0516cc12/backups", "method": "post", "request": { "headers": { diff --git a/samples/regional_database/backups/for-200.json b/samples/regional_database/backups/for-200.json index 6011c37..7b114be 100644 --- a/samples/regional_database/backups/for-200.json +++ b/samples/regional_database/backups/for-200.json @@ -1,5 +1,5 @@ { - "path": "/databases/ad-5ed10967884fef000f5e4fff/backups", + "path": "/databases/63bfe3b600deff4f0516cc12/backups", "method": "get", "request": { "headers": { diff --git a/samples/regional_database/backups/for-400.json b/samples/regional_database/backups/for-400.json index ce7f6a2..31e679e 100644 --- a/samples/regional_database/backups/for-400.json +++ b/samples/regional_database/backups/for-400.json @@ -1,5 +1,5 @@ { - "path": "/databases/ad-5ed10967884fef000f5e4fff/backups", + "path": "/databases/63bfe3b600deff4f0516cc12/backups", "method": "get", "request": { "headers": { diff --git a/samples/regional_database/databases/_meta.json b/samples/regional_database/databases/_meta.json index 9418729..e6339ab 100644 --- a/samples/regional_database/databases/_meta.json +++ b/samples/regional_database/databases/_meta.json @@ -1,3 +1,3 @@ { - "id": "ad-5ed10967884fef000f5e4fff" + "id": "63bfe3b600deff4f0516cc12" } diff --git a/samples/regional_database/databases/find-200.json b/samples/regional_database/databases/find-200.json index 1d89912..5cc228d 100644 --- a/samples/regional_database/databases/find-200.json +++ b/samples/regional_database/databases/find-200.json @@ -1,5 +1,5 @@ { - "path": "/databases/ad-5ed10967884fef000f5e4fff", + "path": "/databases/63bfe3b600deff4f0516cc12", "method": "get", "request": { "headers": { @@ -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", @@ -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 + ] } } } diff --git a/samples/regional_database/databases/find-400.json b/samples/regional_database/databases/find-400.json index 70f1f13..8b92faa 100644 --- a/samples/regional_database/databases/find-400.json +++ b/samples/regional_database/databases/find-400.json @@ -1,5 +1,5 @@ { - "path": "/databases/ad-5ed10967884fef000f5e4fff", + "path": "/databases/63bfe3b600deff4f0516cc12", "method": "get", "request": { "headers": { diff --git a/samples/regional_database/databases/upgrade-202.json b/samples/regional_database/databases/upgrade-202.json new file mode 100644 index 0000000..e84361b --- /dev/null +++ b/samples/regional_database/databases/upgrade-202.json @@ -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": "" + } + } +} diff --git a/samples/regional_database/databases/upgrade-400.json b/samples/regional_database/databases/upgrade-400.json new file mode 100644 index 0000000..d440c20 --- /dev/null +++ b/samples/regional_database/databases/upgrade-400.json @@ -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" + } + } +} diff --git a/spec/scalingo/regional_database/databases_spec.rb b/spec/scalingo/regional_database/databases_spec.rb index 2897cdc..18d035a 100644 --- a/spec/scalingo/regional_database/databases_spec.rb +++ b/spec/scalingo/regional_database/databases_spec.rb @@ -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