-
Notifications
You must be signed in to change notification settings - Fork 250
/
zz_migration.0003_add_caveats.go
46 lines (40 loc) · 1.26 KB
/
zz_migration.0003_add_caveats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package migrations
import (
"context"
"cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
const (
createCaveatTable = `CREATE TABLE caveat (
name STRING(MAX),
definition BYTES(MAX) NOT NULL,
timestamp TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp=true)
) PRIMARY KEY (name)`
addRelationshipCaveatName = `ALTER TABLE relation_tuple
ADD COLUMN caveat_name STRING(MAX)`
addRelationshipCaveatContext = `ALTER TABLE relation_tuple
ADD COLUMN caveat_context JSON`
addChangelogCaveatName = `ALTER TABLE changelog
ADD COLUMN caveat_name STRING(MAX)`
addChangelogCaveatContext = `ALTER TABLE changelog
ADD COLUMN caveat_context JSON`
)
func init() {
if err := SpannerMigrations.Register("add-caveats", "add-metadata-and-counters", func(ctx context.Context, w Wrapper) error {
updateOp, err := w.adminClient.UpdateDatabaseDdl(ctx, &databasepb.UpdateDatabaseDdlRequest{
Database: w.client.DatabaseName(),
Statements: []string{
createCaveatTable,
addRelationshipCaveatName,
addRelationshipCaveatContext,
addChangelogCaveatName,
addChangelogCaveatContext,
},
})
if err != nil {
return err
}
return updateOp.Wait(ctx)
}, nil); err != nil {
panic("failed to register migration: " + err.Error())
}
}