浏览代码

fix: dont auto drop manually created index on text types (#15739)

version-14
Ankush Menat 3 年前
committed by GitHub
父节点
当前提交
e5eca8232f
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 9 次插入3 次删除
  1. +2
    -2
      frappe/database/schema.py
  2. +7
    -1
      frappe/tests/test_db_update.py

+ 2
- 2
frappe/database/schema.py 查看文件

@@ -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')):


+ 7
- 1
frappe/tests/test_db_update.py 查看文件

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

正在加载...
取消
保存