This document shows you how to delete schema revisions for Pub/Sub topics. The delete operation for a schema also deletes all the revisions associated with the schema.
Before you begin
- Understand how Pub/Sub schemas work .
- Create a schema .
Required roles and permissions
To get the permissions that
you need to delete and manage schema revisions,
ask your administrator to grant you the Pub/Sub Editor
( roles/pubsub.editor
)
IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations
.
This predefined role contains the permissions required to delete and manage schema revisions. To see the exact permissions that are required, expand the Required permissionssection:
Required permissions
The following permissions are required to delete and manage schema revisions:
- Create schema:
pubsub.schemas.create
- Attach schema to topic:
pubsub.schemas.attach
- Commit a schema revision:
pubsub.schemas.commit
- Delete a schema or a schema revision:
pubsub.schemas.delete
- Get a schema or schema revisions:
pubsub.schemas.get
- List schemas:
pubsub.schemas.list
- List schema revisions:
pubsub.schemas.listRevisions
- Rollback a schema:
pubsub.schemas.rollback
- Validate a message:
pubsub.schemas.validate
- Get the IAM policy for a schema:
pubsub.schemas.getIamPolicy
- Configure the IAM policy
for a schema:
pubsub.schemas.setIamPolicy
You might also be able to get these permissions with custom roles or other predefined roles .
You can grant roles and permissions to principals such as users, groups, domains, or service accounts. You can create a schema in one project and attach it to a topic located in a different project. Ensure that you have the required permissions for each project.
Delete a schema revision
The following are some important guidelines for deleting a schema revision:
-
You can delete one or multiple schema revisions from a schema.
-
If the schema has only one revision, you cannot delete the revision. Instead, delete the schema.
-
The delete operation for a schema also deletes all the revisions associated with the schema.
-
If you delete a schema, publishing messages to topics associated with that schema fails.
-
If you delete a schema revision, and it's specified as the first revision for a topic, the next revision is used instead for validation.
If the deleted schema revision is specified as the last revision for a topic, the previous schema revision is used instead for validation.
If the deleted schema revision falls within the specified revision range for a topic for validation, the revision is skipped.
You can delete a schema revision using the Google Cloud console, the gcloud CLI, the Pub/Sub API, or the Cloud Client Libraries.
Console
-
In the Google Cloud console, go to the Pub/Sub schemaspage.
-
Click the name of an existing schema.
The Schema detailspage for the schema opens.
-
Select the revision that you want to delete. You can also select multiple revisions.
-
Click Delete revision.
-
Confirm the delete operation.
gcloud
gcloud pubsub schemas delete-revision SCHEMA_NAME@REVISION_ID
Where:
- REVISION_ID is the revision to which you want to roll back.
REST
To delete a schema revision, send a DELETE request like the following:
POST https://pubsub.googleapis.com/v1/projects/ PROJECT_ID /schemas/ SCHEMA_ID@REVISION_ID:deleteRevision Authorization: Bearer $(gcloud auth application-default print-access-token) Content-Type: application/json --data @response-body.json
The response body should contain a JSON representation the deleted schema resource .
C++
Before trying this sample, follow the C++ setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub C++ API reference documentation .
Go
The following sample uses the major version of the Go Pub/Sub client library (v2). If you are still using the v1 library, see the migration guide to v2 . To see a list of v1 code samples, see the deprecated code samples .
Before trying this sample, follow the Go setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Go API reference documentation .
Java
Before trying this sample, follow the Java setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Java API reference documentation .
Python
Before trying this sample, follow the Python setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Python API reference documentation .
Node.js
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Node.js API reference documentation .
Node.js
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Node.js API reference documentation .