feat(pubsub): Add pubsub_rollback_schema sample#1816
Conversation
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new feature to roll back a Google Cloud Pub/Sub schema to a previous revision, including a Gemfile, the implementation in rollback_schema.rb, and corresponding RSpec tests. The feedback suggests minor improvements: adding parentheses to the method definition to comply with Ruby style guidelines, using the client's built-in schema_path helper instead of manual string interpolation, and correcting the Protobuf syntax definition in the tests to use double quotes as strictly required by the Protocol Buffers specification.
| # [START pubsub_rollback_schema] | ||
| require "google/cloud/pubsub" | ||
|
|
||
| def rollback_schema project_id:, schema_id:, revision_id: |
There was a problem hiding this comment.
According to the community Ruby Style Guide, parentheses should be used for method definitions that have arguments. Adding parentheses also ensures that the code complies with standard RuboCop rules (such as Style/MethodDefParentheses), which is important since the PR checklist includes a RuboCop lint pass.
def rollback_schema(project_id:, schema_id:, revision_id:)References
- Use parentheses for method definitions when they have arguments. (link)
| pubsub = Google::Cloud::PubSub.new project_id: project_id | ||
| schema_client = pubsub.schema_service_client | ||
|
|
||
| schema_path = "projects/#{project_id}/schemas/#{schema_id}" |
There was a problem hiding this comment.
Instead of manually constructing the schema resource path using string interpolation, it is more robust and idiomatic to use the path helper method schema_path provided by the GAPIC client. This prevents potential errors in path formatting.
schema_path = schema_client.schema_path project: project_id, schema: schema_id| @schema_path = "projects/#{@project_id}/schemas/#{@schema_id}" | ||
|
|
||
| # Create schema (Revision 1) | ||
| @definition_1 = "syntax = 'proto3'; message Message { string data = 1; }" |
There was a problem hiding this comment.
Protocol Buffers specification strictly requires double quotes for the syntax statement (i.e., syntax = "proto3";). While some parsers might be lenient, using single quotes ('proto3') can lead to parsing errors in strict environments or future updates. It is safer and more standard to use single quotes for the Ruby string literal and double quotes for the protobuf definition.
@definition_1 = 'syntax = "proto3"; message Message { string data = 1; }'| @revision_1_id = @initial_schema.revision_id | ||
|
|
||
| # Commit revision (Revision 2) | ||
| @definition_2 = "syntax = 'proto3'; message Message { string data = 1; string new_field = 2; }" |
There was a problem hiding this comment.
Protocol Buffers specification strictly requires double quotes for the syntax statement (i.e., syntax = "proto3";). It is safer and more standard to use single quotes for the Ruby string literal and double quotes for the protobuf definition.
@definition_2 = 'syntax = "proto3"; message Message { string data = 1; string new_field = 2; }'
Description
Fixes #
Note: It's a good idea to open an issue first for discussion.
Checklist
bundle exec rubocop