@@ -222,7 +222,7 @@ class DbColumn: | |||||
# unique | # unique | ||||
if ((self.unique and not current_def['unique']) and column_type not in ('text', 'longtext')): | if ((self.unique and not current_def['unique']) and column_type not in ('text', 'longtext')): | ||||
self.table.add_unique.append(self) | self.table.add_unique.append(self) | ||||
elif (current_def['unique'] and not self.unique): | |||||
elif (current_def['unique'] and not self.unique) and column_type not in ('text', 'longtext'): | |||||
self.table.drop_unique.append(self) | self.table.drop_unique.append(self) | ||||
# default | # default | ||||
@@ -233,7 +233,7 @@ class DbColumn: | |||||
self.table.set_default.append(self) | self.table.set_default.append(self) | ||||
# index should be applied or dropped irrespective of type change | # index should be applied or dropped irrespective of type change | ||||
if (current_def['index'] and not self.set_index): | |||||
if (current_def['index'] and not self.set_index) and column_type not in ('text', 'longtext'): | |||||
self.table.drop_index.append(self) | self.table.drop_index.append(self) | ||||
elif (not current_def['index'] and self.set_index) and not (column_type in ('text', 'longtext')): | elif (not current_def['index'] and self.set_index) and not (column_type in ('text', 'longtext')): | ||||
@@ -80,6 +80,12 @@ class TestDBUpdate(unittest.TestCase): | |||||
self.assertFalse(restrict_ip_in_table.index) | self.assertFalse(restrict_ip_in_table.index) | ||||
self.assertTrue(restrict_ip_in_table.unique) | self.assertTrue(restrict_ip_in_table.unique) | ||||
# explicitly make a text index | |||||
frappe.db.add_index(doctype, ["email_signature(200)"]) | |||||
frappe.db.updatedb(doctype) | |||||
email_sig_column = get_table_column("User", "email_signature") | |||||
self.assertEqual(email_sig_column.index, 1) | |||||
def get_fieldtype_from_def(field_def): | def get_fieldtype_from_def(field_def): | ||||
fieldtuple = frappe.db.type_map.get(field_def.fieldtype, ('', 0)) | fieldtuple = frappe.db.type_map.get(field_def.fieldtype, ('', 0)) | ||||
fieldtype = fieldtuple[0] | fieldtype = fieldtuple[0] | ||||
@@ -119,4 +125,4 @@ def get_other_fields_meta(meta): | |||||
def get_table_column(doctype, fieldname): | def get_table_column(doctype, fieldname): | ||||
table_columns = frappe.db.get_table_columns_description('tab{}'.format(doctype)) | table_columns = frappe.db.get_table_columns_description('tab{}'.format(doctype)) | ||||
return find(table_columns, lambda d: d.get('name') == fieldname) | |||||
return find(table_columns, lambda d: d.get('name') == fieldname) |