Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: file changes for v15 migration #4

Open
wants to merge 1 commit into
base: v15-assureai
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions frappe/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,14 @@ def _delete_modules(modules: list[str], dry_run: bool) -> list[str]:

def _delete_linked_documents(module_name: str, doctype_linkfield_map: dict[str, str], dry_run: bool) -> None:
"""Deleted all records linked with module def"""
for doctype, fieldname in doctype_linkfield_map.items():
for record in frappe.get_all(doctype, filters={fieldname: module_name}, pluck="name"):
print(f"* removing {doctype} '{record}'...")
if not dry_run:
frappe.delete_doc(doctype, record, ignore_on_trash=True, force=True)

try:
for doctype, fieldname in doctype_linkfield_map.items():
for record in frappe.get_all(doctype, filters={fieldname: module_name}, pluck="name"):
print(f"* removing {doctype} '{record}'...")
if not dry_run:
frappe.delete_doc(doctype, record, ignore_on_trash=True, force=True)
except Exception:
print("Error while deleting linked documents")

def _get_module_linked_doctype_field_map() -> dict[str, str]:
"""Get all the doctypes which have module linked with them.
Expand Down Expand Up @@ -482,12 +484,14 @@ def _get_module_linked_doctype_field_map() -> dict[str, str]:


def _delete_doctypes(doctypes: list[str], dry_run: bool) -> None:
for doctype in set(doctypes):
print(f"* dropping Table for '{doctype}'...")
if not dry_run:
frappe.delete_doc("DocType", doctype, ignore_on_trash=True, force=True)
frappe.db.sql_ddl(f"DROP TABLE IF EXISTS `tab{doctype}`")

try:
for doctype in set(doctypes):
print(f"* dropping Table for '{doctype}'...")
if not dry_run:
frappe.delete_doc("DocType", doctype, ignore_on_trash=True, force=True)
frappe.db.sql_ddl(f"DROP TABLE IF EXISTS `tab{doctype}`")
except Exception:
print("Error while deleting doctypes")

def post_install(rebuild_website=False):
from frappe.website.utils import clear_website_cache
Expand Down
40 changes: 21 additions & 19 deletions frappe/model/delete_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,29 @@ def update_naming_series(doc):


def delete_from_table(doctype: str, name: str, ignore_doctypes: list[str], doc):
if doctype != "DocType" and doctype == name:
frappe.db.delete("Singles", {"doctype": name})
else:
frappe.db.delete(doctype, {"name": name})
if doc:
child_doctypes = [
d.options for d in doc.meta.get_table_fields() if frappe.get_meta(d.options).is_virtual == 0
]

else:
child_doctypes = frappe.get_all(
"DocField",
fields="options",
filters={"fieldtype": ["in", frappe.model.table_fields], "parent": doctype},
pluck="options",
)
try:
if doctype != "DocType" and doctype == name:
frappe.db.delete("Singles", {"doctype": name})
else:
frappe.db.delete(doctype, {"name": name})
if doc:
child_doctypes = [
d.options for d in doc.meta.get_table_fields() if frappe.get_meta(d.options).is_virtual == 0
]

child_doctypes_to_delete = set(child_doctypes) - set(ignore_doctypes)
for child_doctype in child_doctypes_to_delete:
frappe.db.delete(child_doctype, {"parenttype": doctype, "parent": name})
else:
child_doctypes = frappe.get_all(
"DocField",
fields="options",
filters={"fieldtype": ["in", frappe.model.table_fields], "parent": doctype},
pluck="options",
)

child_doctypes_to_delete = set(child_doctypes) - set(ignore_doctypes)
for child_doctype in child_doctypes_to_delete:
frappe.db.delete(child_doctype, {"parenttype": doctype, "parent": name})
except Exception:
print("Error deleting from table", doctype, name)

def update_flags(doc, flags=None, ignore_permissions=False):
if ignore_permissions:
Expand Down
2 changes: 0 additions & 2 deletions frappe/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ execute:frappe.delete_doc_if_exists('Page', 'workspace')
execute:frappe.delete_doc_if_exists('Page', 'dashboard', force=1)
frappe.core.doctype.page.patches.drop_unused_pages
frappe.patches.v13_0.remove_chat
frappe.patches.v13_0.rename_desk_page_to_workspace # 02.02.2021
frappe.patches.v13_0.delete_package_publish_tool
frappe.patches.v13_0.rename_list_view_setting_to_list_view_settings
frappe.patches.v13_0.remove_twilio_settings
Expand All @@ -188,7 +187,6 @@ frappe.patches.v14_0.reset_creation_datetime
frappe.patches.v14_0.remove_is_first_startup
frappe.patches.v14_0.clear_long_pending_stale_logs
frappe.patches.v14_0.log_settings_migration
frappe.patches.v14_0.setup_likes_from_feedback
frappe.patches.v14_0.update_webforms
frappe.patches.v14_0.delete_payment_gateways
frappe.patches.v15_0.remove_event_streaming
Expand Down