Spaces:
Running
Running
File size: 1,762 Bytes
dc612db 4eabb91 dc612db 4eabb91 1ff5490 4eabb91 ab17903 4eabb91 ab17903 4eabb91 ab17903 4eabb91 ab17903 4eabb91 dc612db 4eabb91 dc612db 4eabb91 dc612db | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | """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}")
|