From 70c58ccb81bbe60b0eeb6a4e1bd838f269c9864f Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 19 Oct 2015 17:25:05 +0530 Subject: [PATCH] [hotfix] patches and varchar length check --- frappe/model/db_schema.py | 2 +- frappe/patches.txt | 3 ++- frappe/patches/v6_4/reduce_varchar_length.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index 3a3e15cd22..87dbc0b041 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -106,7 +106,7 @@ class DbTable: try: # check for truncation - max_length = frappe.db.sql("""select max(length(`{fieldname}`)) from `tab{doctype}`"""\ + max_length = frappe.db.sql("""select max(char_length(`{fieldname}`)) from `tab{doctype}`"""\ .format(fieldname=col.fieldname, doctype=self.doctype)) except MySQLdb.OperationalError, e: diff --git a/frappe/patches.txt b/frappe/patches.txt index f25f0ac91d..d982d96efd 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -11,6 +11,7 @@ execute:frappe.reload_doc('core', 'doctype', 'version') #2014-02-21 execute:frappe.reload_doc('email', 'doctype', 'email_alert') #2014-07-15 execute:frappe.reload_doc('desk', 'doctype', 'todo') #2014-12-31-1 execute:frappe.reload_doc('custom', 'doctype', 'property_setter') #2014-12-31-1 +execute:frappe.reload_doctype("File") # 2015-10-19 execute:frappe.db.sql("alter table `tabSessions` modify `user` varchar(255), engine=InnoDB") execute:frappe.db.sql("delete from `tabDocField` where parent='0'") frappe.patches.v4_0.change_varchar_length @@ -96,4 +97,4 @@ execute:frappe.db.sql("delete from tabSessions where user is null") frappe.patches.v6_2.rename_backup_manager execute:frappe.delete_doc("DocType", "Backup Manager") frappe.patches.v6_4.reduce_varchar_length -frappe.patches.v6_4.rename_bengali_language \ No newline at end of file +frappe.patches.v6_4.rename_bengali_language diff --git a/frappe/patches/v6_4/reduce_varchar_length.py b/frappe/patches/v6_4/reduce_varchar_length.py index 45229769cc..bb02451d9b 100644 --- a/frappe/patches/v6_4/reduce_varchar_length.py +++ b/frappe/patches/v6_4/reduce_varchar_length.py @@ -12,12 +12,12 @@ def execute(): if not column_type.startswith("varchar"): continue - max_length = frappe.db.sql("""select max(length(`{fieldname}`)) from `tab{doctype}`"""\ + max_length = frappe.db.sql("""select max(char_length(`{fieldname}`)) from `tab{doctype}`"""\ .format(fieldname=fieldname, doctype=doctype)) max_length = max_length[0][0] if max_length else None - if max_length and max_length > 140: + if max_length and 140 < max_length <= 255: print "setting length of '{fieldname}' in '{doctype}' as {length}".format( fieldname=fieldname, doctype=doctype, length=max_length)