-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimezone.py
More file actions
40 lines (31 loc) · 1.38 KB
/
Copy pathtimezone.py
File metadata and controls
40 lines (31 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import asyncio
from datetime import timezone
from database import DatabaseManager
from config import MEMBERS_COLLECTION
async def migrate_last_increment_to_utc(db: DatabaseManager):
"""
Finds all members with a naive `last_increment` datetime and updates it to UTC-aware.
"""
collection = db.db[MEMBERS_COLLECTION]
cursor = collection.find({})
async for doc in cursor:
guild_id = doc.get("guild_id")
members = doc.get("members", {})
updates = {}
for member_id, member_data in members.items():
profile = member_data.get("profile_data", {})
last_increment = profile.get("last_increment")
if last_increment and last_increment.tzinfo is None:
# Convert to UTC-aware
aware_dt = last_increment.replace(tzinfo=timezone.utc)
updates[f"members.{member_id}.profile_data.last_increment"] = aware_dt
if updates:
await collection.update_one(
{"guild_id": guild_id},
{"$set": updates}
)
print(f"[Migration] Updated {len(updates)} members in guild {guild_id} to UTC-aware datetimes.")
if __name__ == "__main__":
from config import MONGO_URI, DB_NAME
db_manager = DatabaseManager(MONGO_URI, DB_NAME)
asyncio.run(migrate_last_increment_to_utc(db_manager))