refactor: postgres version check
This commit is contained in:
parent
445da4319b
commit
4996b8ac7b
1 changed files with 7 additions and 3 deletions
|
|
@ -1,7 +1,9 @@
|
|||
import os
|
||||
import re
|
||||
|
||||
import frappe
|
||||
from frappe.database.db_manager import DbManager
|
||||
from frappe.utils import cint
|
||||
|
||||
|
||||
def setup_database():
|
||||
|
|
@ -13,9 +15,11 @@ def setup_database():
|
|||
root_conn.sql(f"CREATE DATABASE `{frappe.conf.db_name}`")
|
||||
root_conn.sql(f"CREATE user {frappe.conf.db_name} password '{frappe.conf.db_password}'")
|
||||
root_conn.sql("GRANT ALL PRIVILEGES ON DATABASE `{0}` TO {0}".format(frappe.conf.db_name))
|
||||
psql_version = root_conn.sql(f"SELECT VERSION()", as_dict=True)
|
||||
if psql_version and psql_version[0].get("version", "PostgreSQL 14").split()[1] >= "15":
|
||||
root_conn.sql("ALTER DATABASE `{0}` OWNER TO {0}".format(frappe.conf.db_name))
|
||||
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("ALTER DATABASE `{0}` OWNER TO {0}".format(frappe.conf.db_name))
|
||||
root_conn.close()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue