# Migrating Google Spanner from V1 to V2

2.9.0 (latest) 2.8.1 2.7.0 2.6.1 2.5.1 2.4.1 2.3.0 2.2.0 2.1.0 2.0.1-RC1 1.106.0 1.105.1 1.104.1 1.103.0 1.102.0 1.101.0 1.100.0 1.98.0 1.97.0 1.96.0 1.95.0 1.94.0 1.93.1 1.92.1 1.91.0 1.90.0 1.89.0 1.88.0 1.87.0 1.86.0 1.85.0 1.84.0 1.83.0 1.82.0 1.81.0 1.80.0 1.79.0 1.78.0 1.77.0 1.76.1 1.68.0 1.67.0 1.66.0 1.65.0 1.64.0 1.63.2 1.62.1 1.61.0 1.60.0 1.59.0 1.58.4 1.57.0 1.56.0 1.55.0 1.54.2

## How to upgrade

Update your `google/cloud-spanner` dependency to `^2.0`:

    {
        "require": {
            "google/cloud-spanner": "^2.0"
        }
    }

## Changes

### Version constant removed

Removed `SpannerClient::VERSION`, use the `VERSION` file in the library root instead.

### Client Options changes

The following client options are removed/replaced with other options present in
[`ClientOptions`](https://googleapis.github.io/gax-php/v1.26.1/Google/ApiCore/Options/ClientOptions.html). This was done to ensure client options are consistent across all
Google Cloud clients.

- `authCache` -\> Moved to `credentialsConfig.authCache`
- `authCacheOptions` -\> Moved to `credentialsConfig.authCacheOptions`
- `credentialsFetcher` -\> Moved to `credentials`
- `keyFile` -\> Moved to `credentials`
- `keyFilePath` -\> Moved to `credentials`
- `requestTimeout` -\> Removed from client options and moved to a call option `timeoutMillis`
- `scopes` -\> Moved to `credentialsConfig.scopes`
- `quotaProject` -\> Moved to `credentialsConfig.quotaProject`
- `httpHandler` -\> Moved to `transportConfig.rest.httpHandler`
- `authHttpHandler` -\> Moved to `credentialsConfig.authHttpHandler`
- `retries` -\> Removed from client options and moved to call options `retrySettings.maxRetries`

### Retry Options changes

The retry options have been moved to use [`RetrySettings`](https://googleapis.github.io/gax-php/v1.26.1/Google/ApiCore/RetrySettings.html) in call options
and function parameters.

- `retries` -\> Renamed to `retrySettings.maxRetries`
- `maxRetries` -\> Renamed to `retrySettings.maxRetries`

### Connection classes are not used anymore.

This is a major change with this major version but one that we hope won't break any users. When the
`SpannerClient` was created, behind the scenes a connection adapter was initialized.
This connection object was then forwarded to any resource classes internally,
like so:

    // This initialized a connection object
    $client = new SpannerClient();
    // This passed on the connection object to the Instance class
    $instance = $spanner->instance('my-instance');

As you can see the connection object was handled internally. If you used the library in this way,
you will not need to make any changes. However, if you created the connection classes directly
and passed it to the `Instance` class, this will break in Spanner `v2`:

    // Not intended
    $connObj = new Grpc([]);
    $instance = new Instance(
        $connObj,
        // other constructor options
    );

### `Google\Cloud\Spanner\Duration` class is not used anymore.

We have removed the `Google\Cloud\Spanner\Duration` class from the library. Instead we will be using the `Google\Protobuf\Duration` class.

### IAM class changes

We have kept the functionality of `IAM` the same, however the underlying `IAM` class has changed.

    // In V1, this used to return an instance of Google\Cloud\Core\Iam\Iam
    $iam = $instance->iam();

    // In V2, this will return an instance of Google\Cloud\Core\Iam\IamManager
    $iam = $instance->iam();

    // Both the classes share the same functionality, so the following methods will work for both versions.
    $iam->policy();
    $iam->setPolicy();
    $iam->testIamPermissions();

### LongRunningOperation class changes

We have kept the functionality of `LongRunningOperation` the same,
however the underlying `LongRunningOperation` class has changed.

    // In V1, this used to return an instance of Google\Cloud\Core\LongRunning\LongRunningOperation.
    $lro = $instance->create($configuration);

    // In V2, this will return an instance of Google\ApiCore\OperationResponse.
    $lro = $instance->create($configuration);

    // Both the classes share the same functionality, so the following methods will work for both versions.
    $lro->name();
    $lro->done();
    $lro->state();
    $lro->result();
    $lro->error();
    $lro->info();
    $lro->reload();
    $lro->pollUntilComplete();
    $lro->cancel();
    $lro->delete();

### Removed Methods

- `Operation::createTransaction` =\> use `Operation::transaction` instead
- `Operation::createSnapshot` =\> use `Operation::snapshot` instead
- `Database::close` =\> obsolete
- `Database::sessionPool` =\> obsolete
- `Database::batchCreateSessions` =\> obsolete
- `Database::deleteSessionAsync` =\> obsolete
- `BatchSnapshot::close` =\> obsolete
- `Operation::session` =\> obsolete
- `Operation::createSession` =\> (obsolete)
- `Operation::commitWithResponse` (obsolete) =\> use `Operation::commit` instead

### Removed Classes

- `Session\Session` =\> removed in favor of `SessionCache`
- `Session\CacheSessionPool` =\> removed in favor of `SessionCache`
- `Session\SessionPoolInterface` =\> removed in favor of `SessionCache`
- `Operation` - this class is marked `@internal`, and should not be used directly.