jscheffl commented on code in PR #66674:
URL: https://github.com/apache/airflow/pull/66674#discussion_r3222426161


##########
providers/edge3/src/airflow/providers/edge3/models/db.py:
##########
@@ -61,6 +61,67 @@ class EdgeDBManager(BaseDBManager):
     supports_table_dropping = True
     revision_heads_map = _REVISION_HEADS_MAP
 
+    # TODO: Remove these compatibility overrides once the minimum supported
+    # Airflow version is 3.3, which includes the equivalent BaseDBManager 
implementation.
+    def _has_existing_manager_tables(self) -> bool:
+        """Return whether any table managed by this DB manager already 
exists."""
+        inspector = inspect(self.session.get_bind())
+        table_names_by_schema: dict[str | None, set[str]] = {}
+        for table in self.metadata.tables.values():
+            table_names_by_schema.setdefault(table.schema, 
set()).add(table.name)
+
+        for schema, table_names in table_names_by_schema.items():
+            existing_table_names = 
set(inspector.get_table_names(schema=schema))
+            if table_names.intersection(existing_table_names):
+                return True
+        return False
+
+    def _get_base_revision(self, config=None) -> str:
+        """Return the first/base Alembic revision for this DB manager."""
+        script = self.get_script_object(config)
+        for revision in script.walk_revisions():
+            if revision.down_revision is None:
+                return revision.revision
+        raise RuntimeError(f"No base revision found for 
{self.__class__.__name__}")
+
+    def _stamp_base_revision(self, config) -> None:
+        """Stamp the database to this DB manager's base Alembic revision."""
+        from alembic import command
+
+        base_revision = self._get_base_revision(config)
+        self.log.info(
+            "%s tables already exist without an Alembic version; stamping base 
revision %s before upgrade",
+            self.__class__.__name__,
+            base_revision,
+        )
+        command.stamp(config, base_revision)
+
+    def upgradedb(self, to_revision=None, from_revision=None, 
show_sql_only=False, use_migration_files=False):

Review Comment:
   Nit: Can we repeat the comment to all 4 methods added? Else the scope of 
comment is unclear in a year or so



-- 
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]

Reply via email to