Skip to content

Commit

Permalink
fix: show warning for pending migrations (#25908) (#25909)
Browse files Browse the repository at this point in the history
* Revert "fix: limit title length on form (#25880)"

This reverts commit 28177c8.

* fix: show warning for pending migrations

(cherry picked from commit f6d0039)

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Apr 11, 2024
1 parent 2751be3 commit 026514e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions frappe/core/doctype/doctype/doctype.js
Expand Up @@ -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) {
Expand Down
21 changes: 20 additions & 1 deletion frappe/core/doctype/doctype/doctype.py
Expand Up @@ -6,6 +6,7 @@
import os
import re
import shutil
from pathlib import Path
from typing import TYPE_CHECKING, Union

import frappe
Expand All @@ -32,7 +33,7 @@
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:
Expand Down Expand Up @@ -1015,6 +1016,24 @@ def validate_name(self, name=None):

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."""
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/ui/page.html
Expand Up @@ -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>
Expand Down

0 comments on commit 026514e

Please sign in to comment.