mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-06 17:33:18 +00:00
fix db_update_helper (#8089)
This commit is contained in:
@@ -135,97 +135,35 @@ class DBUpdater(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_ccnet_mysql_info(version):
|
def get_ccnet_mysql_info(version):
|
||||||
config_path = env_mgr.central_config_dir
|
host = os.environ.get('SEAFILE_MYSQL_DB_HOST', 'db')
|
||||||
seafile_conf = os.path.join(config_path, 'seafile.conf')
|
port = os.environ.get('SEAFILE_MYSQL_DB_PORT', 3306)
|
||||||
defaults = {
|
username = os.environ.get('SEAFILE_MYSQL_DB_USER', 'seafile')
|
||||||
'HOST': '127.0.0.1',
|
password = os.environ.get('SEAFILE_MYSQL_DB_PASSWORD')
|
||||||
'PORT': '3306',
|
db = os.environ.get('SEAFILE_MYSQL_DB_CCNET_DB_NAME', 'ccnet_db')
|
||||||
'UNIX_SOCKET': '',
|
|
||||||
}
|
info = MySQLDBInfo(host, int(port), username, password, db)
|
||||||
|
|
||||||
config = Utils.read_config(seafile_conf, defaults)
|
|
||||||
db_section = 'database'
|
|
||||||
|
|
||||||
if not config.has_section(db_section):
|
|
||||||
return None
|
|
||||||
|
|
||||||
type = config.get(db_section, 'type')
|
|
||||||
if type != 'mysql':
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
host = config.get(db_section, 'host')
|
|
||||||
port = config.getint(db_section, 'port')
|
|
||||||
username = config.get(db_section, 'user')
|
|
||||||
password = config.get(db_section, 'password')
|
|
||||||
db = os.environ.get('SEAFILE_MYSQL_DB_CCNET_DB_NAME', '') or 'ccnet_db'
|
|
||||||
unix_socket = config.get(db_section, 'UNIX_SOCKET')
|
|
||||||
except configparser.NoOptionError as e:
|
|
||||||
Utils.error('Database config in seafile.conf is invalid: %s' % e)
|
|
||||||
|
|
||||||
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_seafile_mysql_info(version):
|
def get_seafile_mysql_info(version):
|
||||||
config_path = env_mgr.central_config_dir
|
host = os.environ.get('SEAFILE_MYSQL_DB_HOST', 'db')
|
||||||
seafile_conf = os.path.join(config_path, 'seafile.conf')
|
port = os.environ.get('SEAFILE_MYSQL_DB_PORT', 3306)
|
||||||
defaults = {
|
username = os.environ.get('SEAFILE_MYSQL_DB_USER', 'seafile')
|
||||||
'HOST': '127.0.0.1',
|
password = os.environ.get('SEAFILE_MYSQL_DB_PASSWORD')
|
||||||
'PORT': '3306',
|
db = os.environ.get('SEAFILE_MYSQL_DB_SEAFILE_DB_NAME', 'seafile_db')
|
||||||
'UNIX_SOCKET': '',
|
|
||||||
}
|
|
||||||
config = Utils.read_config(seafile_conf, defaults)
|
|
||||||
db_section = 'database'
|
|
||||||
|
|
||||||
if not config.has_section(db_section):
|
info = MySQLDBInfo(host, int(port), username, password, db)
|
||||||
return None
|
|
||||||
|
|
||||||
type = config.get(db_section, 'type')
|
|
||||||
if type != 'mysql':
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
host = config.get(db_section, 'host')
|
|
||||||
port = config.getint(db_section, 'port')
|
|
||||||
username = config.get(db_section, 'user')
|
|
||||||
password = config.get(db_section, 'password')
|
|
||||||
db = config.get(db_section, 'db_name')
|
|
||||||
unix_socket = config.get(db_section, 'unix_socket')
|
|
||||||
except configparser.NoOptionError as e:
|
|
||||||
Utils.error('Database config in seafile.conf is invalid: %s' % e)
|
|
||||||
|
|
||||||
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_seahub_mysql_info():
|
def get_seahub_mysql_info():
|
||||||
sys.path.insert(0, env_mgr.top_dir)
|
host = os.environ.get('SEAFILE_MYSQL_DB_HOST', 'db')
|
||||||
if env_mgr.central_config_dir:
|
port = os.environ.get('SEAFILE_MYSQL_DB_PORT', 3306)
|
||||||
sys.path.insert(0, env_mgr.central_config_dir)
|
username = os.environ.get('SEAFILE_MYSQL_DB_USER', 'seafile')
|
||||||
try:
|
password = os.environ.get('SEAFILE_MYSQL_DB_PASSWORD')
|
||||||
import seahub_settings # pylint: disable=F0401
|
db = os.environ.get('SEAFILE_MYSQL_DB_SEAHUB_DB_NAME', 'seahub_db')
|
||||||
except ImportError as e:
|
|
||||||
Utils.error('Failed to import seahub_settings.py: %s' % e)
|
|
||||||
|
|
||||||
if not hasattr(seahub_settings, 'DATABASES'):
|
info = MySQLDBInfo(host, int(port), username, password, db)
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
d = seahub_settings.DATABASES['default']
|
|
||||||
if d['ENGINE'] != 'django.db.backends.mysql':
|
|
||||||
return None
|
|
||||||
|
|
||||||
host = d.get('HOST', '127.0.0.1')
|
|
||||||
port = int(d.get('PORT', 3306))
|
|
||||||
username = d['USER']
|
|
||||||
password = d['PASSWORD']
|
|
||||||
db = d['NAME']
|
|
||||||
unix_socket = host if host.startswith('/') else None
|
|
||||||
except KeyError:
|
|
||||||
Utils.error('Database config in seahub_settings.py is invalid: %s' % e)
|
|
||||||
|
|
||||||
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def update_ccnet_sql(self, ccnet_sql):
|
def update_ccnet_sql(self, ccnet_sql):
|
||||||
|
Reference in New Issue
Block a user