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

fix: show warning for pending migrations (backport #25908) #25909

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions frappe/core/doctype/doctype/doctype.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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