Repository: hasura/graphql-engine
File: console/src/components/Services/Data/TableModify/ModifyActions.js (JavaScript)

Code before:
    const nullable = columnEdit.isNullable;
    const unique = columnEdit.isUnique;
    const colDefault = (columnEdit.default || '').trim();
    const comment = (columnEdit.comment || '').trim();
    const newName = columnEdit.name.trim();
    const currentSchema = columnEdit.schemaName;
    const customFieldName = (columnEdit.customFieldName || '').trim();

    const tableDef = generateTableDef(tableName, currentSchema);
    const table = findTable(getState().tables.allSchemas, tableDef);

    // check if column type has changed before making it part of the migration
    const originalColType = column.udt_name; // "value"
    const originalColDefault = column.column_default || ''; // null or "value"
    const originalColComment = column.comment || ''; // null or "value"
    const originalColNullable = column.is_nullable; // "YES" or "NO"
    const originalColUnique = isColumnUnique(table, colName);

    /* column type up/down migration */
    const columnChangesUpQuery =
      'ALTER TABLE ' +
      '"' +
      currentSchema +
      '"' +
      '.' +
      '"' +
      tableName +
      '"' +
      ' ALTER COLUMN ' +
      '"' +
      colName +
      '"' +
      ' TYPE ' +
      colType +
      ';';
    const columnChangesDownQuery =
      'ALTER TABLE ' +
      '"' +
      currentSchema +
      '"' +
      '.' +
      '"' +
      tableName +
      '"' +
      ' ALTER COLUMN ' +
      '"' +
      colName +
      '"' +
      ' TYPE ' +
      column.data_type +
      ';';

Review comment (suggestion):
Nice find!
`udt_name` - Hasura uses user-defined types instead of built-in Postgres `data_type`?

Is `data_type` used elsewhere by Hasura - Wondering about the niggling possible inconsistencies.

Referencing `columns` `element_types` documentation https://www.postgresql.org/docs/12/infoschema-element-types.html
data_type | character_data | Data type of the array elements, if it is a built-in type, else USER-DEFINED (in that case, the type is identified in udt_name and associated columns).
-- | -- | --




Code after:
      constraint =>
        constraint.columns.includes(colName) && constraint.columns.length === 1
    ).length > 0
  );
};

const saveColumnChangesSql = (colName, column, onSuccess) => {
  // eslint-disable-line no-unused-vars
  return (dispatch, getState) => {
    const columnEdit = getState().tables.modify.columnEdit[colName];

    const { tableName } = columnEdit;
    const colType = columnEdit.type;
    const nullable = columnEdit.isNullable;
    const unique = columnEdit.isUnique;
    const colDefault = (columnEdit.default || '').trim();
    const comment = (columnEdit.comment || '').trim();
    const newName = columnEdit.name.trim();
    const currentSchema = columnEdit.schemaName;
    const customFieldName = (columnEdit.customFieldName || '').trim();

    const tableDef = generateTableDef(tableName, currentSchema);
    const table = findTable(getState().tables.allSchemas, tableDef);

    // check if column type has changed before making it part of the migration
    const originalColType = column.udt_name; // "value"
    const originalColDefault = column.column_default || ''; // null or "value"
    const originalColComment = column.comment || ''; // null or "value"
    const originalColNullable = column.is_nullable; // "YES" or "NO"
    const originalColUnique = isColumnUnique(table, colName);

    /* column type up/down migration */
    const columnChangesUpQuery =
      'ALTER TABLE ' +
      '"' +
      currentSchema +
      '"' +
      '.' +
      '"' +
      tableName +
      '"' +
      ' ALTER COLUMN ' +
      '"' +
      colName +
      '"' +
      ' TYPE ' +
      colType +
      ';';
    const columnChangesDownQuery =
      'ALTER TABLE ' +
      '"' +