Ver a proveniência

[fix] alter column for int, float not null

version-14
Anand Doshi há 9 anos
ascendente
cometimento
bcf43d51aa
2 ficheiros alterados com 15 adições e 1 eliminações
  1. +1
    -1
      frappe/patches.txt
  2. +14
    -0
      frappe/patches/v6_9/int_float_not_null.py

+ 1
- 1
frappe/patches.txt Ver ficheiro

@@ -18,7 +18,7 @@ execute:frappe.db.sql("delete from `tabDocField` where parent='0'")
frappe.patches.v4_0.change_varchar_length frappe.patches.v4_0.change_varchar_length
frappe.patches.v6_4.reduce_varchar_length frappe.patches.v6_4.reduce_varchar_length
frappe.patches.v5_2.change_checks_to_not_null frappe.patches.v5_2.change_checks_to_not_null
frappe.patches.v6_9.int_float_not_null
frappe.patches.v6_9.int_float_not_null #2015-11-25
frappe.patches.v5_0.v4_to_v5 frappe.patches.v5_0.v4_to_v5


frappe.patches.v5_0.remove_shopping_cart_app frappe.patches.v5_0.remove_shopping_cart_app


+ 14
- 0
frappe/patches/v6_9/int_float_not_null.py Ver ficheiro

@@ -1,9 +1,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cint, flt


def execute(): def execute():
for doctype in frappe.get_all("DocType", filters={"issingle": 0}): for doctype in frappe.get_all("DocType", filters={"issingle": 0}):
doctype = doctype.name doctype = doctype.name
meta = frappe.get_meta(doctype)


for column in frappe.db.sql("desc `tab{doctype}`".format(doctype=doctype), as_dict=True): for column in frappe.db.sql("desc `tab{doctype}`".format(doctype=doctype), as_dict=True):
fieldname = column["Field"] fieldname = column["Field"]
@@ -14,3 +16,15 @@ def execute():


frappe.db.sql("""update `tab{doctype}` set `{fieldname}`=0 where `{fieldname}` is null"""\ frappe.db.sql("""update `tab{doctype}` set `{fieldname}`=0 where `{fieldname}` is null"""\
.format(doctype=doctype, fieldname=fieldname)) .format(doctype=doctype, fieldname=fieldname))

# alter table
if column["Null"]=='YES':
if not meta.get_field(fieldname):
continue

default = cint(column["Default"]) if column_type.startswith("int") else flt(column["Default"])
frappe.db.sql_ddl("""alter table `tab{doctype}`
change `{fieldname}` `{fieldname}` {column_type} not null default '{default}'""".format(
doctype=doctype, fieldname=fieldname, column_type=column_type, default=default))



Carregando…
Cancelar
Guardar