|
32 | 32 |
|
33 | 33 | from sqlglot import exp, select |
34 | 34 | from sqlglot.executor import execute |
| 35 | +from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_not_exception_type |
35 | 36 |
|
36 | 37 | from sqlmesh.core import constants as c |
37 | 38 | from sqlmesh.core import dialect as d |
|
76 | 77 | from sqlmesh.utils.errors import ( |
77 | 78 | ConfigError, |
78 | 79 | DestructiveChangeError, |
| 80 | + MigrationNotSupportedError, |
79 | 81 | SQLMeshError, |
80 | 82 | format_destructive_change_msg, |
81 | 83 | format_additive_change_msg, |
@@ -1035,7 +1037,6 @@ def _clone_snapshot_in_dev( |
1035 | 1037 | adapter.clone_table( |
1036 | 1038 | target_table_name, |
1037 | 1039 | snapshot.table_name(), |
1038 | | - replace=True, |
1039 | 1040 | rendered_physical_properties=rendered_physical_properties, |
1040 | 1041 | ) |
1041 | 1042 | self._migrate_target_table( |
@@ -1111,6 +1112,15 @@ def _migrate_snapshot( |
1111 | 1112 | dry_run=True, |
1112 | 1113 | ) |
1113 | 1114 |
|
| 1115 | + # Retry in case when the table is migrated concurrently from another plan application |
| 1116 | + @retry( |
| 1117 | + reraise=True, |
| 1118 | + stop=stop_after_attempt(5), |
| 1119 | + wait=wait_exponential(min=1, max=16), |
| 1120 | + retry=retry_if_not_exception_type( |
| 1121 | + (DestructiveChangeError, AdditiveChangeError, MigrationNotSupportedError) |
| 1122 | + ), |
| 1123 | + ) |
1114 | 1124 | def _migrate_target_table( |
1115 | 1125 | self, |
1116 | 1126 | target_table_name: str, |
@@ -2672,7 +2682,7 @@ def migrate( |
2672 | 2682 | ) |
2673 | 2683 | if len(potential_alter_operations) > 0: |
2674 | 2684 | # this can happen if a user changes a managed model and deliberately overrides a plan to be forward only, eg `sqlmesh plan --forward-only` |
2675 | | - raise SQLMeshError( |
| 2685 | + raise MigrationNotSupportedError( |
2676 | 2686 | f"The schema of the managed model '{target_table_name}' cannot be updated in a forward-only fashion." |
2677 | 2687 | ) |
2678 | 2688 |
|
|
0 commit comments