Skip to content

Commit

Permalink
Additional table movement support fixes
Browse files Browse the repository at this point in the history
- Ensure consistent serialized schema names
- Make drop table operator tolerant of missing tables
- Print serialized schema name
  • Loading branch information
geoffxy committed May 3, 2024
1 parent e297115 commit dc45218
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/brad/admin/modify_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ def register_admin_action(subparser) -> None:
help="Set to abort an in-progress transition. "
"Only do this if you know what you are doing!",
)
parser.add_argument(
"--reset-schema-name",
action="store_true",
help="Set to ensure the serialized schema name is the same as the "
"passed-in schema name. Sometimes there may be a mismatch, which can "
"cause problems.",
)
parser.set_defaults(admin_action=modify_blueprint)


Expand Down Expand Up @@ -350,7 +357,9 @@ def modify_blueprint(args) -> None:
enum_blueprint.set_routing_policy(full_policy)

# 6. Write the changes back.
modified_blueprint = enum_blueprint.to_blueprint()
modified_blueprint = enum_blueprint.to_blueprint(
forced_schema_name=args.schema_name if args.reset_schema_name else None
)
if blueprint == modified_blueprint:
logger.info("No changes made to the blueprint.")
return
Expand Down
2 changes: 2 additions & 0 deletions src/brad/blueprint/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def __repr__(self) -> str:
"---",
indefinite_policies,
definite_policy,
"---",
f"Schema name: {self.schema_name()}",
]
)

Expand Down
2 changes: 1 addition & 1 deletion src/brad/data_sync/operators/drop_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __repr__(self) -> str:
)

async def execute(self, ctx: ExecutionContext) -> "Operator":
query_template = "DROP TABLE {}"
query_template = "DROP TABLE IF EXISTS {}"

if self._engine == Engine.Aurora:
for table in self._table_names:
Expand Down
4 changes: 2 additions & 2 deletions src/brad/planner/enumeration/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def set_routing_policy(
self._current_routing_policy = routing_policy
return self

def to_blueprint(self) -> Blueprint:
def to_blueprint(self, forced_schema_name: Optional[str] = None) -> Blueprint:
"""
Makes a copy of this object as a `Blueprint`.
"""

return Blueprint(
self.schema_name(),
self.schema_name() if forced_schema_name is None else forced_schema_name,
self.tables(),
table_locations={
name: locations.copy()
Expand Down

0 comments on commit dc45218

Please sign in to comment.