forked from frappe/frappe
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: remove implicit primary key from logs (frappe#22209)
- Loading branch information
Showing
9 changed files
with
74 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import frappe | ||
from frappe.model.naming import is_autoincremented | ||
|
||
possible_log_types = ( | ||
"Version", | ||
"Error Log", | ||
"Scheduled Job Log", | ||
"Event Sync Log", | ||
"Event Update Log", | ||
"Access Log", | ||
"View Log", | ||
"Activity Log", | ||
"Energy Point Log", | ||
"Notification Log", | ||
"Email Queue", | ||
"DocShare", | ||
"Document Follow", | ||
"Console Log", | ||
) | ||
|
||
|
||
def execute(): | ||
"""Few doctypes had int PKs even though schema didn't mention them, this requires detecting it | ||
at runtime which is prone to bugs and adds unnecessary overhead. | ||
This patch converts them back to varchar. | ||
""" | ||
for doctype in possible_log_types: | ||
if _is_implicit_int_pk(doctype) and not is_autoincremented(doctype): | ||
frappe.db.change_column_type( | ||
doctype, | ||
"name", | ||
type=f"varchar({frappe.db.VARCHAR_LEN})", | ||
nullable=True, | ||
) | ||
|
||
|
||
def _is_implicit_int_pk(doctype: str) -> bool: | ||
query = f"""select data_type FROM information_schema.columns where column_name = 'name' and table_name = 'tab{doctype}'""" | ||
values = () | ||
if frappe.db.db_type == "mariadb": | ||
query += " and table_schema = %s" | ||
values = (frappe.db.db_name,) | ||
|
||
col_type = frappe.db.sql(query, values) | ||
return bool(col_type and col_type[0][0] == "bigint") |