Skip to content

Commit 3d37c58

Browse files
Google APIscopybara-github
authored andcommitted
feat: add Firestore CloneDatabase support
PiperOrigin-RevId: 789807783
1 parent 5409b51 commit 3d37c58

File tree

6 files changed

+174
-0
lines changed

6 files changed

+174
-0
lines changed

google/firestore/admin/v1/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ proto_library(
3232
"location.proto",
3333
"operation.proto",
3434
"schedule.proto",
35+
"snapshot.proto",
3536
"user_creds.proto",
3637
],
3738
deps = [
3839
"//google/api:annotations_proto",
3940
"//google/api:client_proto",
4041
"//google/api:field_behavior_proto",
4142
"//google/api:resource_proto",
43+
"//google/api:routing_proto",
4244
"//google/longrunning:operations_proto",
4345
"//google/type:dayofweek_proto",
4446
"@com_google_protobuf//:duration_proto",

google/firestore/admin/v1/firestore_admin.proto

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import "google/api/annotations.proto";
2020
import "google/api/client.proto";
2121
import "google/api/field_behavior.proto";
2222
import "google/api/resource.proto";
23+
import "google/api/routing.proto";
2324
import "google/firestore/admin/v1/backup.proto";
2425
import "google/firestore/admin/v1/database.proto";
2526
import "google/firestore/admin/v1/field.proto";
2627
import "google/firestore/admin/v1/index.proto";
2728
import "google/firestore/admin/v1/operation.proto";
2829
import "google/firestore/admin/v1/schedule.proto";
30+
import "google/firestore/admin/v1/snapshot.proto";
2931
import "google/firestore/admin/v1/user_creds.proto";
3032
import "google/longrunning/operations.proto";
3133
import "google/protobuf/empty.proto";
@@ -458,6 +460,45 @@ service FirestoreAdmin {
458460
};
459461
option (google.api.method_signature) = "name";
460462
}
463+
464+
// Creates a new database by cloning an existing one.
465+
//
466+
// The new database must be in the same cloud region or multi-region location
467+
// as the existing database. This behaves similar to
468+
// [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.FirestoreAdmin.CreateDatabase]
469+
// except instead of creating a new empty database, a new database is created
470+
// with the database type, index configuration, and documents from an existing
471+
// database.
472+
//
473+
// The [long-running operation][google.longrunning.Operation] can be used to
474+
// track the progress of the clone, with the Operation's
475+
// [metadata][google.longrunning.Operation.metadata] field type being the
476+
// [CloneDatabaseMetadata][google.firestore.admin.v1.CloneDatabaseMetadata].
477+
// The [response][google.longrunning.Operation.response] type is the
478+
// [Database][google.firestore.admin.v1.Database] if the clone was
479+
// successful. The new database is not readable or writeable until the LRO has
480+
// completed.
481+
rpc CloneDatabase(CloneDatabaseRequest)
482+
returns (google.longrunning.Operation) {
483+
option (google.api.http) = {
484+
post: "/v1/{parent=projects/*}/databases:clone"
485+
body: "*"
486+
};
487+
option (google.api.routing) = {
488+
routing_parameters {
489+
field: "pitr_snapshot.database"
490+
path_template: "projects/{project_id=*}/**"
491+
}
492+
routing_parameters {
493+
field: "pitr_snapshot.database"
494+
path_template: "projects/*/databases/{database_id=*}/**"
495+
}
496+
};
497+
option (google.longrunning.operation_info) = {
498+
response_type: "Database"
499+
metadata_type: "CloneDatabaseMetadata"
500+
};
501+
}
461502
}
462503

463504
// A request to list the Firestore Databases in all locations for a project.
@@ -1137,3 +1178,51 @@ message RestoreDatabaseRequest {
11371178
(google.api.field_behavior) = OPTIONAL
11381179
];
11391180
}
1181+
1182+
// The request message for
1183+
// [FirestoreAdmin.CloneDatabase][google.firestore.admin.v1.FirestoreAdmin.CloneDatabase].
1184+
message CloneDatabaseRequest {
1185+
// Required. The project to clone the database in. Format is
1186+
// `projects/{project_id}`.
1187+
string parent = 1 [
1188+
(google.api.field_behavior) = REQUIRED,
1189+
(google.api.resource_reference) = {
1190+
child_type: "firestore.googleapis.com/Database"
1191+
}
1192+
];
1193+
1194+
// Required. The ID to use for the database, which will become the final
1195+
// component of the database's resource name. This database ID must not be
1196+
// associated with an existing database.
1197+
//
1198+
// This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
1199+
// with first character a letter and the last a letter or a number. Must not
1200+
// be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
1201+
//
1202+
// "(default)" database ID is also valid.
1203+
string database_id = 2 [(google.api.field_behavior) = REQUIRED];
1204+
1205+
// Required. Specification of the PITR data to clone from. The source database
1206+
// must exist.
1207+
//
1208+
// The cloned database will be created in the same location as the source
1209+
// database.
1210+
PitrSnapshot pitr_snapshot = 6 [(google.api.field_behavior) = REQUIRED];
1211+
1212+
// Optional. Encryption configuration for the cloned database.
1213+
//
1214+
// If this field is not specified, the cloned database will use
1215+
// the same encryption configuration as the source database, namely
1216+
// [use_source_encryption][google.firestore.admin.v1.Database.EncryptionConfig.use_source_encryption].
1217+
Database.EncryptionConfig encryption_config = 4
1218+
[(google.api.field_behavior) = OPTIONAL];
1219+
1220+
// Optional. Immutable. Tags to be bound to the cloned database.
1221+
//
1222+
// The tags should be provided in the format of
1223+
// `tagKeys/{tag_key_id} -> tagValues/{tag_value_id}`.
1224+
map<string, string> tags = 5 [
1225+
(google.api.field_behavior) = IMMUTABLE,
1226+
(google.api.field_behavior) = OPTIONAL
1227+
];
1228+
}

