36 lines
826 B
Python
36 lines
826 B
Python
"""
|
|
Initialize the database schema.
|
|
Run with: python scripts/schema.py
|
|
"""
|
|
import asyncio
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from app.models import Base, engine
|
|
|
|
|
|
async def init_db():
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
print("Database schema created successfully.")
|
|
|
|
|
|
async def drop_db():
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.drop_all)
|
|
print("Database schema dropped.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--drop", action="store_true", help="Drop all tables")
|
|
args = parser.parse_args()
|
|
|
|
if args.drop:
|
|
asyncio.run(drop_db())
|
|
else:
|
|
asyncio.run(init_db())
|