Spaces:
Running
Running
| """Patch Frappe's db_manager.py to skip user/database management for external MySQL. | |
| The external MySQL user (db54711) lacks CREATE USER and GRANT privileges. | |
| This patch comments out the specific SQL statements that require those | |
| privileges, leaving the method structure intact. | |
| """ | |
| import os | |
| DB_MANAGER = "apps/frappe/frappe/database/db_manager.py" | |
| if not os.path.exists(DB_MANAGER): | |
| print(f"ERROR: {DB_MANAGER} not found") | |
| exit(1) | |
| with open(DB_MANAGER) as f: | |
| content = f.read() | |
| replacements = [ | |
| # create_user (v15): CREATE USER without IF NOT EXISTS | |
| ("self.db.sql(f\"CREATE USER '{user}'@'{host}'{password_predicate}\")", | |
| "pass # PATCHED: CREATE USER -- skipped (no CREATE USER privilege)"), | |
| # create_user (develop): CREATE USER IF NOT EXISTS | |
| ("self.db.sql(f\"CREATE USER IF NOT EXISTS '{user}'@'{host}'{password_predicate}\")", | |
| "pass # PATCHED: CREATE USER -- skipped (no CREATE USER privilege)"), | |
| # delete_user | |
| ("self.db.sql(f\"DROP USER IF EXISTS '{target}'@'{host}'\")", | |
| "pass # PATCHED: DROP USER -- skipped (no DROP USER privilege)"), | |
| # grant_all_privileges | |
| ("self.db.sql(f\"GRANT {permissions} ON `{target}`.* TO '{user}'@'{host}'\")", | |
| "pass # PATCHED: GRANT -- skipped (no GRANT privilege)"), | |
| # flush_privileges | |
| ("self.db.sql(\"FLUSH PRIVILEGES\")", | |
| "pass # PATCHED: FLUSH PRIVILEGES -- skipped (no FLUSH PRIVILEGE)"), | |
| ] | |
| patched = 0 | |
| for old, new in replacements: | |
| if old in content: | |
| content = content.replace(old, new) | |
| patched += 1 | |
| with open(DB_MANAGER, 'w') as f: | |
| f.write(content) | |
| if patched: | |
| print(f"SUCCESS: Patched {DB_MANAGER} ({patched} SQL statements skipped)") | |
| else: | |
| print(f"WARNING: No patches applied to {DB_MANAGER}") | |