Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

CL3 rewritten #181

Closed
wants to merge 24 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
another update to the migrator
  • Loading branch information
tnix100 committed Apr 24, 2023
commit cfcb3aff24263c2faa8ff2884bef31c5d28b6e50
21 changes: 6 additions & 15 deletions src/common/util/migration.py
Original file line number Diff line number Diff line change
@@ -195,7 +195,7 @@ def migrate_from_v1(db):
try:
if username.lower() in lower_usernames:
raise Exception("Duplicate username")
user = {
users[i] = {
"_id": str(username),
"lower_username": str(username.lower()),
"uuid": str(user.get("uuid", uid.uuid())),
@@ -246,6 +246,7 @@ def migrate_from_v1(db):
chat["members"] = list(dict.fromkeys(chat["members"]))
chat["invite_code"] = secrets.token_urlsafe(5)
chat["created"] = int(time.time())
chats[i] = chat
except Exception as e:
logging.error(f"Failed to migrate chat {chat_id}: {str(e)}")
del chats[i]
@@ -301,17 +302,9 @@ def migrate_from_v1(db):
try:
logging.info("Migrating IP bans...")
ip_bans = db.config.find_one({"_id": "IPBanlist"})
for ip_address in ip_bans.get("wildcard", []):
try:
if ip_address == "127.0.0.1":
continue
db.netlog.update_one({"_id": ip_address}, {"$set": {
"banned": True
}})
except Exception as e:
logging.error(f"Failed to migrate IP ban of {ip_address}: {str(e)}")
for username, ip_address in ip_bans.get("users", {}).items():
db.netlog.update_one({"_id": ip_address}, {"$addToSet": {"users": username}})
db.netlog.update_many({"_id": {"$in": ip_bans.get("wildcard", [])}}, {"$set": {
"banned": True
}})
except Exception as e:
logging.error(f"Failed to migrate IP bans: {str(e)}")

@@ -327,8 +320,6 @@ def migrate_from_v1(db):
# Clear unnecessary config items
try:
logging.info("Clearing unnecessary config items...")
for config_name in [config_item["_id"] for config_item in db.config.find({}, projection={"_id": 1})]:
if config_name not in ["filter"]:
db.config.delete_one({"_id": config_name})
db.config.delete_many({"_id": {"$nin": ["filter"]}})
except Exception as e:
logging.error(f"Failed to clear unnecessary config items: {str(e)}")