google-cloud-spanner 1.14.0 → 2.0.0
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/AUTHENTICATION.md +1 -1
- data/CHANGELOG.md +51 -0
- data/CONTRIBUTING.md +5 -5
- data/TROUBLESHOOTING.md +0 -6
- data/lib/google-cloud-spanner.rb +23 -13
- data/lib/google/cloud/spanner.rb +8 -9
- data/lib/google/cloud/spanner/admin/database/credentials.rb +2 -2
- data/lib/google/cloud/spanner/admin/instance/credentials.rb +2 -2
- data/lib/google/cloud/spanner/backup.rb +315 -0
- data/lib/google/cloud/spanner/backup/job.rb +274 -0
- data/lib/google/cloud/spanner/backup/job/list.rb +177 -0
- data/lib/google/cloud/spanner/backup/list.rb +169 -0
- data/lib/google/cloud/spanner/backup/restore/job.rb +246 -0
- data/lib/google/cloud/spanner/batch_client.rb +7 -5
- data/lib/google/cloud/spanner/batch_snapshot.rb +49 -16
- data/lib/google/cloud/spanner/batch_update.rb +1 -1
- data/lib/google/cloud/spanner/client.rb +65 -16
- data/lib/google/cloud/spanner/commit.rb +14 -14
- data/lib/google/cloud/spanner/convert.rb +7 -7
- data/lib/google/cloud/spanner/credentials.rb +2 -2
- data/lib/google/cloud/spanner/data.rb +2 -2
- data/lib/google/cloud/spanner/database.rb +275 -15
- data/lib/google/cloud/spanner/database/backup_info.rb +105 -0
- data/lib/google/cloud/spanner/database/job.rb +5 -2
- data/lib/google/cloud/spanner/database/job/list.rb +177 -0
- data/lib/google/cloud/spanner/database/list.rb +1 -1
- data/lib/google/cloud/spanner/database/restore_info.rb +63 -0
- data/lib/google/cloud/spanner/fields.rb +8 -8
- data/lib/google/cloud/spanner/instance.rb +401 -8
- data/lib/google/cloud/spanner/instance/config.rb +1 -1
- data/lib/google/cloud/spanner/instance/config/list.rb +1 -1
- data/lib/google/cloud/spanner/instance/job.rb +2 -2
- data/lib/google/cloud/spanner/instance/list.rb +1 -1
- data/lib/google/cloud/spanner/partition.rb +4 -4
- data/lib/google/cloud/spanner/policy.rb +2 -2
- data/lib/google/cloud/spanner/project.rb +31 -6
- data/lib/google/cloud/spanner/results.rb +4 -2
- data/lib/google/cloud/spanner/service.rb +231 -240
- data/lib/google/cloud/spanner/session.rb +46 -15
- data/lib/google/cloud/spanner/snapshot.rb +28 -5
- data/lib/google/cloud/spanner/transaction.rb +51 -7
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +28 -104
- data/lib/google/cloud/spanner/admin/database.rb +0 -148
- data/lib/google/cloud/spanner/admin/database/v1.rb +0 -146
- data/lib/google/cloud/spanner/admin/database/v1/credentials.rb +0 -46
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +0 -791
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +0 -71
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/iam_policy.rb +0 -64
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/options.rb +0 -33
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +0 -151
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/longrunning/operations.rb +0 -51
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +0 -201
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/type/expr.rb +0 -45
- data/lib/google/cloud/spanner/admin/instance.rb +0 -164
- data/lib/google/cloud/spanner/admin/instance/v1.rb +0 -162
- data/lib/google/cloud/spanner/admin/instance/v1/credentials.rb +0 -46
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/iam_policy.rb +0 -64
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/options.rb +0 -33
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +0 -151
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/longrunning/operations.rb +0 -51
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +0 -341
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/type/expr.rb +0 -45
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +0 -972
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +0 -76
- data/lib/google/cloud/spanner/v1.rb +0 -16
- data/lib/google/cloud/spanner/v1/credentials.rb +0 -42
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +0 -91
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +0 -74
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/spanner/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +0 -150
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +0 -88
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +0 -121
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +0 -190
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +0 -581
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +0 -432
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/type.rb +0 -112
- data/lib/google/cloud/spanner/v1/spanner_client.rb +0 -1509
- data/lib/google/cloud/spanner/v1/spanner_client_config.json +0 -121
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +0 -88
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +0 -99
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +0 -125
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +0 -182
- data/lib/google/spanner/v1/keys_pb.rb +0 -34
- data/lib/google/spanner/v1/mutation_pb.rb +0 -39
- data/lib/google/spanner/v1/query_plan_pb.rb +0 -48
- data/lib/google/spanner/v1/result_set_pb.rb +0 -48
- data/lib/google/spanner/v1/spanner_pb.rb +0 -174
- data/lib/google/spanner/v1/spanner_services_pb.rb +0 -188
- data/lib/google/spanner/v1/transaction_pb.rb +0 -56
- data/lib/google/spanner/v1/type_pb.rb +0 -44
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49b3d879f62998284edf63a941432c67a8caebf708f2ef4df883a3f336dbc758
|
|
4
|
+
data.tar.gz: e6768ee6037df38c765f888f64a4b29cc192b8a30a1bbcf02d01240c3c228621
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c456f4ee2482f6b0c488c749f11b508092b9c2a9befe8a4c44c74d6321c3dc1be43a6abd4cfec56c1ca7d2312feb79998383537ebd20bbe6f3d0be10f6cf576
|
|
7
|
+
data.tar.gz: b31fad2484409183d77bb00e11ba3526fdb9d5ae6817e8a95af51f61e09d7d3635ac7e58c99fbbb4b862b49a3092d59f7e88505aa86cb509ab1d23447ebfb060
|
data/AUTHENTICATION.md
CHANGED
|
@@ -76,7 +76,7 @@ The environment variables that google-cloud-spanner checks for project ID are:
|
|
|
76
76
|
1. `SPANNER_PROJECT`
|
|
77
77
|
2. `GOOGLE_CLOUD_PROJECT`
|
|
78
78
|
|
|
79
|
-
The environment variables that google-cloud-spanner checks for credentials are configured on
|
|
79
|
+
The environment variables that google-cloud-spanner checks for credentials are configured on `Google::Cloud::Spanner::V1::Spanner::Credentials`:
|
|
80
80
|
|
|
81
81
|
1. `SPANNER_CREDENTIALS` - Path to JSON file, or JSON contents
|
|
82
82
|
2. `SPANNER_KEYFILE` - Path to JSON file, or JSON contents
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### 2.0.0 / 2020-07-23
|
|
4
|
+
|
|
5
|
+
This is a major update that removes the "low-level" client interface code, and
|
|
6
|
+
instead adds `google-cloud-spanner-v1`, `google-cloud-spanner-admin-database-v1`,
|
|
7
|
+
and `google-cloud-spanner-admin-instance-v1` as dependencies.
|
|
8
|
+
The new dependencies are rewritten low-level clients, produced by a next-
|
|
9
|
+
generation client code generator, with improved performance and stability.
|
|
10
|
+
|
|
11
|
+
This change should have no effect on the high-level interface that most users
|
|
12
|
+
will use. The one exception is that the (mostly undocumented) `client_config`
|
|
13
|
+
argument, for adjusting low-level parameters such as RPC retry settings on
|
|
14
|
+
client objects, has been removed. If you need to adjust these parameters, use
|
|
15
|
+
the configuration interface in low-level clients.
|
|
16
|
+
|
|
17
|
+
Substantial changes have been made in the low-level interfaces, however. If you
|
|
18
|
+
are using the low-level classes under the old `Google::Spanner::V1` module,
|
|
19
|
+
please review the docs for the new `google-cloud-spanner-v1` gem. In particular:
|
|
20
|
+
|
|
21
|
+
* Some classes have been renamed, notably the client class itself.
|
|
22
|
+
* The client constructor takes a configuration block instead of configuration
|
|
23
|
+
keyword arguments.
|
|
24
|
+
* All RPC method arguments are now keyword arguments.
|
|
25
|
+
|
|
26
|
+
### 1.16.2 / 2020-05-28
|
|
27
|
+
|
|
28
|
+
#### Documentation
|
|
29
|
+
|
|
30
|
+
* Fix a few broken links
|
|
31
|
+
|
|
32
|
+
### 1.16.1 / 2020-05-21
|
|
33
|
+
|
|
34
|
+
#### Bug Fixes
|
|
35
|
+
|
|
36
|
+
* Increased default timeouts to match clients in other languages
|
|
37
|
+
* Run system tests against the emulator, skipping those not supported by the emulator
|
|
38
|
+
* Do not require a key file when running against the emulator
|
|
39
|
+
|
|
40
|
+
### 1.16.0 / 2020-03-20
|
|
41
|
+
|
|
42
|
+
#### Features
|
|
43
|
+
|
|
44
|
+
* Added support for backing up and restoring databases ([#5053](https://www.github.com/googleapis/google-cloud-ruby/issues/5053))
|
|
45
|
+
|
|
46
|
+
### 1.15.0 / 2020-03-15
|
|
47
|
+
|
|
48
|
+
#### Features
|
|
49
|
+
|
|
50
|
+
* Added support for query options ([#4907](https://www.github.com/googleapis/google-cloud-ruby/issues/4907))
|
|
51
|
+
* Added support for specifying the query optimizer version.
|
|
52
|
+
* Support separate project setting for quota/billing
|
|
53
|
+
|
|
3
54
|
### 1.14.0 / 2020-02-18
|
|
4
55
|
|
|
5
56
|
#### Features
|
data/CONTRIBUTING.md
CHANGED
|
@@ -53,7 +53,7 @@ there is a small amount of setup:
|
|
|
53
53
|
In order to run code interactively, you can automatically load
|
|
54
54
|
google-cloud-spanner and its dependencies in IRB. This requires that your
|
|
55
55
|
developer environment has already been configured by following the steps
|
|
56
|
-
described in the
|
|
56
|
+
described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
|
|
57
57
|
can be created with:
|
|
58
58
|
|
|
59
59
|
```sh
|
|
@@ -119,7 +119,7 @@ If you alter an example's title, you may encounter breaking tests.
|
|
|
119
119
|
### Spanner Acceptance Tests
|
|
120
120
|
|
|
121
121
|
The Spanner acceptance tests interact with the live service API. Follow the
|
|
122
|
-
instructions in the
|
|
122
|
+
instructions in the {file:AUTHENTICATION.md Authentication Guide} for enabling
|
|
123
123
|
the Spanner API. Occasionally, some API features may not yet be generally
|
|
124
124
|
available, making it difficult for some contributors to successfully run the
|
|
125
125
|
entire acceptance test suite. However, please ensure that you do successfully
|
|
@@ -127,7 +127,7 @@ run acceptance tests for any code areas covered by your pull request.
|
|
|
127
127
|
|
|
128
128
|
To run the acceptance tests, first create and configure a project in the Google
|
|
129
129
|
Developers Console, as described in the
|
|
130
|
-
|
|
130
|
+
{file:AUTHENTICATION.md Authentication Guide}. Be sure to download the JSON KEY
|
|
131
131
|
file. Make note of the PROJECT_ID and the KEYFILE location on your system.
|
|
132
132
|
|
|
133
133
|
Before you can run the Spanner acceptance tests, you must first create indexes
|
|
@@ -184,5 +184,5 @@ $ bundle exec rake rubocop
|
|
|
184
184
|
## Code of Conduct
|
|
185
185
|
|
|
186
186
|
Please note that this project is released with a Contributor Code of Conduct. By
|
|
187
|
-
participating in this project you agree to abide by its terms. See
|
|
188
|
-
|
|
187
|
+
participating in this project you agree to abide by its terms. See the
|
|
188
|
+
{file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
|
data/TROUBLESHOOTING.md
CHANGED
|
@@ -24,14 +24,8 @@ improved, *please* create a new issue on GitHub so we can talk about it.
|
|
|
24
24
|
|
|
25
25
|
- [New issue][gh-ruby]
|
|
26
26
|
|
|
27
|
-
Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
|
|
28
|
-
can use the "ruby" channel for general Ruby questions, or use the
|
|
29
|
-
"google-cloud-ruby" channel if you have questions about this gem in particular.
|
|
30
|
-
|
|
31
27
|
[so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+spanner
|
|
32
28
|
|
|
33
29
|
[gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+spanner%22
|
|
34
30
|
|
|
35
31
|
[gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
|
|
36
|
-
|
|
37
|
-
[slack-ruby]: https://gcp-slack.appspot.com/
|
data/lib/google-cloud-spanner.rb
CHANGED
|
@@ -43,8 +43,6 @@ module Google
|
|
|
43
43
|
# * `https://www.googleapis.com/auth/spanner`
|
|
44
44
|
# * `https://www.googleapis.com/auth/spanner.data`
|
|
45
45
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
|
46
|
-
# @param [Hash] client_config A hash of values to override the default
|
|
47
|
-
# behavior of the API client. Optional.
|
|
48
46
|
# @param [String] lib_name Library name. This will be added as a prefix
|
|
49
47
|
# to the API call tracking header `x-goog-api-client` with provided
|
|
50
48
|
# lib version for telemetry. Optional. For example prefix looks like
|
|
@@ -75,11 +73,9 @@ module Google
|
|
|
75
73
|
# platform_scope = "https://www.googleapis.com/auth/cloud-platform"
|
|
76
74
|
# spanner = gcloud.spanner scope: platform_scope
|
|
77
75
|
#
|
|
78
|
-
def spanner scope: nil, timeout: nil,
|
|
79
|
-
lib_version: nil
|
|
76
|
+
def spanner scope: nil, timeout: nil, lib_name: nil, lib_version: nil
|
|
80
77
|
Google::Cloud.spanner @project, @keyfile, scope: scope,
|
|
81
78
|
timeout: (timeout || @timeout),
|
|
82
|
-
client_config: client_config,
|
|
83
79
|
lib_name: lib_name,
|
|
84
80
|
lib_version: lib_version
|
|
85
81
|
end
|
|
@@ -107,8 +103,6 @@ module Google
|
|
|
107
103
|
# * `https://www.googleapis.com/auth/spanner`
|
|
108
104
|
# * `https://www.googleapis.com/auth/spanner.data`
|
|
109
105
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
|
110
|
-
# @param [Hash] client_config A hash of values to override the default
|
|
111
|
-
# behavior of the API client. Optional.
|
|
112
106
|
# @param [String] lib_name Library name. This will be added as a prefix
|
|
113
107
|
# to the API call tracking header `x-goog-api-client` with provided
|
|
114
108
|
# lib version for telemetry. Optional. For example prefix looks like
|
|
@@ -132,18 +126,18 @@ module Google
|
|
|
132
126
|
# spanner = Google::Cloud.spanner
|
|
133
127
|
#
|
|
134
128
|
def self.spanner project_id = nil, credentials = nil, scope: nil,
|
|
135
|
-
timeout: nil,
|
|
136
|
-
lib_version: nil
|
|
129
|
+
timeout: nil, lib_name: nil, lib_version: nil
|
|
137
130
|
require "google/cloud/spanner"
|
|
138
131
|
Google::Cloud::Spanner.new project_id: project_id,
|
|
139
132
|
credentials: credentials,
|
|
140
133
|
scope: scope, timeout: timeout,
|
|
141
|
-
client_config: client_config,
|
|
142
134
|
lib_name: lib_name, lib_version: lib_version
|
|
143
135
|
end
|
|
144
136
|
end
|
|
145
137
|
end
|
|
146
138
|
|
|
139
|
+
# rubocop:disable Metrics/BlockLength
|
|
140
|
+
|
|
147
141
|
# Set the default spanner configuration
|
|
148
142
|
Google::Cloud.configure.add_config! :spanner do |config|
|
|
149
143
|
default_project = Google::Cloud::Config.deferred do
|
|
@@ -159,17 +153,33 @@ Google::Cloud.configure.add_config! :spanner do |config|
|
|
|
159
153
|
ENV["SPANNER_EMULATOR_HOST"]
|
|
160
154
|
end
|
|
161
155
|
|
|
156
|
+
default_query_options = Google::Cloud::Config.deferred do
|
|
157
|
+
query_options = {}
|
|
158
|
+
optimizer_version = ENV["SPANNER_OPTIMIZER_VERSION"]
|
|
159
|
+
query_options[:optimizer_version] = optimizer_version if optimizer_version
|
|
160
|
+
query_options = nil if query_options.empty?
|
|
161
|
+
query_options
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
default_scopes = [
|
|
165
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
|
166
|
+
"https://www.googleapis.com/auth/spanner.admin",
|
|
167
|
+
"https://www.googleapis.com/auth/spanner.data"
|
|
168
|
+
]
|
|
169
|
+
|
|
162
170
|
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
|
163
171
|
config.add_alias! :project, :project_id
|
|
164
172
|
config.add_field! :credentials, default_creds,
|
|
165
173
|
match: [String, Hash, Google::Auth::Credentials],
|
|
166
174
|
allow_nil: true
|
|
167
175
|
config.add_alias! :keyfile, :credentials
|
|
168
|
-
config.add_field! :scope,
|
|
176
|
+
config.add_field! :scope, default_scopes, match: [String, Array]
|
|
169
177
|
config.add_field! :timeout, nil, match: Integer
|
|
170
|
-
config.add_field! :
|
|
171
|
-
config.add_field! :endpoint, nil, match: String
|
|
178
|
+
config.add_field! :endpoint, "spanner.googleapis.com", match: String
|
|
172
179
|
config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
|
|
173
180
|
config.add_field! :lib_name, nil, match: String, allow_nil: true
|
|
174
181
|
config.add_field! :lib_version, nil, match: String, allow_nil: true
|
|
182
|
+
config.add_field! :query_options, default_query_options, match: Hash, allow_nil: true
|
|
175
183
|
end
|
|
184
|
+
|
|
185
|
+
# rubocop:enable Metrics/BlockLength
|
data/lib/google/cloud/spanner.rb
CHANGED
|
@@ -59,8 +59,6 @@ module Google
|
|
|
59
59
|
# * `https://www.googleapis.com/auth/spanner`
|
|
60
60
|
# * `https://www.googleapis.com/auth/spanner.data`
|
|
61
61
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
|
62
|
-
# @param [Hash] client_config A hash of values to override the default
|
|
63
|
-
# behavior of the API client. Optional.
|
|
64
62
|
# @param [String] endpoint Override of the endpoint host name. Optional.
|
|
65
63
|
# If the param is nil, uses the default endpoint.
|
|
66
64
|
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
|
@@ -91,12 +89,11 @@ module Google
|
|
|
91
89
|
# spanner = Google::Cloud::Spanner.new
|
|
92
90
|
#
|
|
93
91
|
def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
|
|
94
|
-
|
|
92
|
+
endpoint: nil, project: nil, keyfile: nil,
|
|
95
93
|
emulator_host: nil, lib_name: nil, lib_version: nil
|
|
96
94
|
project_id ||= (project || default_project_id)
|
|
97
95
|
scope ||= configure.scope
|
|
98
96
|
timeout ||= configure.timeout
|
|
99
|
-
client_config ||= configure.client_config
|
|
100
97
|
endpoint ||= configure.endpoint
|
|
101
98
|
credentials ||= (keyfile || default_credentials(scope: scope))
|
|
102
99
|
emulator_host ||= configure.emulator_host
|
|
@@ -122,9 +119,10 @@ module Google
|
|
|
122
119
|
Spanner::Project.new(
|
|
123
120
|
Spanner::Service.new(
|
|
124
121
|
project_id, credentials,
|
|
125
|
-
host: endpoint, timeout: timeout,
|
|
126
|
-
|
|
127
|
-
)
|
|
122
|
+
host: endpoint, timeout: timeout, lib_name: lib_name,
|
|
123
|
+
lib_version: lib_version
|
|
124
|
+
),
|
|
125
|
+
query_options: configure.query_options
|
|
128
126
|
)
|
|
129
127
|
end
|
|
130
128
|
|
|
@@ -144,8 +142,6 @@ module Google
|
|
|
144
142
|
# * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
|
|
145
143
|
# the set of resources and operations that the connection can access.
|
|
146
144
|
# * `timeout` - (Integer) Default timeout to use in requests.
|
|
147
|
-
# * `client_config` - (Hash) A hash of values to override the default
|
|
148
|
-
# behavior of the API client.
|
|
149
145
|
# * `endpoint` - (String) Override of the endpoint host name, or `nil`
|
|
150
146
|
# to use the default endpoint.
|
|
151
147
|
# * `emulator_host` - (String) Host name of the emulator. Defaults to
|
|
@@ -183,4 +179,7 @@ module Google
|
|
|
183
179
|
end
|
|
184
180
|
end
|
|
185
181
|
end
|
|
182
|
+
|
|
183
|
+
# @private
|
|
184
|
+
Spanner = Cloud::Spanner unless const_defined? :Spanner
|
|
186
185
|
end
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
require "
|
|
16
|
+
require "google/cloud/spanner/admin/database/v1/database_admin/credentials"
|
|
17
17
|
|
|
18
18
|
module Google
|
|
19
19
|
module Cloud
|
|
@@ -23,7 +23,7 @@ module Google
|
|
|
23
23
|
##
|
|
24
24
|
# @deprecated Use version-specific credentials classes
|
|
25
25
|
#
|
|
26
|
-
Credentials =
|
|
26
|
+
Credentials = V1::DatabaseAdmin::Credentials
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
require "
|
|
16
|
+
require "google/cloud/spanner/admin/instance/v1/instance_admin/credentials"
|
|
17
17
|
|
|
18
18
|
module Google
|
|
19
19
|
module Cloud
|
|
@@ -23,7 +23,7 @@ module Google
|
|
|
23
23
|
##
|
|
24
24
|
# @deprecated Use version-specific credentials classes
|
|
25
25
|
#
|
|
26
|
-
Credentials =
|
|
26
|
+
Credentials = V1::InstanceAdmin::Credentials
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# Copyright 2020 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
require "google/cloud/spanner/backup/job"
|
|
17
|
+
require "google/cloud/spanner/backup/list"
|
|
18
|
+
require "google/cloud/spanner/backup/restore/job"
|
|
19
|
+
|
|
20
|
+
module Google
|
|
21
|
+
module Cloud
|
|
22
|
+
module Spanner
|
|
23
|
+
##
|
|
24
|
+
# # Backup
|
|
25
|
+
#
|
|
26
|
+
# A backup is a representation of Cloud Spanner database backup.
|
|
27
|
+
#
|
|
28
|
+
# See {Google::Cloud::Spanner::Instance#backups},
|
|
29
|
+
# {Google::Cloud::Spanner::Instance#backup}, and
|
|
30
|
+
# {Google::Cloud::Spanner::Database#create_backup}.
|
|
31
|
+
#
|
|
32
|
+
# @example
|
|
33
|
+
# require "google/cloud"
|
|
34
|
+
#
|
|
35
|
+
# spanner = Google::Cloud::Spanner.new
|
|
36
|
+
# database = spanner.database "my-instance", "my-database"
|
|
37
|
+
#
|
|
38
|
+
# expire_time = Time.now + 36000
|
|
39
|
+
# job = database.create_backup "my-backup", expire_time
|
|
40
|
+
#
|
|
41
|
+
# job.done? #=> false
|
|
42
|
+
# job.reload! # API call
|
|
43
|
+
# job.done? #=> true
|
|
44
|
+
#
|
|
45
|
+
# if job.error?
|
|
46
|
+
# status = job.error
|
|
47
|
+
# else
|
|
48
|
+
# backup = job.backup
|
|
49
|
+
# end
|
|
50
|
+
#
|
|
51
|
+
class Backup
|
|
52
|
+
##
|
|
53
|
+
# @private The gRPC Service object.
|
|
54
|
+
attr_accessor :service
|
|
55
|
+
|
|
56
|
+
##
|
|
57
|
+
# @private Creates a new Backup instance.
|
|
58
|
+
def initialize grpc, service
|
|
59
|
+
@grpc = grpc
|
|
60
|
+
@service = service
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
##
|
|
64
|
+
# The unique identifier for the project.
|
|
65
|
+
# @return [String]
|
|
66
|
+
def project_id
|
|
67
|
+
@grpc.name.split("/")[1]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
##
|
|
71
|
+
# The unique identifier for the instance.
|
|
72
|
+
# @return [String]
|
|
73
|
+
def instance_id
|
|
74
|
+
@grpc.name.split("/")[3]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
##
|
|
78
|
+
# The unique identifier for the backup.
|
|
79
|
+
# @return [String]
|
|
80
|
+
def backup_id
|
|
81
|
+
@grpc.name.split("/")[5]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
##
|
|
85
|
+
# Name of the database from which this backup was created.
|
|
86
|
+
# @return [String]
|
|
87
|
+
def database_id
|
|
88
|
+
@grpc.database.split("/")[5]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
##
|
|
92
|
+
# The full path for the backup. Values are of the form
|
|
93
|
+
# `projects/<project>/instances/<instance>/backups/<backup_id>`.
|
|
94
|
+
# @return [String]
|
|
95
|
+
def path
|
|
96
|
+
@grpc.name
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
##
|
|
100
|
+
# The current backup state. Possible values are `:CREATING` and
|
|
101
|
+
# `:READY`.
|
|
102
|
+
# @return [Symbol]
|
|
103
|
+
def state
|
|
104
|
+
@grpc.state
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
##
|
|
108
|
+
# The backup is still being created. A backup is not yet available
|
|
109
|
+
# for the database restore operation.
|
|
110
|
+
# @return [Boolean]
|
|
111
|
+
def creating?
|
|
112
|
+
state == :CREATING
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
##
|
|
116
|
+
# The backup is created and can be used to restore a database.
|
|
117
|
+
# @return [Boolean]
|
|
118
|
+
def ready?
|
|
119
|
+
state == :READY
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
##
|
|
123
|
+
# The expiration time of the backup, with microseconds granularity.
|
|
124
|
+
# @return [Time]
|
|
125
|
+
def expire_time
|
|
126
|
+
Convert.timestamp_to_time @grpc.expire_time
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
##
|
|
130
|
+
# Update backup expiration time.
|
|
131
|
+
#
|
|
132
|
+
# Set expiration time of the backup, with microseconds granularity
|
|
133
|
+
# that must be at least 6 hours and at most 366 days from the time the
|
|
134
|
+
# request is received. Once the `expire_time` has passed, Cloud Spanner
|
|
135
|
+
# will delete the backup and free the resources used by the backup.
|
|
136
|
+
#
|
|
137
|
+
# @param [Time] time Backup expiration time.
|
|
138
|
+
# @raise [Google::Cloud::Error] if expire time is in past or update
|
|
139
|
+
# call is aborted.
|
|
140
|
+
#
|
|
141
|
+
# @example
|
|
142
|
+
# require "google/cloud/spanner"
|
|
143
|
+
#
|
|
144
|
+
# spanner = Google::Cloud::Spanner.new
|
|
145
|
+
#
|
|
146
|
+
# instance = spanner.instance "my-instance"
|
|
147
|
+
# backup = instance.backup "my-backup"
|
|
148
|
+
# backup.expire_time = Time.now + 36000
|
|
149
|
+
# puts backup.expire_time
|
|
150
|
+
#
|
|
151
|
+
def expire_time= time
|
|
152
|
+
ensure_service!
|
|
153
|
+
|
|
154
|
+
expire_time_was = @grpc.expire_time
|
|
155
|
+
@grpc.expire_time = Convert.time_to_timestamp time
|
|
156
|
+
update_mask = Google::Protobuf::FieldMask.new paths: ["expire_time"]
|
|
157
|
+
@grpc = service.update_backup @grpc, update_mask
|
|
158
|
+
rescue Google::Cloud::Error => error
|
|
159
|
+
@grpc.expire_time = expire_time_was
|
|
160
|
+
raise error
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
##
|
|
164
|
+
# Create time is approximately the time when the backup request was
|
|
165
|
+
# received.
|
|
166
|
+
# @return [Time]
|
|
167
|
+
def create_time
|
|
168
|
+
Convert.timestamp_to_time @grpc.create_time
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
##
|
|
172
|
+
# Size of the backup in bytes.
|
|
173
|
+
# @return [Integer]
|
|
174
|
+
def size_in_bytes
|
|
175
|
+
@grpc.size_bytes
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
##
|
|
179
|
+
# The instances of the restored databases that reference the backup.
|
|
180
|
+
# Referencing databases may exist in different instances.
|
|
181
|
+
# The existence of any referencing database prevents the backup from
|
|
182
|
+
# being deleted. When a restored database from the backup enters the
|
|
183
|
+
# `READY` state, the reference to the backup is removed.
|
|
184
|
+
#
|
|
185
|
+
# @return [Array<Google::Cloud::Spanner::Database>] Returns list of
|
|
186
|
+
# referencing database instances.
|
|
187
|
+
#
|
|
188
|
+
# @example
|
|
189
|
+
# spanner = Google::Cloud::Spanner.new
|
|
190
|
+
#
|
|
191
|
+
# instance = spanner.instance "my-instance"
|
|
192
|
+
# backup = instance.backup "my-backup"
|
|
193
|
+
#
|
|
194
|
+
# backup.referencing_databases.each do |database|
|
|
195
|
+
# puts database.database_id
|
|
196
|
+
# end
|
|
197
|
+
#
|
|
198
|
+
def referencing_databases
|
|
199
|
+
ensure_service!
|
|
200
|
+
|
|
201
|
+
@grpc.referencing_databases.map do |referencing_database|
|
|
202
|
+
segments = referencing_database.split "/"
|
|
203
|
+
database_grpc = service.get_database segments[3], segments[5]
|
|
204
|
+
Database.from_grpc database_grpc, service
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
##
|
|
209
|
+
# Permanently deletes the backup.
|
|
210
|
+
#
|
|
211
|
+
# @return [Boolean] Returns `true` if the backup was deleted.
|
|
212
|
+
#
|
|
213
|
+
# @example
|
|
214
|
+
# require "google/cloud/spanner"
|
|
215
|
+
#
|
|
216
|
+
# spanner = Google::Cloud::Spanner.new
|
|
217
|
+
#
|
|
218
|
+
# instance = spanner.instance "my-instance"
|
|
219
|
+
# backup = instance.backup "my-backup"
|
|
220
|
+
# backup.delete # true
|
|
221
|
+
#
|
|
222
|
+
def delete
|
|
223
|
+
ensure_service!
|
|
224
|
+
service.delete_backup instance_id, backup_id
|
|
225
|
+
true
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
##
|
|
229
|
+
# Restores deleted database from the backup.
|
|
230
|
+
#
|
|
231
|
+
# @param [String] database_id The unique identifier for the database,
|
|
232
|
+
# which cannot be changed after the database is created. Values are of
|
|
233
|
+
# the form `[a-z][a-z0-9_\-]*[a-z0-9]` and must be between 2 and 30
|
|
234
|
+
# characters in length. Required.
|
|
235
|
+
# @param [String] instance_id The name of the instance in which to
|
|
236
|
+
# create the restored database. This instance must be in the same
|
|
237
|
+
# project and have the same instance configuration as the instance
|
|
238
|
+
# containing the source backup. Optional. Default value is same as a
|
|
239
|
+
# backup instance.
|
|
240
|
+
# @return [Database] Restored database.
|
|
241
|
+
#
|
|
242
|
+
# @example
|
|
243
|
+
# require "google/cloud/spanner"
|
|
244
|
+
#
|
|
245
|
+
# spanner = Google::Cloud::Spanner.new
|
|
246
|
+
#
|
|
247
|
+
# instance = spanner.instance "my-instance"
|
|
248
|
+
# backup = instance.backup "my-backup"
|
|
249
|
+
# job = backup.restore "my-restored-database"
|
|
250
|
+
#
|
|
251
|
+
# job.done? #=> false
|
|
252
|
+
# job.reload! # API call
|
|
253
|
+
# job.done? #=> true
|
|
254
|
+
#
|
|
255
|
+
# if job.error?
|
|
256
|
+
# status = job.error
|
|
257
|
+
# else
|
|
258
|
+
# database = job.database
|
|
259
|
+
# end
|
|
260
|
+
#
|
|
261
|
+
# @example Restore database in provided instance id
|
|
262
|
+
# require "google/cloud/spanner"
|
|
263
|
+
#
|
|
264
|
+
# spanner = Google::Cloud::Spanner.new
|
|
265
|
+
#
|
|
266
|
+
# instance = spanner.instance "my-instance"
|
|
267
|
+
# backup = instance.backup "my-backup"
|
|
268
|
+
# job = backup.restore(
|
|
269
|
+
# "my-restored-database",
|
|
270
|
+
# instance_id: "other-instance"
|
|
271
|
+
# )
|
|
272
|
+
#
|
|
273
|
+
# job.done? #=> false
|
|
274
|
+
# job.reload! # API call
|
|
275
|
+
# job.done? #=> true
|
|
276
|
+
#
|
|
277
|
+
# if job.error?
|
|
278
|
+
# status = job.error
|
|
279
|
+
# else
|
|
280
|
+
# database = job.database
|
|
281
|
+
# end
|
|
282
|
+
#
|
|
283
|
+
def restore database_id, instance_id: nil
|
|
284
|
+
ensure_service!
|
|
285
|
+
|
|
286
|
+
instance_id ||= self.instance_id
|
|
287
|
+
|
|
288
|
+
grpc = service.restore_database \
|
|
289
|
+
self.instance_id,
|
|
290
|
+
backup_id,
|
|
291
|
+
instance_id,
|
|
292
|
+
database_id
|
|
293
|
+
Restore::Job.from_grpc grpc, service
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
##
|
|
297
|
+
# @private
|
|
298
|
+
# Creates a new Backup instance from a
|
|
299
|
+
# `Google::Cloud::Spanner::Admin::Database::V1::Backup`.
|
|
300
|
+
def self.from_grpc grpc, service
|
|
301
|
+
new grpc, service
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
protected
|
|
305
|
+
|
|
306
|
+
##
|
|
307
|
+
# @private Raise an error unless an active connection to the service is
|
|
308
|
+
# available.
|
|
309
|
+
def ensure_service!
|
|
310
|
+
raise "Must have active connection to service" unless service
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
end
|