mirror of
https://github.com/haiwen/seahub.git
synced 2025-04-28 03:10:45 +00:00
UserActivity remove ForeignKey (#7125)
* UserActivity remove ForeignKey * UserActivity clean_db_records
This commit is contained in:
parent
6a514d87eb
commit
49cd661163
@ -49,8 +49,7 @@ CREATE TABLE IF NOT EXISTS `UserActivity` (
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `activity_id` (`activity_id`),
|
||||
KEY `ix_UserActivity_timestamp` (`timestamp`),
|
||||
KEY `idx_username_timestamp` (`username`,`timestamp`),
|
||||
CONSTRAINT `useractivity_ibfk_1` FOREIGN KEY (`activity_id`) REFERENCES `Activity` (`id`) ON DELETE CASCADE
|
||||
KEY `idx_username_timestamp` (`username`,`timestamp`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `FileHistory` (
|
||||
|
@ -2,7 +2,6 @@ ALTER TABLE UserActivity DROP FOREIGN KEY `UserActivity_ibfk_1`;
|
||||
ALTER TABLE Activity CHANGE id id BIGINT(20) AUTO_INCREMENT;
|
||||
ALTER TABLE UserActivity CHANGE id id BIGINT(20) AUTO_INCREMENT;
|
||||
ALTER TABLE UserActivity CHANGE activity_id activity_id BIGINT(20);
|
||||
ALTER TABLE UserActivity ADD CONSTRAINT `UserActivity_ibfk_1` FOREIGN KEY (`activity_id`) REFERENCES `Activity` (`id`) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE FileHistory CHANGE id id BIGINT(20) AUTO_INCREMENT;
|
||||
ALTER TABLE FileAudit CHANGE eid eid BIGINT(20) AUTO_INCREMENT;
|
||||
|
@ -19,6 +19,7 @@ class Command(BaseCommand):
|
||||
clean_sql5 = "DELETE FROM FileHistory WHERE to_days(now()) - to_days(timestamp) > 90"
|
||||
clean_sql6 = "DELETE FROM PermAudit WHERE to_days(now()) - to_days(timestamp) > 90"
|
||||
clean_sql7 = "DELETE FROM FileTrash WHERE to_days(now()) - to_days(delete_time) > 90"
|
||||
clean_sql8 = "DELETE FROM UserActivity WHERE to_days(now()) - to_days(timestamp) > 90"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
logger.debug('Start clean database records.')
|
||||
@ -37,6 +38,7 @@ class Command(BaseCommand):
|
||||
cursor.execute(self.clean_sql5)
|
||||
cursor.execute(self.clean_sql6)
|
||||
cursor.execute(self.clean_sql7)
|
||||
cursor.execute(self.clean_sql8)
|
||||
except Exception as e:
|
||||
logger.error('Failed to clean database records, error: %s.' % e)
|
||||
self.stderr.write('[%s] Failed to clean database records, error: %s.' % (datetime.now(), e))
|
||||
|
Loading…
Reference in New Issue
Block a user