Implemented memcached caching
This commit is contained in:
63
migrations/202502092252.py
Normal file
63
migrations/202502092252.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import logging
|
||||
from logging import Logger
|
||||
|
||||
from libbot.utils import config_set, config_delete
|
||||
from mongodb_migrations.base import BaseMigration
|
||||
|
||||
logger: Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Migration(BaseMigration):
|
||||
def upgrade(self):
|
||||
try:
|
||||
config_set(
|
||||
"cache",
|
||||
{
|
||||
"type": None,
|
||||
"memcached": {"uri": "127.0.0.1:11211"},
|
||||
"redis": {"uri": "127.0.0.1:6379"},
|
||||
},
|
||||
*[],
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error(
|
||||
"Could not upgrade the config during migration '%s' due to: %s",
|
||||
__name__,
|
||||
exc,
|
||||
)
|
||||
|
||||
self.db.users.update_many(
|
||||
{"user": {"$exists": True}},
|
||||
{"$rename": {"user": "id"}},
|
||||
)
|
||||
self.db.analytics.update_many(
|
||||
{"user": {"$exists": True}},
|
||||
{"$rename": {"user": "user_id"}},
|
||||
)
|
||||
self.db.warnings.update_many(
|
||||
{"user": {"$exists": True}},
|
||||
{"$rename": {"user": "user_id"}},
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
try:
|
||||
config_delete("cache", *[])
|
||||
except Exception as exc:
|
||||
logger.error(
|
||||
"Could not downgrade the config during migration '%s' due to: %s",
|
||||
__name__,
|
||||
exc,
|
||||
)
|
||||
|
||||
self.db.users.update_many(
|
||||
{"id": {"$exists": True}},
|
||||
{"$rename": {"id": "user"}},
|
||||
)
|
||||
self.db.analytics.update_many(
|
||||
{"user": {"$exists": True}},
|
||||
{"$rename": {"user_id": "user"}},
|
||||
)
|
||||
self.db.warnings.update_many(
|
||||
{"user": {"$exists": True}},
|
||||
{"$rename": {"user_id": "user"}},
|
||||
)
|
Reference in New Issue
Block a user