2
0
mirror of https://github.com/frappe/frappe.git synced 2024-06-03 00:10:47 +00:00

refactor: add_column (#24867)

- Skip cache which can be invalid
- Do check at db level
This commit is contained in:
Ankush Menat 2024-02-12 13:15:18 +05:30 committed by GitHub
parent 7b197f1a2b
commit 4350f94616
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 6 deletions

View File

@ -391,13 +391,8 @@ def get_definition(fieldtype, precision=None, length=None):
def add_column(doctype, column_name, fieldtype, precision=None, length=None, default=None, not_null=False):
if column_name in frappe.db.get_table_columns(doctype):
# already exists
return
frappe.db.commit()
query = "alter table `tab{}` add column {} {}".format(
query = "alter table `tab{}` add column if not exists {} {}".format(
doctype,
column_name,
get_definition(fieldtype, precision, length),

View File

@ -76,6 +76,7 @@ class SiteMigration:
"""Complete setup required for site migration"""
frappe.flags.touched_tables = set()
self.touched_tables_file = frappe.get_site_path("touched_tables.json")
frappe.clear_cache()
add_column(doctype="DocType", column_name="migration_hash", fieldtype="Data")
clear_global_cache()