fix: avoid re-running run-once migrations (409)#422
Open
cburyta wants to merge 3 commits intoSnowflake-Labs:masterfrom
Open
fix: avoid re-running run-once migrations (409)#422cburyta wants to merge 3 commits intoSnowflake-Labs:masterfrom
cburyta wants to merge 3 commits intoSnowflake-Labs:masterfrom
Conversation
…atch (Snowflake-Labs#409) Snowflake stores schema and table names in uppercase in INFORMATION_SCHEMA. When change_history_table is specified with lowercase names (e.g. from config), the previous REPLACE-only comparison failed, so fetch_change_history_metadata() returned {} and schemachange re-ran all versioned scripts. - fetch_change_history_metadata: UPPER(REPLACE(...)) for TABLE_SCHEMA and TABLE_NAME - change_history_schema_exists: UPPER(REPLACE(...)) for SCHEMA_NAME
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull Request: Fix INFORMATION_SCHEMA case sensitivity (#409)
Summary
Fixes the bug where schemachange re-deploys all versioned scripts when the change history table is specified with lowercase schema/table names (e.g.
mydb.myschema.change_history). Snowflake stores identifiers in uppercase inINFORMATION_SCHEMA; the previous query used a case-sensitive comparison, so the lookup returned no rows and schemachange treated the table as missing.Problem
fetch_change_history_metadata()andchange_history_schema_exists()compared againstINFORMATION_SCHEMAusingREPLACE('schema_name','"','')without normalizing case. Snowflake returnsTABLE_SCHEMA = 'MYSCHEMA', so'myschema' != 'MYSCHEMA'and the query returns no rows.Solution
Use
UPPER(REPLACE(...))in the WHERE clause for:fetch_change_history_metadata()–TABLE_SCHEMAandTABLE_NAMEin theINFORMATION_SCHEMA.TABLESquery.change_history_schema_exists()–SCHEMA_NAMEin theINFORMATION_SCHEMA.SCHEMATAquery.No change to object references (e.g.
fully_qualified); Snowflake is already case-insensitive for those. Only the INFORMATION_SCHEMA lookups are fixed.Testing
test_fetch_change_history_metadata_uses_upper_for_information_schema– builds a session with lowercaseChangeHistoryTableand asserts the executed query containsUPPER(REPLACE(so the lookup is case-insensitive.Checklist
pytest)ruff format .)ruff check .)