From 5e7ac28b6fb935c60e09df5c0f252adf02ec1c8e Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Mon, 27 Oct 2025 12:02:56 -0400 Subject: [PATCH] Update add_user.py to use configurable database path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- add_user.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/add_user.py b/add_user.py index 2380a89..be7c364 100644 --- a/add_user.py +++ b/add_user.py @@ -1,16 +1,21 @@ # GENERATED BY CLAUDE +import os import sys import uuid import asyncio from tortoise import Tortoise 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): """Add a new user to the database""" await Tortoise.init( - db_url="sqlite://database/raggr.db", + db_url=DATABASE_URL, modules={ "models": [ "blueprints.users.models", @@ -56,7 +61,7 @@ async def add_user(username: str, email: str, password: str): async def list_users(): """List all users in the database""" await Tortoise.init( - db_url="sqlite://database/raggr.db", + db_url=DATABASE_URL, modules={ "models": [ "blueprints.users.models", @@ -94,6 +99,11 @@ def print_usage(): print("\nExamples:") print(" python add_user.py add ryan ryan@example.com mypassword123") 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():