Migrating Google Datastore from V1 to V2
How to upgrade
Update your google/cloud-datastore
dependency to ^2.0
:
{
"require": {
"google/cloud-datastore": "^2.0"
}
}
Breaking Changes
EntityInterface changes
Types have been added to the methods in EntityInterface
. This means that
any classes implementing this interface will need to be updated to match the new method signatures:
class Business implements EntityInterface
{
use EntityTrait;
- public static function mappings()
+ public static function mappings(): array
{
return [
'parent' => Business::class
];
}
}
Client Options changes
The following ClientOptions
have been reorganized. This was
done to ensure client options are consistent across all Google Cloud clients.
-
authCache-> Moved tocredentialsConfig.authCache -
authCacheOptions-> Moved tocredentialsConfig.authCacheOptions -
credentialsFetcher-> Moved tocredentials -
keyFile-> Moved tocredentials -
keyFilePath-> Moved tocredentials -
requestTimeout-> Removed from client options and moved to a call optiontimeoutMillis -
scopes-> Moved tocredentialsConfig.scopes -
defaultScopes-> Moved tocredentialsConfig.defaultScopes -
quotaProject-> Moved tocredentialsConfig.quotaProject -
httpHandler-> Moved totransportConfig.rest.httpHandler -
authHttpHandler-> Moved tocredentialsConfig.authHttpHandler -
asyncHttpHandler-> Removed in favor of a single httpHandler option. -
restOptions-> Moved totransportConfig.rest -
grpcOptions-> Moved totransportConfig.grpc -
accessToken-> Removed - This option is no longer supported. Use the$credentialsFetcheroption instead. -
shouldSignRequest-> Removed - obsolete -
preferNumericProjectId-> Removed - obsolete
Retry Options changes
The retry options have been moved to use RetrySettings
in Client Options and in
call options.
-
retries-> Renamed toretrySettings.maxRetries -
restRetryFunction-> Renamed toretrySettings.retryFunction -
grpcRetryFunction-> Renamed toretrySettings.retryFunction -
delayFunc/calcDelayFunction-> Removed in favor of the propertiesretrySettings.initialRetryDelayMillis,retrySettings.retryDelayMultiplierandretrySettings.maxRetryDelayMillis.
Internal changes
We expect these changes to not break existing code, as they have been done in
classes marked @internal
or as part of refactoring, but to be safe, these
changes have been released in a major version.
Types for properties, parameters, and return types.
Types have been added for all properties, parameters and return types. This means that any classes
implementing interfaces in this library (specifically, EntityInterface
as mentioned above),
will need to be updated to match the new method signatures. Typing constraints may have other effects
where the incorrect types had been previously applied.
Options array validation
Previously, if unrecognized array keys were passed into methods, these additional arguments would
be ignored. Now, a LogicException
will be thrown in the OptionsValidator
class with the message
"Unexpected option(s) provided: [OPTION-NAME]". If you see this exception, and you believe it to be
an error, please file an issue in the google-cloud-php repo
and let us
know.
Connection classes are not used anymore.
The following classes are removed, and have been replaced with the generated
GAPIC client Google\Cloud\Datastore\V1\Client\DatastoreClient
:
-
Google\Cloud\Datastore\Connection\ConnectionInterfaceis removed -
Google\Cloud\Datastore\Connection\Restis removed -
Google\Cloud\Datastore\Connection\Grpcis removed
Additionally, the previously generated GAPIC client
( Google\Cloud\Datastore\V1\DatastoreClient
, which has a similar name to Google\Cloud\Datastore\V1\Client\DatastoreClient
, but without the Client
namespace) has been removed. For more information, see Migrating to V2
.
Constants in Query\Query
have been changed from string to int
These constants are used internally, but if they are being used in any code, they will need to be updated:
-
Google\Cloud\Datastore\Query\Query::OP_DEFAULTchanged from'EQUAL'to5 -
Google\Cloud\Datastore\Query\Query::OP_LESS_THANchanged from'LESS_THAN'to1 -
Google\Cloud\Datastore\Query\Query::OP_LESS_THAN_OR_EQUALchanged from'LESS_THAN_OR_EQUAL'to2 -
Google\Cloud\Datastore\Query\Query::OP_GREATER_THANchanged from'GREATER_THAN'to3 -
Google\Cloud\Datastore\Query\Query::OP_GREATER_THAN_OR_EQUALchanged from'GREATER_THAN_OR_EQUAL'to4 -
Google\Cloud\Datastore\Query\Query::OP_EQUALSchanged from'EQUAL'to5 -
Google\Cloud\Datastore\Query\Query::OP_NOT_EQUALSchanged from'NOT_EQUAL'to9 -
Google\Cloud\Datastore\Query\Query::OP_INchanged from'IN'to6 -
Google\Cloud\Datastore\Query\Query::OP_NOT_INchanged from'NOT_IN'to13 -
Google\Cloud\Datastore\Query\Query::OP_HAS_ANCESTORchanged from'HAS_ANCESTOR'to11 -
Google\Cloud\Datastore\Query\Query::ORDER_DEFAULTchanged from'ASCENDING'to1 -
Google\Cloud\Datastore\Query\Query::ORDER_DESCENDINGchanged from'DESCENDING'to2 -
Google\Cloud\Datastore\Query\Query::ORDER_ASCENDINGchanged from'ASCENDING'to1
Protobuf backwards compatibility files have been removed
These class aliases have been deprecated for a very long time, and are finally being removed. Update
to the namespaced version (replacing _
with \
) to upgrade.
-
Google\Cloud\Datastore\V1\PropertyFilter_Operatorhas been removed -
Google\Cloud\Datastore\V1\EntityResult_ResultTypehas been removed -
Google\Cloud\Datastore\V1\CommitRequest_Modehas been removed -
Google\Cloud\Datastore\V1\CompositeFilter_Operatorhas been removed -
Google\Cloud\Datastore\V1\TransactionOptions_ReadWritehas been removed -
Google\Cloud\Datastore\V1\QueryResultBatch_MoreResultsTypehas been removed -
Google\Cloud\Datastore\V1\TransactionOptions_ReadOnlyhas been removed -
Google\Cloud\Datastore\V1\PropertyOrder_Directionhas been removed -
Google\Cloud\Datastore\V1\AggregationQuery_Aggregationhas been removed -
Google\Cloud\Datastore\V1\ReadOptions_ReadConsistencyhas been removed -
Google\Cloud\Datastore\V1\Key_PathElementhas been removed -
Google\Cloud\Datastore\V1\AggregationQuery_Aggregation_Counthas been removed

