diff --git a/frappe/core/doctype/version/version.json b/frappe/core/doctype/version/version.json index 37294355ee..57cd54b6d2 100644 --- a/frappe/core/doctype/version/version.json +++ b/frappe/core/doctype/version/version.json @@ -188,7 +188,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-12-29 14:39:45.926836", + "modified": "2018-04-10 14:39:45.926836", "modified_by": "Administrator", "module": "Core", "name": "Version", diff --git a/frappe/core/doctype/version/version.py b/frappe/core/doctype/version/version.py index 671eb8c597..9d945fed11 100644 --- a/frappe/core/doctype/version/version.py +++ b/frappe/core/doctype/version/version.py @@ -85,4 +85,7 @@ def get_diff(old, new, for_child=False): return out else: - return None \ No newline at end of file + return None + +def on_doctype_update(): + frappe.db.add_index("Version", ["ref_doctype", "docname"]) \ No newline at end of file diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index 64d7daca71..a52538eb1d 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -110,7 +110,8 @@ class DbTable: for col in columns: if len(col.fieldname) >= 64: - frappe.throw(_("Fieldname is limited to 64 characters ({0})").format(frappe.bold(col.fieldname))) + frappe.throw(_("Fieldname is limited to 64 characters ({0})") + .format(frappe.bold(col.fieldname))) if col.fieldtype in type_map and type_map[col.fieldtype][0]=="varchar": @@ -119,33 +120,35 @@ class DbTable: if not (1 <= new_length <= 1000): frappe.throw(_("Length of {0} should be between 1 and 1000").format(col.fieldname)) - try: - # check for truncation - max_length = frappe.db.sql("""select max(char_length(`{fieldname}`)) from `tab{doctype}`"""\ - .format(fieldname=col.fieldname, doctype=self.doctype)) + current_col = self.current_columns.get(col.fieldname, {}) + if not current_col: + continue + current_type = self.current_columns[col.fieldname]["type"] + current_length = re.findall('varchar\(([\d]+)\)', current_type) + if not current_length: + # case when the field is no longer a varchar + continue + current_length = current_length[0] + if cint(current_length) != cint(new_length): + try: + # check for truncation + max_length = frappe.db.sql("""select max(char_length(`{fieldname}`)) from `tab{doctype}`"""\ + .format(fieldname=col.fieldname, doctype=self.doctype)) - except pymysql.InternalError as e: - if e.args[0] == ER.BAD_FIELD_ERROR: - # Unknown column 'column_name' in 'field list' - continue + except pymysql.InternalError as e: + if e.args[0] == ER.BAD_FIELD_ERROR: + # Unknown column 'column_name' in 'field list' + continue - else: - raise + else: + raise - if max_length and max_length[0][0] and max_length[0][0] > new_length: - current_type = self.current_columns[col.fieldname]["type"] - current_length = re.findall('varchar\(([\d]+)\)', current_type) - if not current_length: - # case when the field is no longer a varchar - continue + if max_length and max_length[0][0] and max_length[0][0] > new_length: + if col.fieldname in self.columns: + self.columns[col.fieldname].length = current_length - current_length = current_length[0] - - if col.fieldname in self.columns: - self.columns[col.fieldname].length = current_length - - frappe.msgprint(_("Reverting length to {0} for '{1}' in '{2}'; Setting the length as {3} will cause truncation of data.")\ - .format(current_length, col.fieldname, self.doctype, new_length)) + frappe.msgprint(_("Reverting length to {0} for '{1}' in '{2}'; Setting the length as {3} will cause truncation of data.")\ + .format(current_length, col.fieldname, self.doctype, new_length)) def sync(self): @@ -180,7 +183,8 @@ class DbTable: parentfield varchar({varchar_len}), parenttype varchar({varchar_len}), idx int(8) not null default '0', - %sindex parent(parent)) + %sindex parent(parent), + index modified(modified)) ENGINE={engine} ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4