fix: Replace NULL values with zero having data type as INT, FLOAT or DECIMAL

This commit is contained in:
deepeshgarg007 2019-03-18 08:47:17 +05:30
parent 26197ee29e
commit fb49819cd7
2 changed files with 23 additions and 0 deletions

View file

@ -236,3 +236,4 @@ execute:frappe.delete_doc("Page", "modules", ignore_missing=True)
frappe.patches.v11_0.set_default_letter_head_source
frappe.patches.v12_0.setup_comments_from_communications
frappe.patches.v12_0.init_desk_settings #11-03-2019
frappe.patches.v12_0.replace_null_values_in_tables

View file

@ -0,0 +1,22 @@
import frappe
def execute():
fields = frappe.db.sql("""
SELECT COLUMN_NAME , TABLE_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE DATA_TYPE IN ('INT', 'FLOAT', 'DECIMAL') AND IS_NULLABLE = 'YES'
""", as_dict=1)
update_column_table_map = {}
for field in fields:
update_column_table_map.setdefault(field.TABLE_NAME, [])
if field.TABLE_NAME not in ['tabDocPerm', 'tabCustom Field', 'tabWebsite Route Permission']:
update_column_table_map[field.TABLE_NAME].append(str(field.COLUMN_NAME)+"=COALESCE("+str(field.COLUMN_NAME)+", 0)")
for table in frappe.db.get_tables():
if update_column_table_map.get(table):
frappe.db.sql("""UPDATE `{table}` SET {columns}"""
.format(table=table, columns=",".join(update_column_table_map.get(table))))