ephraimbuddy commented on code in PR #63920: URL: https://github.com/apache/airflow/pull/63920#discussion_r2964311915
########## airflow-core/tests/unit/migrations/test_0101_ui_improvements_for_deadlines.py: ########## @@ -0,0 +1,112 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import importlib.util +from pathlib import Path + +from sqlalchemy.exc import OperationalError + +from tests_common.test_utils.paths import AIRFLOW_CORE_SOURCES_PATH + +MIGRATION_PATH = Path( + AIRFLOW_CORE_SOURCES_PATH, + "airflow/migrations/versions/0101_3_2_0_ui_improvements_for_deadlines.py", +) + + +def load_migration_module(): + spec = importlib.util.spec_from_file_location( + "migration_0101_ui_improvements_for_deadlines", MIGRATION_PATH + ) + module = importlib.util.module_from_spec(spec) + assert spec.loader is not None + spec.loader.exec_module(module) + return module + + +def configure_migration(mocker, migration_module, *, dialect_name: str, indexes: list[dict]): + conn = mocker.MagicMock() + conn.dialect.name = dialect_name + + inspector = mocker.MagicMock() + inspector.get_indexes.return_value = indexes + inspector.get_pk_constraint.return_value = {"constrained_columns": ["id"]} + inspector.get_unique_constraints.return_value = [] + mocker.patch.object(migration_module.sa, "inspect", return_value=inspector) + + fake_op = mocker.MagicMock() + fake_op.get_bind.return_value = conn + mocker.patch.object(migration_module, "op", fake_op) + return fake_op Review Comment: I don't think we need the test file ########## airflow-core/src/airflow/migrations/versions/0101_3_2_0_ui_improvements_for_deadlines.py: ########## @@ -74,6 +75,83 @@ DEFAULT_BATCH_SIZE = 1000 ENCODING_TYPE = "deadline_alert" + +def _has_matching_index(conn: Connection, table_name: str, columns: Iterable[str]) -> bool: + log.debug("Targeting index check", table=table_name, columns=list(columns)) + target_columns = list(columns) + inspector = sa.inspect(conn) Review Comment: This won't work in offline mode. We should indicate that it won't work in offline mode so those using the offline mode are aware of it -- 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]
