PySimpleSocial/src/orm/__init__.py

22 lines
868 B
Python

import asyncio
from piccolo.table import create_db_tables
from .users import User
from .media import Media
from .email_verification import EmailVerification
async def create_tables():
"""
Initializes the database by creating the
necessary tables and indexes
"""
await create_db_tables(User, Media, EmailVerification, if_not_exists=True)
# Even though we use an auto-incrementing internal ID as the primary key,
# we'll almost never use it for lookups from the API (it's mostly needed
# for statistics), so we index by public_id and username since those are
# the two main fields we're going to fetch users with
await User.create_index([User.public_id], if_not_exists=True)
await User.create_index([User.username], if_not_exists=True)
await EmailVerification.create_index([EmailVerification.user], if_not_exists=True)