google/firestore/admin/v1/firestore_admin_grpc_service_config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
{
7171
"service": "google.firestore.admin.v1.FirestoreAdmin",
7272
"method": "RestoreDatabase"
73+
},
74+
{
75+
"service": "google.firestore.admin.v1.FirestoreAdmin",
76+
"method": "CloneDatabase"
7377
}
7478
],
7579
"timeout": "120s"

google/firestore/admin/v1/firestore_v1.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ apis:
1010

1111
types:
1212
- name: google.firestore.admin.v1.BulkDeleteDocumentsMetadata
13+
- name: google.firestore.admin.v1.CloneDatabaseMetadata
1314
- name: google.firestore.admin.v1.CreateDatabaseMetadata
1415
- name: google.firestore.admin.v1.DeleteDatabaseMetadata
1516
- name: google.firestore.admin.v1.ExportDocumentsMetadata

google/firestore/admin/v1/operation.proto

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package google.firestore.admin.v1;
1818

1919
import "google/api/resource.proto";
2020
import "google/firestore/admin/v1/index.proto";
21+
import "google/firestore/admin/v1/snapshot.proto";
2122
import "google/protobuf/timestamp.proto";
2223

2324
option csharp_namespace = "Google.Cloud.Firestore.Admin.V1";
@@ -259,6 +260,30 @@ message RestoreDatabaseMetadata {
259260
Progress progress_percentage = 8;
260261
}
261262

263+
// Metadata for the [long-running operation][google.longrunning.Operation] from
264+
// the [CloneDatabase][google.firestore.admin.v1.CloneDatabase] request.
265+
message CloneDatabaseMetadata {
266+
// The time the clone was started.
267+
google.protobuf.Timestamp start_time = 1;
268+
269+
// The time the clone finished, unset for ongoing clones.
270+
google.protobuf.Timestamp end_time = 2;
271+
272+
// The operation state of the clone.
273+
OperationState operation_state = 3;
274+
275+
// The name of the database being cloned to.
276+
string database = 4 [(google.api.resource_reference) = {
277+
type: "firestore.googleapis.com/Database"
278+
}];
279+
280+
// The snapshot from which this database was cloned.
281+
PitrSnapshot pitr_snapshot = 7;
282+
283+
// How far along the clone is as an estimated percentage of remaining time.
284+
Progress progress_percentage = 6;
285+
}
286+
262287
// Describes the progress of the operation.
263288
// Unit of work is generic and must be interpreted based on where
264289
// [Progress][google.firestore.admin.v1.Progress] is used.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2025 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+
// http://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+
syntax = "proto3";
16+
17+
package google.firestore.admin.v1;
18+
19+
import "google/api/field_behavior.proto";
20+
import "google/api/resource.proto";
21+
import "google/protobuf/timestamp.proto";
22+
23+
option csharp_namespace = "Google.Cloud.Firestore.Admin.V1";
24+
option go_package = "cloud.google.com/go/firestore/apiv1/admin/adminpb;adminpb";
25+
option java_multiple_files = true;
26+
option java_outer_classname = "PitrSnapshotProto";
27+
option java_package = "com.google.firestore.admin.v1";
28+
option objc_class_prefix = "GCFS";
29+
option php_namespace = "Google\\Cloud\\Firestore\\Admin\\V1";
30+
option ruby_package = "Google::Cloud::Firestore::Admin::V1";
31+
32+
// A consistent snapshot of a database at a specific point in time.
33+
// A PITR (Point-in-time recovery) snapshot with previous versions of a
34+
// database's data is available for every minute up to the associated database's
35+
// data retention period. If the PITR feature is enabled, the retention period
36+
// is 7 days; otherwise, it is one hour.
37+
message PitrSnapshot {
38+
// Required. The name of the database that this was a snapshot of. Format:
39+
// `projects/{project}/databases/{database}`.
40+
string database = 1 [
41+
(google.api.field_behavior) = REQUIRED,
42+
(google.api.resource_reference) = {
43+
type: "firestore.googleapis.com/Database"
44+
}
45+
];
46+
47+
// Output only. Public UUID of the database the snapshot was associated with.
48+
bytes database_uid = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
49+
50+
// Required. Snapshot time of the database.
51+
google.protobuf.Timestamp snapshot_time = 3
52+
[(google.api.field_behavior) = REQUIRED];
53+
}

0 commit comments

Comments
 (0)