delete records in child table where parent is missing or parent is like

old_par%
This commit is contained in:
Anand Doshi 2012-06-26 12:15:15 +05:30
parent 81fa802e09
commit 68196bc966
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,17 @@
def execute():
"""delete entries of child table having parent like old_par%% or ''"""
import webnotes
res = webnotes.conn.sql("""\
select dt.name from `tabDocType` dt
where ifnull(dt.istable, 0)=1 and
exists (
select * from `tabDocField` df
where df.fieldtype='Table' and
df.options=dt.name
)""")
for r in res:
if r[0]:
webnotes.conn.sql("""\
delete from `tab%s`
where (ifnull(parent, '')='' or parent like "old_par%%") and
ifnull(parenttype, '')!=''""" % r[0])

View File

@ -452,4 +452,9 @@ patch_list = [
'patch_file': 'alter_tabsessions',
'description': "alter tabsessions to change user column definition"
},
{
'patch_module': 'patches.june_2012',
'patch_file': 'delete_old_parent_entries',
'description': "delete entries of child table having parent like old_par%% or ''"
},
]