Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
c18752958e
|
|||
0534cc9e2d
|
|||
cd5e1a6a18
|
|||
dfddea78e0
|
|||
7dbd1fcc95 |
1
main.py
1
main.py
@@ -45,7 +45,6 @@ def main() -> None:
|
|||||||
# Perform migration if command line argument was provided
|
# Perform migration if command line argument was provided
|
||||||
if args.migrate:
|
if args.migrate:
|
||||||
migrate_database()
|
migrate_database()
|
||||||
exit()
|
|
||||||
|
|
||||||
# if args.downgrade:
|
# if args.downgrade:
|
||||||
# if not args.confirm:
|
# if not args.confirm:
|
||||||
|
@@ -1,59 +0,0 @@
|
|||||||
from typing import Dict, Any
|
|
||||||
|
|
||||||
from mongodb_migrations.base import BaseMigration
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(BaseMigration):
|
|
||||||
def upgrade(self):
|
|
||||||
index_information_users: Dict[str, Any] = self.db.users.index_information()
|
|
||||||
index_information_events: Dict[str, Any] = self.db.events.index_information()
|
|
||||||
index_information_stages: Dict[str, Any] = self.db.stages.index_information()
|
|
||||||
|
|
||||||
# Update users collection
|
|
||||||
if "user_id" in index_information_users:
|
|
||||||
self.db.users.drop_index("user_id")
|
|
||||||
|
|
||||||
if "user_id-guild_id" not in index_information_users:
|
|
||||||
self.db.users.create_index(["id", "guild_id"], name="user_id-guild_id", unique=True)
|
|
||||||
|
|
||||||
# Update events collection
|
|
||||||
if "guild_id" in index_information_events:
|
|
||||||
self.db.events.drop_index("guild_id")
|
|
||||||
|
|
||||||
if "event_name-guild_id" not in index_information_events:
|
|
||||||
self.db.events.create_index(["name", "guild_id"], name="event_name-guild_id", unique=False)
|
|
||||||
|
|
||||||
# Update stages collection
|
|
||||||
if "event_id-and-guild_id" in index_information_stages:
|
|
||||||
self.db.stages.drop_index("event_id-and-guild_id")
|
|
||||||
|
|
||||||
if "event_id-guild_id" not in index_information_stages:
|
|
||||||
self.db.stages.create_index(["event_id", "guild_id"], name="event_id-guild_id", unique=False)
|
|
||||||
|
|
||||||
def downgrade(self):
|
|
||||||
index_information_users: Dict[str, Any] = self.db.users.index_information()
|
|
||||||
index_information_events: Dict[str, Any] = self.db.events.index_information()
|
|
||||||
index_information_stages: Dict[str, Any] = self.db.stages.index_information()
|
|
||||||
|
|
||||||
# Update users collection
|
|
||||||
if "user_id-guild_id" in index_information_users:
|
|
||||||
self.db.users.drop_index("user_id-guild_id")
|
|
||||||
|
|
||||||
if "user_id" not in index_information_users:
|
|
||||||
self.db.users.create_index("id", name="user_id", unique=True)
|
|
||||||
|
|
||||||
# Update events collection
|
|
||||||
if "event_name-guild_id" in index_information_events:
|
|
||||||
self.db.events.drop_index("event_name-guild_id")
|
|
||||||
|
|
||||||
if "guild_id" not in index_information_events:
|
|
||||||
self.db.events.create_index("guild_id", name="guild_id", unique=False)
|
|
||||||
|
|
||||||
# Update stages collection
|
|
||||||
if "event_id-guild_id" in index_information_stages:
|
|
||||||
self.db.stages.drop_index("event_id-guild_id")
|
|
||||||
|
|
||||||
if "event_id-and-guild_id" not in index_information_stages:
|
|
||||||
self.db.stages.create_index(
|
|
||||||
["event_id", "guild_id"], name="event_id-and-guild_id", unique=False
|
|
||||||
)
|
|
@@ -32,7 +32,7 @@ col_stages: AsyncCollection = db.get_collection("stages")
|
|||||||
|
|
||||||
# Update indexes
|
# Update indexes
|
||||||
async def _update_database_indexes() -> None:
|
async def _update_database_indexes() -> None:
|
||||||
await col_users.create_index(["id", "guild_id"], name="user_id-guild_id", unique=True)
|
await col_users.create_index("id", name="user_id", unique=True)
|
||||||
await col_guilds.create_index("id", name="guild_id", unique=True)
|
await col_guilds.create_index("id", name="guild_id", unique=True)
|
||||||
await col_events.create_index(["name", "guild_id"], name="event_name-guild_id", unique=False)
|
await col_events.create_index("guild_id", name="guild_id", unique=False)
|
||||||
await col_stages.create_index(["event_id", "guild_id"], name="event_id-guild_id", unique=False)
|
await col_stages.create_index(["event_id", "guild_id"], name="event_id-and-guild_id", unique=False)
|
||||||
|
Reference in New Issue
Block a user