2023-01-03 16:12:46 +02:00
|
|
|
"""Module that provides all database columns and
|
|
|
|
creates geospatial index for col_applications"""
|
|
|
|
|
2022-12-31 00:29:17 +02:00
|
|
|
from pymongo import MongoClient, GEOSPHERE
|
2022-12-10 12:37:15 +02:00
|
|
|
from ujson import loads
|
|
|
|
|
|
|
|
with open("config.json", "r", encoding="utf-8") as f:
|
|
|
|
db_config = loads(f.read())["database"]
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
if db_config["user"] is not None and db_config["password"] is not None:
|
|
|
|
con_string = 'mongodb://{0}:{1}@{2}:{3}/{4}'.format(
|
|
|
|
db_config["user"],
|
|
|
|
db_config["password"],
|
|
|
|
db_config["host"],
|
|
|
|
db_config["port"],
|
|
|
|
db_config["name"]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
con_string = 'mongodb://{0}:{1}/{2}'.format(
|
|
|
|
db_config["host"],
|
|
|
|
db_config["port"],
|
|
|
|
db_config["name"]
|
|
|
|
)
|
|
|
|
|
|
|
|
db_client = MongoClient(con_string)
|
|
|
|
db = db_client.get_database(name=db_config["name"])
|
|
|
|
|
|
|
|
collections = db.list_collection_names()
|
|
|
|
|
2023-01-30 12:01:52 +02:00
|
|
|
for collection in ["tmp", "bans", "users", "context", "youtube", "spoilers", "messages", "warnings", "applications", "sponsorships"]:
|
2022-12-10 12:37:15 +02:00
|
|
|
if not collection in collections:
|
|
|
|
db.create_collection(collection)
|
|
|
|
|
2022-12-14 14:57:29 +02:00
|
|
|
col_tmp = db.get_collection("tmp")
|
2023-01-30 12:01:52 +02:00
|
|
|
col_bans = db.get_collection("bans")
|
2022-12-10 12:37:15 +02:00
|
|
|
col_users = db.get_collection("users")
|
|
|
|
col_context = db.get_collection("context")
|
2023-01-12 14:57:41 +02:00
|
|
|
col_youtube = db.get_collection("youtube")
|
2023-01-04 20:58:54 +02:00
|
|
|
col_spoilers = db.get_collection("spoilers")
|
2022-12-10 12:37:15 +02:00
|
|
|
col_messages = db.get_collection("messages")
|
|
|
|
col_warnings = db.get_collection("warnings")
|
2022-12-10 16:52:07 +02:00
|
|
|
col_applications = db.get_collection("applications")
|
2022-12-28 19:56:13 +02:00
|
|
|
col_sponsorships = db.get_collection("sponsorships")
|
|
|
|
|
2023-01-02 12:13:41 +02:00
|
|
|
col_applications.create_index([("application.3.location", GEOSPHERE)])
|