fix: show warning for pending migrations (#25908)

* Revert "fix: limit title length on form (#25880)"

This reverts commit 28177c8574.

* fix: show warning for pending migrations
This commit is contained in:
Ankush Menat 2024-04-11 11:51:40 +05:30 committed by GitHub
parent 38979111d4
commit f6d003963c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 2 deletions

View file

@ -6,6 +6,7 @@ frappe.ui.form.on("DocType", {
if (frm.is_new() && !frm.doc?.fields) {
frappe.listview_settings["DocType"].new_doctype_dialog();
}
frm.call("check_pending_migration");
},
before_save: function (frm) {

View file

@ -6,6 +6,7 @@ import json
import os
import re
import shutil
from pathlib import Path
from typing import TYPE_CHECKING, Union
import frappe
@ -32,7 +33,7 @@ from frappe.modules import get_doc_path, make_boilerplate
from frappe.modules.import_file import get_file_path
from frappe.permissions import ALL_USER_ROLE, AUTOMATIC_ROLES, SYSTEM_USER_ROLE
from frappe.query_builder.functions import Concat
from frappe.utils import cint, flt, is_a_property, random_string
from frappe.utils import cint, flt, get_datetime, is_a_property, random_string
from frappe.website.utils import clear_cache
if TYPE_CHECKING:
@ -1021,6 +1022,24 @@ class DocType(Document):
validate_route_conflict(self.doctype, self.name)
@frappe.whitelist()
def check_pending_migration(self) -> bool:
"""Checks if all migrations are applied on doctype."""
if self.is_new() or self.custom:
return
file = Path(get_file_path(frappe.scrub(self.module), self.doctype, self.name))
content = json.loads(file.read_text())
if content.get("modified") and get_datetime(self.modified) != get_datetime(content.get("modified")):
frappe.msgprint(
_(
"This doctype has pending migrations, run 'bench migrate' before modifying the doctype to avoid losing changes."
),
alert=True,
indicator="yellow",
)
return True
def validate_series(dt, autoname=None, name=None):
"""Validate if `autoname` property is correctly set."""

View file

@ -17,7 +17,7 @@
</button>
<div class="flex fill-width title-area">
<div>
<div class="flex col-md-8 col-sm-8">
<div class="flex">
<h3 class="ellipsis title-text"></h3>
<span class="indicator-pill whitespace-nowrap"></span>
</div>