Documentation ¶
Overview ¶
Copyright 2024 Google LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2024 Google LLC ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- type SpannerAccessor
- type SpannerAccessorImpl
- func (sp *SpannerAccessorImpl) CheckExistingDb(ctx context.Context, dbURI string) (bool, error)
- func (sp *SpannerAccessorImpl) CheckIfChangeStreamExists(ctx context.Context, changeStreamName, dbURI string) (bool, error)
- func (sp *SpannerAccessorImpl) CreateChangeStream(ctx context.Context, changeStreamName, dbURI string) error
- func (sp *SpannerAccessorImpl) CreateDatabase(ctx context.Context, dbURI string, conv *internal.Conv, driver string, ...) error
- func (sp *SpannerAccessorImpl) CreateEmptyDatabase(ctx context.Context, dbURI string) error
- func (sp *SpannerAccessorImpl) CreateOrUpdateDatabase(ctx context.Context, dbURI, driver string, conv *internal.Conv, ...) error
- func (sp *SpannerAccessorImpl) DropDatabase(ctx context.Context, dbURI string) error
- func (sp *SpannerAccessorImpl) GetDatabaseDialect(ctx context.Context, dbURI string) (string, error)
- func (sp *SpannerAccessorImpl) GetSpannerLeaderLocation(ctx context.Context, instanceURI string) (string, error)
- func (sp *SpannerAccessorImpl) Refresh(ctx context.Context, dbURI string)
- func (sp *SpannerAccessorImpl) UpdateDDLForeignKeys(ctx context.Context, dbURI string, conv *internal.Conv, driver string, ...)
- func (sp *SpannerAccessorImpl) UpdateDatabase(ctx context.Context, dbURI string, conv *internal.Conv, driver string) error
- func (sp *SpannerAccessorImpl) ValidateChangeStreamOptions(ctx context.Context, changeStreamName, dbURI string) error
- func (sp *SpannerAccessorImpl) ValidateDDL(ctx context.Context, dbURI string) error
- func (sp *SpannerAccessorImpl) ValidateDML(ctx context.Context, query string) (bool, error)
- func (sp *SpannerAccessorImpl) VerifyDb(ctx context.Context, dbURI string) (dbExists bool, err error)
- type SpannerAccessorMock
- func (sam *SpannerAccessorMock) CheckExistingDb(ctx context.Context, dbURI string) (bool, error)
- func (sam *SpannerAccessorMock) CheckIfChangeStreamExists(ctx context.Context, changeStreamName, dbURI string) (bool, error)
- func (sam *SpannerAccessorMock) CreateChangeStream(ctx context.Context, changeStreamName, dbURI string) error
- func (sam *SpannerAccessorMock) CreateDatabase(ctx context.Context, dbURI string, conv *internal.Conv, driver string, ...) error
- func (sam *SpannerAccessorMock) CreateEmptyDatabase(ctx context.Context, dbURI string) error
- func (sam *SpannerAccessorMock) CreateOrUpdateDatabase(ctx context.Context, dbURI, driver string, conv *internal.Conv, ...) error
- func (sam *SpannerAccessorMock) DropDatabase(ctx context.Context, dbURI string) error
- func (sam *SpannerAccessorMock) GetDatabaseDialect(ctx context.Context, dbURI string) (string, error)
- func (sam *SpannerAccessorMock) GetSpannerLeaderLocation(ctx context.Context, instanceURI string) (string, error)
- func (sam *SpannerAccessorMock) UpdateDDLForeignKeys(ctx context.Context, dbURI string, conv *internal.Conv, driver string, ...)
- func (sam *SpannerAccessorMock) UpdateDatabase(ctx context.Context, dbURI string, conv *internal.Conv, driver string) error
- func (sam *SpannerAccessorMock) ValidateChangeStreamOptions(ctx context.Context, changeStreamName, dbURI string) error
- func (sam *SpannerAccessorMock) ValidateDDL(ctx context.Context, dbURI string) error
- func (sam *SpannerAccessorMock) ValidateDML(ctx context.Context, query string) (bool, error)
- func (sam *SpannerAccessorMock) VerifyDb(ctx context.Context, dbURI string) (dbExists bool, err error)
Constants ¶
This section is empty.
Variables ¶
var ( // Set the maximum number of concurrent workers during foreign key creation. // This number should not be too high so as to not hit the AdminQuota limit. // AdminQuota limits are mentioned here: https://cloud.google.com/spanner/quotas#administrative_limits // If facing a quota limit error, consider reducing this value. MaxWorkers = 50 )
Functions ¶
This section is empty.
Types ¶
type SpannerAccessor ¶
type SpannerAccessor interface { // Fetch the dialect of the spanner database. GetDatabaseDialect(ctx context.Context, dbURI string) (string, error) // CheckExistingDb checks whether the database with dbURI exists or not. // If API call doesn't respond then user is informed after every 5 minutes on command line. CheckExistingDb(ctx context.Context, dbURI string) (bool, error) // Create a database with no schema. CreateEmptyDatabase(ctx context.Context, dbURI string) error // Fetch the leader of the Spanner instance. GetSpannerLeaderLocation(ctx context.Context, instanceURI string) (string, error) // Check if a change stream already exists. CheckIfChangeStreamExists(ctx context.Context, changeStreamName, dbURI string) (bool, error) // Validate that change stream option 'VALUE_CAPTURE_TYPE' is 'NEW_ROW'. ValidateChangeStreamOptions(ctx context.Context, changeStreamName, dbURI string) error // Create a change stream with default options. CreateChangeStream(ctx context.Context, changeStreamName, dbURI string) error // Create new Database using conv CreateDatabase(ctx context.Context, dbURI string, conv *internal.Conv, driver string, migrationType string) error // Update Database using conv UpdateDatabase(ctx context.Context, dbURI string, conv *internal.Conv, driver string) error // Updates an existing Spanner database or create a new one if one does not exist using Conv CreateOrUpdateDatabase(ctx context.Context, dbURI, driver string, conv *internal.Conv, migrationType string) error // Check whether the db exists and if it does, verify if the schema is what we currently support. VerifyDb(ctx context.Context, dbURI string) (dbExists bool, err error) // Verify if an existing DB's ddl follows what is supported by Spanner migration tool. Currently, we only support empty schema when db already exists. ValidateDDL(ctx context.Context, dbURI string) error // UpdateDDLForeignKeys updates the Spanner database with foreign key constraints using ALTER TABLE statements. UpdateDDLForeignKeys(ctx context.Context, dbURI string, conv *internal.Conv, driver string, migrationType string) // Deletes a database. DropDatabase(ctx context.Context, dbURI string) error //Runs a query against the provided spanner database and returns if the executed DML is validate or not ValidateDML(ctx context.Context, query string) (bool, error) }
The SpannerAccessor provides methods that internally use a spanner client (can be adminClient/databaseclient/instanceclient etc). Methods should only contain generic logic here that can be used by multiple workflows.
type SpannerAccessorImpl ¶
type SpannerAccessorImpl struct { InstanceClient spinstanceadmin.InstanceAdminClient AdminClient spanneradmin.AdminClient SpannerClient spannerclient.SpannerClient }
This implements the SpannerAccessor interface. This is the primary implementation that should be used in all places other than tests.
func NewSpannerAccessorClientImpl ¶
func NewSpannerAccessorClientImpl(ctx context.Context) (*SpannerAccessorImpl, error)
func NewSpannerAccessorClientImplWithSpannerClient ¶
func NewSpannerAccessorClientImplWithSpannerClient(ctx context.Context, dbURI string) (*SpannerAccessorImpl, error)
func (*SpannerAccessorImpl) CheckExistingDb ¶
func (*SpannerAccessorImpl) CheckIfChangeStreamExists ¶
func (sp *SpannerAccessorImpl) CheckIfChangeStreamExists(ctx context.Context, changeStreamName, dbURI string) (bool, error)
Consider using a CreateChangestream operation and check for alreadyExists error. That uses adminClient which can be unit tested.
func (*SpannerAccessorImpl) CreateChangeStream ¶
func (sp *SpannerAccessorImpl) CreateChangeStream(ctx context.Context, changeStreamName, dbURI string) error
func (*SpannerAccessorImpl) CreateDatabase ¶
func (sp *SpannerAccessorImpl) CreateDatabase(ctx context.Context, dbURI string, conv *internal.Conv, driver string, migrationType string) error
CreateDatabase returns a newly create Spanner DB. It automatically determines an appropriate project, selects a Spanner instance to use, generates a new Spanner DB name, and call into the Spanner admin interface to create the new DB.
func (*SpannerAccessorImpl) CreateEmptyDatabase ¶
func (sp *SpannerAccessorImpl) CreateEmptyDatabase(ctx context.Context, dbURI string) error
func (*SpannerAccessorImpl) CreateOrUpdateDatabase ¶
func (sp *SpannerAccessorImpl) CreateOrUpdateDatabase(ctx context.Context, dbURI, driver string, conv *internal.Conv, migrationType string) error
CreatesOrUpdatesDatabase updates an existing Spanner database or creates a new one if one does not exist.
func (*SpannerAccessorImpl) DropDatabase ¶
func (sp *SpannerAccessorImpl) DropDatabase(ctx context.Context, dbURI string) error
func (*SpannerAccessorImpl) GetDatabaseDialect ¶
func (*SpannerAccessorImpl) GetSpannerLeaderLocation ¶
func (*SpannerAccessorImpl) Refresh ¶
func (sp *SpannerAccessorImpl) Refresh(ctx context.Context, dbURI string)
func (*SpannerAccessorImpl) UpdateDDLForeignKeys ¶
func (sp *SpannerAccessorImpl) UpdateDDLForeignKeys(ctx context.Context, dbURI string, conv *internal.Conv, driver string, migrationType string)
UpdateDDLForeignKeys updates the Spanner database with foreign key constraints using ALTER TABLE statements.
func (*SpannerAccessorImpl) UpdateDatabase ¶
func (sp *SpannerAccessorImpl) UpdateDatabase(ctx context.Context, dbURI string, conv *internal.Conv, driver string) error
UpdateDatabase updates an existing spanner database.
func (*SpannerAccessorImpl) ValidateChangeStreamOptions ¶
func (sp *SpannerAccessorImpl) ValidateChangeStreamOptions(ctx context.Context, changeStreamName, dbURI string) error
func (*SpannerAccessorImpl) ValidateDDL ¶
func (sp *SpannerAccessorImpl) ValidateDDL(ctx context.Context, dbURI string) error
ValidateDDL verifies if an existing DB's ddl follows what is supported by Spanner migration tool. Currently, we only support empty schema when db already exists.
func (*SpannerAccessorImpl) ValidateDML ¶
type SpannerAccessorMock ¶
type SpannerAccessorMock struct { GetDatabaseDialectMock func(ctx context.Context, dbURI string) (string, error) CheckExistingDbMock func(ctx context.Context, dbURI string) (bool, error) CreateEmptyDatabaseMock func(ctx context.Context, dbURI string) error GetSpannerLeaderLocationMock func(ctx context.Context, instanceURI string) (string, error) CheckIfChangeStreamExistsMock func(ctx context.Context, changeStreamName, dbURI string) (bool, error) ValidateChangeStreamOptionsMock func(ctx context.Context, changeStreamName, dbURI string) error CreateChangeStreamMock func(ctx context.Context, changeStreamName, dbURI string) error CreateDatabaseMock func(ctx context.Context, dbURI string, conv *internal.Conv, driver string, migrationType string) error UpdateDatabaseMock func(ctx context.Context, dbURI string, conv *internal.Conv, driver string) error CreateOrUpdateDatabaseMock func(ctx context.Context, dbURI, driver string, conv *internal.Conv, migrationType string) error VerifyDbMock func(ctx context.Context, dbURI string) (dbExists bool, err error) ValidateDDLMock func(ctx context.Context, dbURI string) error UpdateDDLForeignKeysMock func(ctx context.Context, dbURI string, conv *internal.Conv, driver string, migrationType string) DropDatabaseMock func(ctx context.Context, dbURI string) error ValidateDMLMock func(ctx context.Context, query string) (bool, error) }
Mock that implements the SpannerAccessor interface. Pass in unit tests where SpannerAccessor is an input parameter.
func (*SpannerAccessorMock) CheckExistingDb ¶
func (*SpannerAccessorMock) CheckIfChangeStreamExists ¶
func (*SpannerAccessorMock) CreateChangeStream ¶
func (sam *SpannerAccessorMock) CreateChangeStream(ctx context.Context, changeStreamName, dbURI string) error
func (*SpannerAccessorMock) CreateDatabase ¶
func (*SpannerAccessorMock) CreateEmptyDatabase ¶
func (sam *SpannerAccessorMock) CreateEmptyDatabase(ctx context.Context, dbURI string) error
func (*SpannerAccessorMock) CreateOrUpdateDatabase ¶
func (*SpannerAccessorMock) DropDatabase ¶
func (sam *SpannerAccessorMock) DropDatabase(ctx context.Context, dbURI string) error
DropDatabase implements SpannerAccessor.
func (*SpannerAccessorMock) GetDatabaseDialect ¶
func (*SpannerAccessorMock) GetSpannerLeaderLocation ¶
func (*SpannerAccessorMock) UpdateDDLForeignKeys ¶
func (*SpannerAccessorMock) UpdateDatabase ¶
func (*SpannerAccessorMock) ValidateChangeStreamOptions ¶
func (sam *SpannerAccessorMock) ValidateChangeStreamOptions(ctx context.Context, changeStreamName, dbURI string) error
func (*SpannerAccessorMock) ValidateDDL ¶
func (sam *SpannerAccessorMock) ValidateDDL(ctx context.Context, dbURI string) error
func (*SpannerAccessorMock) ValidateDML ¶
ValidateDML implements SpannerAccessor.