File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -1184,6 +1184,7 @@ def get_alter_operations(
11841184 def alter_table (
11851185 self ,
11861186 alter_expressions : t .Union [t .List [exp .Alter ], t .List [TableAlterOperation ]],
1187+ ** kwargs : t .Any ,
11871188 ) -> None :
11881189 """
11891190 Performs the alter statements to change the current table into the structure of the target table.
Original file line number Diff line number Diff line change @@ -689,6 +689,31 @@ def clone_table(
689689 ** kwargs ,
690690 )
691691
692+ def alter_table (
693+ self ,
694+ alter_expressions : t .Union [t .List [exp .Alter ], t .List ["TableAlterOperation" ]],
695+ ** kwargs : t .Any ,
696+ ) -> None :
697+ # Snowflake requires ALTER ICEBERG TABLE instead of ALTER TABLE for Iceberg tables
698+ table_format = kwargs .pop ("table_format" , None )
699+ if table_format and isinstance (table_format , str ) and table_format .upper () == "ICEBERG" :
700+ from sqlmesh .core .schema_diff import TableAlterOperation
701+
702+ resolved_expressions = []
703+ for x in alter_expressions :
704+ if isinstance (x , TableAlterOperation ):
705+ alter_expr = x .expression
706+ else :
707+ alter_expr = x
708+ alter_expr .args ["kind" ] = f"{ table_format .upper ()} TABLE"
709+ resolved_expressions .append (alter_expr )
710+
711+ with self .transaction ():
712+ for alter_expr in resolved_expressions :
713+ self .execute (alter_expr )
714+ else :
715+ super ().alter_table (alter_expressions , ** kwargs )
716+
692717 @t .overload
693718 def _columns_to_types (
694719 self ,
Original file line number Diff line number Diff line change @@ -2109,7 +2109,7 @@ def migrate(
21092109 _check_additive_schema_change (
21102110 snapshot , alter_operations , kwargs ["allow_additive_snapshots" ]
21112111 )
2112- self .adapter .alter_table (alter_operations )
2112+ self .adapter .alter_table (alter_operations , table_format = snapshot . model . table_format )
21132113
21142114 # Apply grants after schema migration
21152115 deployability_index = kwargs .get ("deployability_index" )
You can’t perform that action at this time.
0 commit comments