Added Schema Filter to "drop_all_indexes()" #439
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The macro "drop_all_indexes()" searches in sys.indexes for all indexes that are applied on a specific table. But this table is only identified by the name of the table.
This leads to the following problem:
When having the same table (therefore the same name) in different schemas, the macro will drop the indexes on all the tables with this name, no matter the schema.
When working with the "generate_schema_name" macro to create a schema per developer, each of them will also drop all indexes of the tables of other developers.
To solve this, a simple additional WHERE condition can be used, which uses
target.schema
as the value of the schema.The
drop_all_indexes()
macro before:With the additional WHERE condition: