diff --git a/changai/changai/api/v2/schema_utils.py b/changai/changai/api/v2/schema_utils.py index 3756a91..4dd5d23 100644 --- a/changai/changai/api/v2/schema_utils.py +++ b/changai/changai/api/v2/schema_utils.py @@ -184,45 +184,42 @@ def validate_sql_schema(sql: str, dialect: str = "mysql") -> dict: ] -def is_doctype_schema_changed(doc,last_sync): - doctype_modified = frappe.db.get_value( - "DocType", - doc, - "modified" - ) - custom_field_modified = frappe.db.get_value( - "Custom Field", - {"dt": doc}, - "max(modified)" - ) - property_setter_modified = frappe.db.get_value( - "Property Setter", - {"doc_type": doc}, - "max(modified)" - ) - latest = max( - [ - d for d in [ - doctype_modified, - custom_field_modified, - property_setter_modified - ] if d - ], - default=None - ) - if latest and last_sync and bool(getdate(latest) > getdate(last_sync)): - return True - return False +def is_doctype_schema_changed(doc, last_sync): + from frappe.utils import get_datetime + + doctype_modified = frappe.db.get_value("DocType", doc, "modified") + + custom_field_modified = frappe.db.sql( + "SELECT MAX(modified) FROM `tabCustom Field` WHERE dt = %s", + doc + )[0][0] + + property_setter_modified = frappe.db.sql( + "SELECT MAX(modified) FROM `tabProperty Setter` WHERE doc_type = %s", + doc + )[0][0] + + candidates = [ + get_datetime(d) for d in [ + doctype_modified, + custom_field_modified, + property_setter_modified + ] if d + ] + + latest = max(candidates, default=None) + return bool(latest and last_sync and latest > get_datetime(last_sync)) def is_master_data_changed(last_sync): + from frappe.utils import get_datetime + for doc in MASTER_DOCTYPES: - latest_modified = frappe.db.get_value( - doc, - {}, - "max(modified)" - ) - return bool(getdate(latest_modified) > getdate(last_sync)) if latest_modified and last_sync else False + latest_modified = frappe.db.sql( + f"SELECT MAX(modified) FROM `tab{doc}`" + )[0][0] + if latest_modified and last_sync and get_datetime(latest_modified) > get_datetime(last_sync): + return True return False diff --git a/pyproject.toml b/pyproject.toml index 63b4126..d309e71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,18 +1,18 @@ [project] name = "changai" authors = [ - { name = "ERpGulf", email = "support@erpgulf.com"} + { name = "ERPGulf", email = "support@erpgulf.com"} ] description = "ChangAI" readme = "README.md" dynamic = ["version"] dependencies = [ "cffi", - "openai>=1.64.0,<2.0.0", - "anthropic>=0.79.0,<1.0.0", - "google-genai<2.0.0", + "openai", + "anthropic", + "google-genai", "google-auth", - "google-cloud-aiplatform<2.0.0", + "google-cloud-aiplatform", "langchain-core", "langchain-community", "langchain-huggingface", @@ -20,7 +20,7 @@ dependencies = [ "symspellpy", "transformers", "sentence-transformers", - "faiss-cpu<2.0.0", + "faiss-cpu", "numpy", "sqlglot", "boto3",