fix: postgres uses double quotes for identifiers, especially if case-sensitive
(single quotes would force it to lowercase) Also unconditionally create a new user while running tests - we're gonna be dropping the test site Don't pass a `None` value to bench cli Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
265c0b0e01
commit
9b18289b33
2 changed files with 17 additions and 18 deletions
|
|
@ -10,22 +10,22 @@ def setup_database():
|
|||
root_conn = get_root_connection()
|
||||
root_conn.commit()
|
||||
root_conn.sql("end")
|
||||
root_conn.sql(f"DROP DATABASE IF EXISTS `{frappe.conf.db_name}`")
|
||||
root_conn.sql(f'DROP DATABASE IF EXISTS "{frappe.conf.db_name}"')
|
||||
|
||||
# If user exists, just update password
|
||||
if root_conn.sql(f"SELECT 1 FROM pg_roles WHERE rolname='{frappe.conf.db_user}'"):
|
||||
root_conn.sql(f"ALTER USER {frappe.conf.db_user} WITH PASSWORD '{frappe.conf.db_password}'")
|
||||
root_conn.sql(f"ALTER USER \"{frappe.conf.db_user}\" WITH PASSWORD '{frappe.conf.db_password}'")
|
||||
else:
|
||||
root_conn.sql(f"CREATE USER {frappe.conf.db_user} WITH PASSWORD '{frappe.conf.db_password}'")
|
||||
root_conn.sql(f"CREATE DATABASE `{frappe.conf.db_name}`")
|
||||
root_conn.sql(f"CREATE USER \"{frappe.conf.db_user}\" WITH PASSWORD '{frappe.conf.db_password}'")
|
||||
root_conn.sql(f'CREATE DATABASE "{frappe.conf.db_name}"')
|
||||
root_conn.sql(
|
||||
f"GRANT ALL PRIVILEGES ON DATABASE `{frappe.conf.db_name}` TO {frappe.conf.db_user}"
|
||||
f'GRANT ALL PRIVILEGES ON DATABASE "{frappe.conf.db_name}" TO "{frappe.conf.db_user}"'
|
||||
)
|
||||
if psql_version := root_conn.sql("SELECT VERSION()", as_dict=True):
|
||||
version_string = psql_version[0].get("version") or "PostgreSQL 14"
|
||||
major_version = cint(re.split(r"[\w\.]", version_string)[1])
|
||||
if major_version > 15:
|
||||
root_conn.sql(f"ALTER DATABASE `{frappe.conf.db_name}` OWNER TO {frappe.conf.db_user}")
|
||||
root_conn.sql(f'ALTER DATABASE "{frappe.conf.db_name}" OWNER TO "{frappe.conf.db_user}"')
|
||||
root_conn.close()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -520,7 +520,7 @@ class TestCommands(BaseTestCommands):
|
|||
kwargs = {
|
||||
"new_site": site,
|
||||
"admin_password": frappe.conf.admin_password,
|
||||
"root_password": frappe.conf.root_password,
|
||||
"root_password": frappe.conf.root_password or "",
|
||||
"db_type": frappe.conf.db_type,
|
||||
"db_user": user,
|
||||
"db_password": password,
|
||||
|
|
@ -549,19 +549,18 @@ class TestCommands(BaseTestCommands):
|
|||
|
||||
def test_existing_db_username(self):
|
||||
site = frappe.generate_hash()
|
||||
if (user := frappe.conf.db_user) is None:
|
||||
user = "".join(secrets.choice(string.ascii_letters) for _ in range(8))
|
||||
if frappe.conf.db_type == "mariadb":
|
||||
from frappe.database.mariadb.setup_db import get_root_connection
|
||||
user = "".join(secrets.choice(string.ascii_letters) for _ in range(8))
|
||||
if frappe.conf.db_type == "mariadb":
|
||||
from frappe.database.mariadb.setup_db import get_root_connection
|
||||
|
||||
root_conn = get_root_connection()
|
||||
root_conn.sql(f"CREATE USER '{user}'@'localhost'")
|
||||
else:
|
||||
from frappe.database.postgres.setup_db import get_root_connection
|
||||
root_conn = get_root_connection()
|
||||
root_conn.sql(f"CREATE USER '{user}'@'localhost'")
|
||||
else:
|
||||
from frappe.database.postgres.setup_db import get_root_connection
|
||||
|
||||
root_conn = get_root_connection()
|
||||
root_conn.sql(f"CREATE USER {user}")
|
||||
password = frappe.conf.db_password or frappe.generate_hash()
|
||||
root_conn = get_root_connection()
|
||||
root_conn.sql(f"CREATE USER {user}")
|
||||
password = frappe.generate_hash()
|
||||
kwargs = {
|
||||
"new_site": site,
|
||||
"admin_password": frappe.conf.admin_password,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue