fix: frappe.conf.db_type -> frappe.db.db_type

This commit is contained in:
Rushabh Mehta 2019-05-24 11:44:28 +05:30
parent 4c03f8b31c
commit 1c893e44c0
11 changed files with 18 additions and 17 deletions

View file

@ -129,7 +129,7 @@ class DocType(Document):
link_fieldname, source_fieldname = df.fetch_from.split('.', 1)
link_df = new_meta.get_field(link_fieldname)
if frappe.conf.db_type == 'postgres':
if frappe.db.db_type == 'postgres':
update_query = '''
UPDATE `tab{doctype}`
SET `{fieldname}` = source.`{source_fieldname}`

View file

@ -8,7 +8,7 @@ from __future__ import unicode_literals
def setup_database(force, source_sql=None, verbose=None):
import frappe
if frappe.conf.db_type == 'postgres':
if frappe.db.db_type == 'postgres':
import frappe.database.postgres.setup_db
return frappe.database.postgres.setup_db.setup_database(force, source_sql, verbose)
else:
@ -17,7 +17,7 @@ def setup_database(force, source_sql=None, verbose=None):
def drop_user_and_database(db_name, root_login=None, root_password=None):
import frappe
if frappe.conf.db_type == 'postgres':
if frappe.db.db_type == 'postgres':
pass
else:
import frappe.database.mariadb.setup_db
@ -25,7 +25,7 @@ def drop_user_and_database(db_name, root_login=None, root_password=None):
def get_db(host=None, user=None, password=None, port=None):
import frappe
if frappe.conf.db_type == 'postgres':
if frappe.db.db_type == 'postgres':
import frappe.database.postgres.database
return frappe.database.postgres.database.PostgresDatabase(host, user, password, port=port)
else:
@ -34,7 +34,7 @@ def get_db(host=None, user=None, password=None, port=None):
def setup_help_database(help_db_name):
import frappe
if frappe.conf.db_type == 'postgres':
if frappe.db.db_type == 'postgres':
import frappe.database.postgres.setup_db
return frappe.database.postgres.setup_db.setup_help_database(help_db_name)
else:

View file

@ -178,10 +178,10 @@ class Database(object):
frappe.errprint(("Execution time: {0} sec").format(round(time_end - time_start, 2)))
except Exception as e:
if(frappe.conf.db_type == 'postgres'):
if(frappe.db.db_type == 'postgres'):
self.rollback()
if frappe.conf.db_type == 'mariadb' and self.is_syntax_error(e):
if frappe.db.db_type == 'mariadb' and self.is_syntax_error(e):
frappe.errprint('Syntax error in query:')
frappe.errprint(query)
@ -729,6 +729,7 @@ class Database(object):
def commit(self):
"""Commit current transaction. Calls SQL `COMMIT`."""
self.sql("commit")
frappe.local.rollback_observers = []
self.flush_realtime_log()
enqueue_jobs_after_commit()
@ -910,7 +911,7 @@ class Database(object):
return self.is_missing_column(e) or self.is_missing_table(e)
def multisql(self, sql_dict, values=(), **kwargs):
current_dialect = frappe.conf.db_type or 'mariadb'
current_dialect = frappe.db.db_type or 'mariadb'
query = sql_dict.get(current_dialect)
return self.sql(query, values, **kwargs)

View file

@ -85,7 +85,7 @@ def convert_to_dates(data, timegrain):
def get_unit_function(datefield, timegrain):
unit_function = ''
if timegrain=='Daily':
if frappe.conf.db_type == 'mariadb':
if frappe.db.db_type == 'mariadb':
unit_function = 'dayofyear({})'.format(datefield)
else:
unit_function = 'extract(doy from {datefield})'.format(

View file

@ -24,7 +24,7 @@ def install_db(root_login="root", root_password=None, db_name=None, source_sql=N
db_type=None):
if not db_type:
db_type = frappe.conf.db_type or 'mariadb'
db_type = frappe.db.db_type or 'mariadb'
make_conf(db_name, site_config=site_config, db_type=db_type)

View file

@ -112,7 +112,7 @@ def delete_fields(args_dict, delete=0):
if not fields_need_to_delete:
continue
if frappe.conf.db_type == 'mariadb':
if frappe.db.db_type == 'mariadb':
# mariadb implicitly commits before DDL, make it explicit
frappe.db.commit()
@ -120,6 +120,6 @@ def delete_fields(args_dict, delete=0):
", ".join(["DROP COLUMN `%s`" % f for f in fields_need_to_delete])
frappe.db.sql(query)
if frappe.conf.db_type == 'postgres':
if frappe.db.db_type == 'postgres':
# commit the results to db
frappe.db.commit()

View file

@ -367,7 +367,7 @@ class BaseDocument(object):
def show_unique_validation_message(self, e):
# TODO: Find a better way to extract fieldname
if frappe.conf.db_type != 'postgres':
if frappe.db.db_type != 'postgres':
fieldname = str(e).split("'")[-2]
label = None

View file

@ -30,7 +30,7 @@ def sql(*args, **kwargs):
stack = list(get_current_stack_frames())
if frappe.conf.db_type == 'postgres':
if frappe.db.db_type == 'postgres':
query = frappe.db._cursor.query
else:
query = frappe.db._cursor._executed

View file

@ -178,7 +178,7 @@ class TestReportview(unittest.TestCase):
limit_start=0, limit_page_length=1)
self.assertTrue('creation' in data[0])
if frappe.conf.db_type != 'postgres':
if frappe.db.db_type != 'postgres':
# datediff function does not exist in postgres
data = DatabaseQuery("DocType").execute(fields=["name", "issingle",
"datediff(modified, creation) as date_diff"], limit_start=0, limit_page_length=1)

View file

@ -86,7 +86,7 @@ class TestRecorder(unittest.TestCase):
{'mariadb': 'COMMIT', 'postgres': 'COMMIT'},
]
sql_dialect = frappe.conf.db_type or 'mariadb'
sql_dialect = frappe.db.db_type or 'mariadb'
for query in queries:
frappe.db.sql(query[sql_dialect])

View file

@ -9,7 +9,7 @@ from frappe import _
def get_monthly_results(goal_doctype, goal_field, date_col, filter_str, aggregation = 'sum'):
'''Get monthly aggregation values for given field of doctype'''
# TODO: move to ORM?
if(frappe.conf.db_type == 'postgres'):
if(frappe.db.db_type == 'postgres'):
month_year_format_query = '''to_char("{}", 'MM-YYYY')'''.format(date_col)
else:
month_year_format_query = 'date_format(`{}`, "%m-%Y")'.format(date_col)