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

Code before:
      currentSchemaInfo.comment = updatedComment;
      dispatch({
        type: LOAD_SCHEMA,
        allSchemas: existingSchemas.concat(currentSchemaInfo),
      });
      dispatch(activateCommentEdit(false, null));
    };
    const customOnError = () => {};

    makeMigrationCall(
      dispatch,
      getState,
      schemaChangesUp,
      schemaChangesDown,
      migrationName,
      customOnSuccess,
      customOnError,
      requestMsg,
      successMsg,
      errorMsg,
      true
    );
  };
};

const isColumnUnique = (tableSchema, colName) => {
  const { primary_key, unique_constraints } = tableSchema;

  const columnPkConstraint =
    primary_key.columns.includes(colName) && primary_key.columns.length === 1;

  const columnUniqueConstraint =
    unique_constraints.filter(
      constraint =>
        constraint.columns.includes(colName) && constraint.columns.length === 1
    ).length > 0;

  return columnPkConstraint || columnUniqueConstraint;
};

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();

Review comment (suggestion):
Can you undo this change?
I understand you did this because primary key is technically unique.
But the distinction here is based on the constraints. And it is confusing to mix the two. Maybe you can change the function name to `hasUniqueKeyConstraint` and `hasPKConstraint` for it to semantically be correct.

Code after:
    const successMsg = 'Comment Updated';
    const errorMsg = 'Updating comment failed';

    const customOnSuccess = () => {
      // Instead of calling loadSchema, update only the table comment in the state.
      // get existing state and filter out with table name and table schema.
      // update the comment and set in the state.
      const existingSchemas = getState().tables.allSchemas.filter(
        schemaInfo =>
          !(
            schemaInfo.table_name !== tableName &&
            schemaInfo.table_schema !== currentSchema
          )
      );
      const currentSchemaInfo = getState().tables.allSchemas.find(
        schemaInfo =>
          schemaInfo.table_name === tableName &&
          schemaInfo.table_schema === currentSchema
      );
      currentSchemaInfo.comment = updatedComment;
      dispatch({
        type: LOAD_SCHEMA,
        allSchemas: existingSchemas.concat(currentSchemaInfo),
      });
      dispatch(activateCommentEdit(false, null));
    };
    const customOnError = () => {};

    makeMigrationCall(
      dispatch,
      getState,
      schemaChangesUp,
      schemaChangesDown,
      migrationName,
      customOnSuccess,
      customOnError,
      requestMsg,
      successMsg,
      errorMsg,
      true
    );
  };
};

const isColumnUnique = (tableSchema, colName) => {
  return (
    tableSchema.unique_constraints.filter(
      constraint =>
        constraint.columns.includes(colName) && constraint.columns.length === 1
    ).length > 0
  );