kaxil commented on a change in pull request #10254:
URL: https://github.com/apache/airflow/pull/10254#discussion_r537744155



##########
File path: airflow/utils/db.py
##########
@@ -597,6 +597,68 @@ def check_migrations(timeout):
             log.info('Waiting for migrations... %s second(s)', ticker)
 
 
+def check_conn_id_duplicates(session=None):
+    """
+    Check unique conn_id in connection table
+    @param session:  session of the sqlalchemy
+    @return: str
+    """
+    dups = []
+    try:
+        dups = session.query(Connection, func.count(Connection.conn_id)) \
+                      .group_by(Connection.conn_id) \
+                      .having(func.count(Connection.conn_id) > 1).all()
+    except (exc.OperationalError, exc.ProgrammingError):
+        # fallback if tables hasn't been created yet
+        pass
+    if dups:
+        return f'Seems you have non unique conn_id in connection table.\n' \
+               f'You have to manage those duplicate connections ' \
+               f'before upgrading the database.\n' \
+               f'Duplicated conn_id: {[dup[0] for dup in dups]}'
+
+    return ''
+
+
+def check_conn_type_null(session=None):
+    """
+    Check nullable conn_type column in connection table
+    @param session:  session of the sqlalchemy
+    @return: str
+    """
+    n_nulls = []
+    try:
+        n_nulls = session.query(Connection)\
+                         .filter(Connection.conn_type.is_(None)).all()
+    except (exc.OperationalError, exc.ProgrammingError, exc.InternalError):
+        # fallback if tables hasn't been created yet
+        pass
+
+    if n_nulls:
+        return f'The conn_type column in the connection ' \
+               f'table must contain content.\n' \
+               f'Make sure you don\'t have null ' \
+               f'in the conn_type column.\n' \
+               f'Null conn_type conn_id: {list(n_nulls)}'

Review comment:
       ```suggestion
           return 'The conn_type column in the connection ' \
                  'table must contain content.\n' \
                  'Make sure you don\'t have null ' \
                  'in the conn_type column.\n' \
                  f'Null conn_type conn_id: {list(n_nulls)}'
   ```




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to