瀏覽代碼

[fix] alter column for int, float not null

version-14
Anand Doshi 9 年之前
父節點
當前提交
bcf43d51aa
共有 2 個文件被更改,包括 15 次插入1 次删除
  1. +1
    -1
      frappe/patches.txt
  2. +14
    -0
      frappe/patches/v6_9/int_float_not_null.py

+ 1
- 1
frappe/patches.txt 查看文件

@@ -18,7 +18,7 @@ execute:frappe.db.sql("delete from `tabDocField` where parent='0'")
frappe.patches.v4_0.change_varchar_length
frappe.patches.v6_4.reduce_varchar_length
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.remove_shopping_cart_app


+ 14
- 0
frappe/patches/v6_9/int_float_not_null.py 查看文件

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

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

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

frappe.db.sql("""update `tab{doctype}` set `{fieldname}`=0 where `{fieldname}` is null"""\
.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))



Loading…
取消
儲存