code: def get_table_constraints(
      conn, table_name
  ) -> dict[tuple[str, str], list[str]]:
      """Return primary and unique constraint along with column name.
  
      This function return primary and unique constraint
      along with column name. some tables like task_instance
      is missing primary key constraint name and the name is
      auto-generated by sql server. so this function helps to
      retrieve any primary or unique constraint name.
  
      :param conn: sql connection object
      :param table_name: table name
      :return: a dictionary of ((constraint name, constraint type), column name) of table
      """
      query = text(
          f"""SELECT tc.CONSTRAINT_NAME , tc.CONSTRAINT_TYPE, ccu.COLUMN_NAME
       FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
       JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu ON ccu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
       WHERE tc.TABLE_NAME = '{table_name}' AND
       (tc.CONSTRAINT_TYPE = 'PRIMARY KEY' or UPPER(tc.CONSTRAINT_TYPE) = 'UNIQUE')
      """
      )
      result = conn.execute(query).fetchall()
      constraint_dict = defaultdict(list)
      for constraint, constraint_type, column in result:
          constraint_dict[(constraint, constraint_type)].append(column)
      return constraint_dict
  
file_path: airflow/airflow/migrations/versions/0046_1_10_5_change_datetime_to_datetime2_6_on_mssql_.py
imports: from __future__ import annotations
  from collections import defaultdict
  from alembic import op
  from sqlalchemy import text
  from sqlalchemy.dialects import mssql
label_desc: Use image node_id 3 for calling a global function with example usage: get_table_constraints(conn, table_name) and returns: constraint_dict