Vitor-Avila commented on code in PR #32829:
URL: https://github.com/apache/superset/pull/32829#discussion_r2012271576
##########
superset/commands/database/update.py:
##########
@@ -159,6 +172,29 @@ def _handle_ssh_tunnel(self, database: Database) ->
SSHTunnel | None:
ssh_tunnel_properties,
).run()
+ def _update_catalog_attribute(
+ self,
+ database_id: int,
+ new_catalog: str | None,
+ ) -> None:
+ """
+ Update the catalog of the datasets that are associated with database.
+ """
+ from superset.connectors.sqla.models import SqlaTable
+ from superset.models.sql_lab import Query, SavedQuery, TableSchema,
TabState
+
+ for model in [
+ SqlaTable,
+ Query,
+ SavedQuery,
+ TabState,
+ TableSchema,
+ ]:
+ fk = "db_id" if model == SavedQuery else "database_id"
+ predicate = {fk: database_id}
+ update = {"catalog": new_catalog}
+ db.session.query(model).filter_by(**predicate).update(update)
Review Comment:
Nice!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]