Update add_user.py to use configurable database path

- Use DATABASE_PATH and DATABASE_URL environment variables
- Consistent with app.py and aerich_config.py configuration
- Add environment variable documentation to help text
- Default remains database/raggr.db for backward compatibility

Usage:
  DATABASE_PATH=dev.db python add_user.py list

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-27 12:02:56 -04:00
parent 29f8894e4a
commit 5e7ac28b6f

View File

@@ -1,16 +1,21 @@
# GENERATED BY CLAUDE # GENERATED BY CLAUDE
import os
import sys import sys
import uuid import uuid
import asyncio import asyncio
from tortoise import Tortoise from tortoise import Tortoise
from blueprints.users.models import User from blueprints.users.models import User
# Database configuration with environment variable support
DATABASE_PATH = os.getenv("DATABASE_PATH", "database/raggr.db")
DATABASE_URL = os.getenv("DATABASE_URL", f"sqlite://{DATABASE_PATH}")
async def add_user(username: str, email: str, password: str): async def add_user(username: str, email: str, password: str):
"""Add a new user to the database""" """Add a new user to the database"""
await Tortoise.init( await Tortoise.init(
db_url="sqlite://database/raggr.db", db_url=DATABASE_URL,
modules={ modules={
"models": [ "models": [
"blueprints.users.models", "blueprints.users.models",
@@ -56,7 +61,7 @@ async def add_user(username: str, email: str, password: str):
async def list_users(): async def list_users():
"""List all users in the database""" """List all users in the database"""
await Tortoise.init( await Tortoise.init(
db_url="sqlite://database/raggr.db", db_url=DATABASE_URL,
modules={ modules={
"models": [ "models": [
"blueprints.users.models", "blueprints.users.models",
@@ -94,6 +99,11 @@ def print_usage():
print("\nExamples:") print("\nExamples:")
print(" python add_user.py add ryan ryan@example.com mypassword123") print(" python add_user.py add ryan ryan@example.com mypassword123")
print(" python add_user.py list") print(" python add_user.py list")
print("\nEnvironment Variables:")
print(" DATABASE_PATH - Path to database file (default: database/raggr.db)")
print(" DATABASE_URL - Full database URL (overrides DATABASE_PATH)")
print("\n Example with custom database:")
print(" DATABASE_PATH=dev.db python add_user.py list")
async def main(): async def main():