Commit 7b0af8e
committed
Include Schema When Creating Indices
Fixes an issue where indices aren't able to be created for tables in
schemas. At present, `create_index emits SQL like
```sql
CREATE INDEX index_name (col) ON schema_name.table_name
```
which results in an error when creating the table:
```
Index index_name cannot index a table/index schema_name.table_name
which is in a different named schema.
```
because the name needs to be prefixed by schema.
`drop_index` does emit the correct SQL with the schema prefix.
```sql
DROP INDEX schema_name.index_name
```
This is due to an odd issue where the base class's
`visit_create_index` method has in its signature
`include_schema=False`:
https://github.com/sqlalchemy/sqlalchemy/blob/299284cec65076fd4c76bf1efaae60b60f4d4f7b/lib/sqlalchemy/sql/compiler.py#L6828C23-L6828C43
but `visit_drop_index` hard-codes the value to `True`:
https://github.com/sqlalchemy/sqlalchemy/blob/299284cec65076fd4c76bf1efaae60b60f4d4f7b/lib/sqlalchemy/sql/compiler.py#L6870
The dialects handle this by hard-coding `include_schema=True` in
`visit_create_index`, e.g.
sqlite:
https://github.com/sqlalchemy/sqlalchemy/blob/299284cec65076fd4c76bf1efaae60b60f4d4f7b/lib/sqlalchemy/dialects/sqlite/base.py#L1740
The difference in defaults is odd in the base class, but it seems like
include_schema=True is the appropriate setting for Spanner.1 parent e17c5ef commit 7b0af8e
File tree
2 files changed
+43
-3
lines changed- google/cloud/sqlalchemy_spanner
- test/mockserver_tests
2 files changed
+43
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
534 | | - | |
535 | | - | |
536 | | - | |
| 534 | + | |
537 | 535 | | |
538 | 536 | | |
539 | 537 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
137 | 179 | | |
138 | 180 | | |
139 | 181 | | |
| |||
0 commit comments