Skip to content

Commit f27972e

Browse files
committed
feat(spanner): add support for proto bundle DDL statements
1 parent 36d17ba commit f27972e

File tree

4 files changed

+1353
-130
lines changed

4 files changed

+1353
-130
lines changed

database/spanner/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ as described in [README.md#database-urls](../../README.md#database-urls)
1515
| ----- | ------------------- | ----------- |
1616
| `x-migrations-table` | `MigrationsTable` | Name of the migrations table |
1717
| `x-clean-statements` | `CleanStatements` | Whether to parse and clean DDL statements before running migration towards Spanner (Required for comments and multiple statements) |
18+
| `x-proto-descriptors-file` | `ProtoDescriptorsFile` | File containing proto descriptors to use for `PROTO BUNDLE` statements |
1819
| `url` | `DatabaseName` | The full path to the Spanner database resource. If provided as part of `Config` it must not contain a scheme or query string to match the format `projects/{projectId}/instances/{instanceId}/databases/{databaseName}`|
1920
| `projectId` || The Google Cloud Platform project id
2021
| `instanceId` || The id of the instance running Spanner

database/spanner/spanner.go

+20-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"log"
99
nurl "net/url"
10+
"os"
1011
"regexp"
1112
"strconv"
1213
"strings"
@@ -55,7 +56,8 @@ type Config struct {
5556
// running them towards Spanner.
5657
// Parsing outputs clean DDL statements such as reformatted
5758
// and void of comments.
58-
CleanStatements bool
59+
CleanStatements bool
60+
ProtoDescriptorsFile string
5961
}
6062

6163
// Spanner implements database.Driver for Google Cloud Spanner
@@ -136,11 +138,14 @@ func (s *Spanner) Open(url string) (database.Driver, error) {
136138
}
137139
}
138140

141+
protoDescriptorsFile := purl.Query().Get("x-proto-descriptors-file")
142+
139143
db := &DB{admin: adminClient, data: dataClient}
140144
return WithInstance(db, &Config{
141-
DatabaseName: dbname,
142-
MigrationsTable: migrationsTable,
143-
CleanStatements: clean,
145+
DatabaseName: dbname,
146+
MigrationsTable: migrationsTable,
147+
CleanStatements: clean,
148+
ProtoDescriptorsFile: protoDescriptorsFile,
144149
})
145150
}
146151

@@ -182,10 +187,19 @@ func (s *Spanner) Run(migration io.Reader) error {
182187
}
183188
}
184189

190+
var protoDescriptors []byte
191+
if s.config.ProtoDescriptorsFile != "" {
192+
protoDescriptors, err = os.ReadFile(s.config.ProtoDescriptorsFile)
193+
if err != nil {
194+
return err
195+
}
196+
}
197+
185198
ctx := context.Background()
186199
op, err := s.db.admin.UpdateDatabaseDdl(ctx, &adminpb.UpdateDatabaseDdlRequest{
187-
Database: s.config.DatabaseName,
188-
Statements: stmts,
200+
Database: s.config.DatabaseName,
201+
Statements: stmts,
202+
ProtoDescriptors: protoDescriptors,
189203
})
190204

