From e8829003761dd6e4891a7de532277879116ad0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Michon?= Date: Wed, 11 Jan 2023 18:44:23 +0100 Subject: [PATCH] feat(databases): add support for upgrade endpoint --- lib/scalingo/regional_database/databases.rb | 13 +++++++ .../regional_database/databases/_meta.json | 2 +- .../regional_database/databases/find-200.json | 8 ++-- .../regional_database/databases/find-400.json | 2 +- .../databases/upgrade-202.json | 39 +++++++++++++++++++ .../databases/upgrade-400.json | 24 ++++++++++++ .../regional_database/databases_spec.rb | 16 ++++++++ 7 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 samples/regional_database/databases/upgrade-202.json create mode 100644 samples/regional_database/databases/upgrade-400.json 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/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