Skip to content

Commit

Permalink
Ignore indexes managed by spanner (#68)
Browse files Browse the repository at this point in the history
* Use spanner emulator v1.2.0

* Ignore indexes managed by spanner

Spanner creates secondary backing indexes for foreign keys.
Such indexes have random names and are not suitable for use via yo generated code.
  • Loading branch information
tyamagu2 committed Jul 22, 2021
1 parent e48ae7f commit 44edfc5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
PROJECT: yo-test
INSTANCE: yo-test
DATABASE: yo-test
- image: gcr.io/cloud-spanner-emulator/emulator:1.0.0
- image: gcr.io/cloud-spanner-emulator/emulator:1.2.0
working_directory: /go/src/github.com/cloudspannerecosystem/yo
steps:
- checkout
Expand Down
5 changes: 4 additions & 1 deletion loaders/spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ func SpanTableIndexes(client *spanner.Client, table string) ([]*models.Index, er
const sqlstr = `SELECT ` +
`INDEX_NAME, IS_UNIQUE ` +
`FROM INFORMATION_SCHEMA.INDEXES ` +
`WHERE TABLE_SCHEMA = "" AND INDEX_NAME != "PRIMARY_KEY" AND TABLE_NAME = @table `
`WHERE TABLE_SCHEMA = "" ` +
`AND INDEX_NAME != "PRIMARY_KEY" ` +
`AND TABLE_NAME = @table ` +
`AND SPANNER_IS_MANAGED = FALSE `

stmt := spanner.NewStatement(sqlstr)
stmt.Params["table"] = table
Expand Down

0 comments on commit 44edfc5

Please sign in to comment.