dpgaspar commented on code in PR #34679:
URL: https://github.com/apache/superset/pull/34679#discussion_r2287456623
##########
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:
do we still need this?
##########
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"]
+ ):
+ logger.warning(
+ "Database URI appears to be a fallback value. "
+ "Skipping database-dependent sync."
+ )
+ return
+
+ # Check if database is up-to-date with migrations
+ if not self._is_database_up_to_date():
Review Comment:
is it still necessary? if superset init's without having the database up to
date will it be silently in a broken state?
--
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]