Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: don't generate unnecessary migrations (close #4215) #4393

Merged
merged 11 commits into from
Apr 27, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The order and collapsed state of columns is now persisted across page navigation
- console: decouple data rows and count fetch in data browser to account for really large tables (close #3793) (#4269)
- console: update cookie policy for API calls to "same-origin"
- console: redirect to /:table/browse from /:table (close #4330) (#4374)
- console: fix generating unnecessary migrations after modifying table columns (close #4125) (#4393)
- docs: add One-Click Render deployment guide (close #3683) (#4209)
- server: reserved keywords in column references break parser (fix #3597) #3927
- server: fix postgres specific error message that exposed database type on invalid query parameters (#4294)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const REMOVE_PRIMARY_KEY = 'ModifyTable/REMOVE_PRIMARY_KEY';
const RESET_PRIMARY_KEY = 'ModifyTable/RESET_PRIMARY_KEY';
const SET_PRIMARY_KEYS = 'ModifyTable/SET_PRIMARY_KEYS';

const SET_COLUMN_EDIT = 'ModifyTable/SET_COLUMN_EDIT;';
const RESET_COLUMN_EDIT = 'ModifyTable/RESET_COLUMN_EDIT;';
Comment on lines -87 to -88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops ;';

const SET_COLUMN_EDIT = 'ModifyTable/SET_COLUMN_EDIT';
const RESET_COLUMN_EDIT = 'ModifyTable/RESET_COLUMN_EDIT';
const EDIT_COLUMN = 'ModifyTable/EDIT_COLUMN';

const SET_FOREIGN_KEYS = 'ModifyTable/SET_FOREIGN_KEYS';
Expand Down Expand Up @@ -1438,18 +1438,25 @@ const saveTableCommentSql = isTable => {
};

const isColumnUnique = (tableSchema, colName) => {
beerose marked this conversation as resolved.
Show resolved Hide resolved
return (
tableSchema.unique_constraints.filter(
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
);
).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;
Expand All @@ -1464,7 +1471,7 @@ const saveColumnChangesSql = (colName, column, onSuccess) => {
const table = findTable(getState().tables.allSchemas, tableDef);

// check if column type has changed before making it part of the migration
const originalColType = column.data_type; // "value"
const originalColType = column.udt_name; // "value"
Comment on lines -1486 to +1487
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

const originalColDefault = column.column_default || ''; // null or "value"
const originalColComment = column.comment || ''; // null or "value"
const originalColNullable = column.is_nullable; // "YES" or "NO"
Expand Down