mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-07 18:30:27 +00:00
add the logic about seafevents
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#coding: UTF-8
|
# coding: UTF-8
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
@@ -106,6 +106,7 @@ class DBUpdater(object):
|
|||||||
ccnet_sql = os.path.join(self.sql_dir, 'ccnet.sql')
|
ccnet_sql = os.path.join(self.sql_dir, 'ccnet.sql')
|
||||||
seafile_sql = os.path.join(self.sql_dir, 'seafile.sql')
|
seafile_sql = os.path.join(self.sql_dir, 'seafile.sql')
|
||||||
seahub_sql = os.path.join(self.sql_dir, 'seahub.sql')
|
seahub_sql = os.path.join(self.sql_dir, 'seahub.sql')
|
||||||
|
seafevents_sql = os.path.join(self.sql_dir, 'seafevents.sql')
|
||||||
|
|
||||||
if os.path.exists(ccnet_sql):
|
if os.path.exists(ccnet_sql):
|
||||||
Utils.info('updating ccnet database...')
|
Utils.info('updating ccnet database...')
|
||||||
@@ -119,6 +120,9 @@ class DBUpdater(object):
|
|||||||
Utils.info('updating seahub database...')
|
Utils.info('updating seahub database...')
|
||||||
self.update_seahub_sql(seahub_sql)
|
self.update_seahub_sql(seahub_sql)
|
||||||
|
|
||||||
|
if os.path.exists(seafevents_sql):
|
||||||
|
self.update_seafevents_sql(seafevents_sql)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_ccnet_mysql_info(version):
|
def get_ccnet_mysql_info(version):
|
||||||
if version > '5.0.0':
|
if version > '5.0.0':
|
||||||
@@ -231,6 +235,9 @@ class DBUpdater(object):
|
|||||||
def update_seahub_sql(self, seahub_sql):
|
def update_seahub_sql(self, seahub_sql):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def update_seafevents_sql(self, seafevents_sql):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
class CcnetSQLiteDB(object):
|
class CcnetSQLiteDB(object):
|
||||||
def __init__(self, ccnet_dir):
|
def __init__(self, ccnet_dir):
|
||||||
self.ccnet_dir = ccnet_dir
|
self.ccnet_dir = ccnet_dir
|
||||||
@@ -254,6 +261,10 @@ class SQLiteDBUpdater(DBUpdater):
|
|||||||
self.ccnet_db = CcnetSQLiteDB(env_mgr.ccnet_dir)
|
self.ccnet_db = CcnetSQLiteDB(env_mgr.ccnet_dir)
|
||||||
self.seafile_db = os.path.join(env_mgr.seafile_dir, 'seafile.db')
|
self.seafile_db = os.path.join(env_mgr.seafile_dir, 'seafile.db')
|
||||||
self.seahub_db = os.path.join(env_mgr.top_dir, 'seahub.db')
|
self.seahub_db = os.path.join(env_mgr.top_dir, 'seahub.db')
|
||||||
|
self.seafevents_db = os.path.join(env_mgr.top_dir, 'seafevents.db')
|
||||||
|
|
||||||
|
def is_pro(self):
|
||||||
|
return os.path.exists(self.seafevents_db)
|
||||||
|
|
||||||
def update_db(self):
|
def update_db(self):
|
||||||
super(SQLiteDBUpdater, self).update_db()
|
super(SQLiteDBUpdater, self).update_db()
|
||||||
@@ -282,6 +293,11 @@ class SQLiteDBUpdater(DBUpdater):
|
|||||||
def update_seahub_sql(self, sql_path):
|
def update_seahub_sql(self, sql_path):
|
||||||
self.apply_sqls(self.seahub_db, sql_path)
|
self.apply_sqls(self.seahub_db, sql_path)
|
||||||
|
|
||||||
|
def update_seafevents_sql(self, sql_path):
|
||||||
|
if self.is_pro():
|
||||||
|
Utils.info('updating seafevents database...')
|
||||||
|
self.apply_sqls(self.seafevents_db, sql_path)
|
||||||
|
|
||||||
|
|
||||||
class MySQLDBUpdater(DBUpdater):
|
class MySQLDBUpdater(DBUpdater):
|
||||||
def __init__(self, version, ccnet_db_info, seafile_db_info, seahub_db_info):
|
def __init__(self, version, ccnet_db_info, seafile_db_info, seahub_db_info):
|
||||||
@@ -299,6 +315,11 @@ class MySQLDBUpdater(DBUpdater):
|
|||||||
def update_seahub_sql(self, seahub_sql):
|
def update_seahub_sql(self, seahub_sql):
|
||||||
self.apply_sqls(self.seahub_db_info, seahub_sql)
|
self.apply_sqls(self.seahub_db_info, seahub_sql)
|
||||||
|
|
||||||
|
def update_seafevents_sql(self, seafevents_sql):
|
||||||
|
if self.is_pro(self.seahub_db_info):
|
||||||
|
Utils.info('updating seafevents database...')
|
||||||
|
self.apply_sqls(self.seahub_db_info, seahub_sql)
|
||||||
|
|
||||||
def get_conn(self, info):
|
def get_conn(self, info):
|
||||||
kw = dict(
|
kw = dict(
|
||||||
user=info.username,
|
user=info.username,
|
||||||
@@ -347,6 +368,14 @@ class MySQLDBUpdater(DBUpdater):
|
|||||||
else:
|
else:
|
||||||
self.execute_sql(conn, line)
|
self.execute_sql(conn, line)
|
||||||
|
|
||||||
|
def is_pro(self, info):
|
||||||
|
conn = self.get_conn(info)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
text = "select count(1) from information_schema.tables where table_schema=%s and table_name=%s"
|
||||||
|
cursor.execute(text, (info.db, 'Event'))
|
||||||
|
res = cursor.fetchone()
|
||||||
|
return res[0] == 1
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
skipdb = os.environ.get('SEAFILE_SKIP_DB_UPGRADE', '').lower()
|
skipdb = os.environ.get('SEAFILE_SKIP_DB_UPGRADE', '').lower()
|
||||||
|
4
scripts/upgrade/sql/6.3.0/mysql/seafevents.sql
Normal file
4
scripts/upgrade/sql/6.3.0/mysql/seafevents.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE Event ADD INDEX `ix_event_timestamp` (`timestamp`);
|
||||||
|
ALTER TABLE FileAudit ADD INDEX `ix_FileAudit_timestamp` (`timestamp`);
|
||||||
|
ALTER TABLE FileUpdate ADD INDEX `ix_FileUpdate_timestamp` (`timestamp`);
|
||||||
|
ALTER TABLE UserTrafficStat ADD INDEX `ix_UserTrafficStat_month` (`month`);
|
4
scripts/upgrade/sql/6.3.0/sqlite3/seafevents.sql
Normal file
4
scripts/upgrade/sql/6.3.0/sqlite3/seafevents.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
CREATE INDEX IF NOT EXISTS ix_event_timestamp ON Event (timestamp);
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_FileAudit_timestamp ON FileAudit (timestamp);
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_FileUpdate_timestamp ON FileUpdate (timestamp);
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_UserTrafficStat_month ON UserTrafficStat (month);
|
Reference in New Issue
Block a user