mistercrunch commented on code in PR #34679:
URL: https://github.com/apache/superset/pull/34679#discussion_r2289417125


##########
superset/app.py:
##########
@@ -96,6 +100,90 @@ def send_static_file(self, filename: str) -> Response:
                 return Response("", status=204)  # No Content
         return super().send_static_file(filename)
 
+    def _is_database_up_to_date(self) -> bool:
+        """
+        Check if database migrations are up to date.
+        Returns False if there are pending migrations or unable to determine.
+        """
+        try:
+            # Import here to avoid circular import issues
+            from superset.extensions import db
+
+            # Get current revision from database
+            with db.engine.connect() as connection:
+                context = MigrationContext.configure(connection)
+                current_rev = context.get_current_revision()
+
+            # Get head revision from migration files
+            alembic_cfg = Config()
+            alembic_cfg.set_main_option("script_location", 
"superset:migrations")
+            script = ScriptDirectory.from_config(alembic_cfg)
+            head_rev = script.get_current_head()
+
+            # Database is up-to-date if current revision matches head
+            is_current = current_rev == head_rev
+            if not is_current:
+                logger.debug(
+                    "Pending migrations. Current: %s, Head: %s",
+                    current_rev,
+                    head_rev,
+                )
+            return is_current
+        except Exception as e:
+            logger.debug("Could not check migration status: %s", e)
+            return False
+
+    def sync_config_to_db(self) -> None:
+        """
+        Synchronize configuration to database.
+        This method handles database-dependent features that need to be synced
+        after the app is initialized and database connection is available.
+
+        This is separated from app initialization to support multi-tenant
+        environments where database connection might not be available during
+        app startup.
+        """
+        try:
+            # Import here to avoid circular import issues
+            from superset.extensions import feature_flag_manager
+
+            # Check if database URI is a fallback value before trying to 
connect
+            db_uri = self.config.get("SQLALCHEMY_DATABASE_URI", "")
+            if not db_uri or any(
+                fallback in db_uri.lower()
+                for fallback in ["nouser", "nopassword", "nohost", "nodb"]

Review Comment:
   idk! @eschutho I think you might have added this logic



-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to