191205
if err != nil {

go.mod

+47-44
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module github.com/golang-migrate/migrate/v4
22

3-
go 1.22.0
3+
go 1.23.0
44

55
toolchain go1.23.1
66

77
require (
8-
cloud.google.com/go/spanner v1.56.0
9-
cloud.google.com/go/storage v1.38.0
8+
cloud.google.com/go/spanner v1.76.1
9+
cloud.google.com/go/storage v1.50.0
1010
github.com/Azure/go-autorest/autorest/adal v0.9.16
1111
github.com/ClickHouse/clickhouse-go v1.4.3
1212
github.com/aws/aws-sdk-go v1.49.6
@@ -33,47 +33,52 @@ require (
3333
github.com/nakagami/firebirdsql v0.0.0-20190310045651-3c02a58cfed8
3434
github.com/neo4j/neo4j-go-driver v1.8.1-0.20200803113522-b626aa943eba
3535
github.com/snowflakedb/gosnowflake v1.6.19
36-
github.com/stretchr/testify v1.9.0
36+
github.com/stretchr/testify v1.10.0
3737
github.com/xanzy/go-gitlab v0.15.0
3838
go.mongodb.org/mongo-driver v1.7.5
3939
go.uber.org/atomic v1.7.0
40-
golang.org/x/oauth2 v0.18.0
40+
golang.org/x/oauth2 v0.26.0
4141
golang.org/x/tools v0.24.0
42-
google.golang.org/api v0.169.0
42+
google.golang.org/api v0.222.0
4343
modernc.org/ql v1.0.0
4444
modernc.org/sqlite v1.18.1
4545
)
4646

4747
require (
48+
cel.dev/expr v0.19.0 // indirect
49+
cloud.google.com/go/auth v0.14.1 // indirect
50+
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
51+
cloud.google.com/go/monitoring v1.24.0 // indirect
52+
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2 // indirect
53+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 // indirect
54+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0 // indirect
55+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 // indirect
4856
github.com/distribution/reference v0.6.0 // indirect
4957
github.com/docker/go-connections v0.5.0 // indirect
5058
github.com/felixge/httpsnoop v1.0.4 // indirect
5159
github.com/go-logr/logr v1.4.2 // indirect
5260
github.com/go-logr/stdr v1.2.2 // indirect
5361
github.com/jackc/puddle/v2 v2.2.1 // indirect
54-
github.com/json-iterator/go v1.1.12 // indirect
55-
github.com/kr/text v0.2.0 // indirect
5662
github.com/moby/docker-image-spec v1.3.1 // indirect
57-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
58-
github.com/modern-go/reflect2 v1.0.2 // indirect
59-
github.com/rogpeppe/go-internal v1.12.0 // indirect
60-
github.com/stretchr/objx v0.5.2 // indirect
61-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
62-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
63-
go.opentelemetry.io/otel v1.29.0 // indirect
63+
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
64+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
65+
go.opentelemetry.io/contrib/detectors/gcp v1.34.0 // indirect
66+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0 // indirect
67+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
68+
go.opentelemetry.io/otel v1.34.0 // indirect
6469
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
65-
go.opentelemetry.io/otel/metric v1.29.0 // indirect
66-
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
67-
go.opentelemetry.io/otel/trace v1.29.0 // indirect
70+
go.opentelemetry.io/otel/metric v1.34.0 // indirect
71+
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
72+
go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect
73+
go.opentelemetry.io/otel/trace v1.34.0 // indirect
6874
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
6975
)
7076

7177
require (
72-
cloud.google.com/go v0.112.1 // indirect
73-
cloud.google.com/go/compute v1.25.1 // indirect
74-
cloud.google.com/go/compute/metadata v0.2.3 // indirect
75-
cloud.google.com/go/iam v1.1.6 // indirect
76-
cloud.google.com/go/longrunning v0.5.5 // indirect
78+
cloud.google.com/go v0.118.2 // indirect
79+
cloud.google.com/go/compute/metadata v0.6.0 // indirect
80+
cloud.google.com/go/iam v1.4.0 // indirect
81+
cloud.google.com/go/longrunning v0.6.4 // indirect
7782
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
7883
github.com/99designs/keyring v1.2.1 // indirect
7984
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 // indirect
@@ -102,17 +107,17 @@ require (
102107
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.11 // indirect
103108
github.com/aws/smithy-go v1.13.3 // indirect
104109
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
105-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
110+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
106111
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 // indirect
107-
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 // indirect
112+
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
108113
github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369 // indirect
109114
github.com/danieljoos/wincred v1.1.2 // indirect
110115
github.com/davecgh/go-spew v1.1.1 // indirect
111116
github.com/docker/go-units v0.5.0 // indirect
112117
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
113118
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect
114-
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
115-
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
119+
github.com/envoyproxy/go-control-plane v0.13.1 // indirect
120+
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
116121
github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect
117122
github.com/gabriel-vasile/mimetype v1.4.1 // indirect
118123
github.com/go-stack/stack v1.8.0 // indirect
@@ -123,14 +128,13 @@ require (
123128
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
124129
github.com/golang-sql/sqlexp v0.1.0 // indirect
125130
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
126-
github.com/golang/protobuf v1.5.4 // indirect
127131
github.com/golang/snappy v0.0.4 // indirect
128132
github.com/google/flatbuffers v2.0.8+incompatible // indirect
129133
github.com/google/go-querystring v1.1.0 // indirect
130-
github.com/google/s2a-go v0.1.7 // indirect
134+
github.com/google/s2a-go v0.1.9 // indirect
131135
github.com/google/uuid v1.6.0 // indirect
132-
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
133-
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
136+
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
137+
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
134138
github.com/gorilla/handlers v1.4.2 // indirect
135139
github.com/gorilla/mux v1.7.4 // indirect
136140
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
@@ -176,22 +180,21 @@ require (
176180
github.com/zeebo/xxh3 v1.0.2 // indirect
177181
gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b // indirect
178182
go.opencensus.io v0.24.0 // indirect
179-
golang.org/x/crypto v0.31.0 // indirect
183+
golang.org/x/crypto v0.33.0 // indirect
180184
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect
181185
golang.org/x/mod v0.21.0 // indirect
182-
golang.org/x/net v0.33.0 // indirect
183-
golang.org/x/sync v0.10.0 // indirect
184-
golang.org/x/sys v0.28.0 // indirect
185-
golang.org/x/term v0.27.0 // indirect
186-
golang.org/x/text v0.21.0 // indirect
187-
golang.org/x/time v0.5.0 // indirect
186+
golang.org/x/net v0.35.0 // indirect
187+
golang.org/x/sync v0.11.0 // indirect
188+
golang.org/x/sys v0.30.0 // indirect
189+
golang.org/x/term v0.29.0 // indirect
190+
golang.org/x/text v0.22.0 // indirect
191+
golang.org/x/time v0.10.0 // indirect
188192
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
189-
google.golang.org/appengine v1.6.8 // indirect
190-
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
191-
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 // indirect
192-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
193-
google.golang.org/grpc v1.64.1 // indirect
194-
google.golang.org/protobuf v1.34.2 // indirect
193+
google.golang.org/genproto v0.0.0-20250122153221-138b5a5a4fd4 // indirect
194+
google.golang.org/genproto/googleapis/api v0.0.0-20250219182151-9fdb1cabc7b2 // indirect
195+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250219182151-9fdb1cabc7b2 // indirect
196+
google.golang.org/grpc v1.70.0 // indirect
197+
google.golang.org/protobuf v1.36.5 // indirect
195198
gopkg.in/inf.v0 v0.9.1 // indirect
196199
gopkg.in/yaml.v3 v3.0.1 // indirect
197200
lukechampine.com/uint128 v1.2.0 // indirect

0 commit comments

Comments
 (0)