Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable passing custom domain username via cli #420

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions backend/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
from sqlmodel import select, func
from sqlmodel.ext.asyncio.session import AsyncSession
from colorama import Fore, Style
import click
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, we should add it to pyproject.toml via poetry?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chethanuk Yes, I mean could you help submit click to pyproject 😂


from app.core.db import get_db_async_session_context
from app.models import User, ChatEngine


async def ensure_admin_user(session: AsyncSession) -> None:
async def ensure_admin_user(session: AsyncSession, email: str | None = None, password: str | None = None) -> None:
result = await session.exec(select(User).where(User.is_superuser == True))
user = result.first()
if not user:
from app.auth.users import create_user

admin_email = "[email protected]"
admin_password = secrets.token_urlsafe(16)
admin_email = email or "[email protected]"
admin_password = password or secrets.token_urlsafe(16)
user = await create_user(
session,
email=admin_email,
Expand Down Expand Up @@ -51,13 +52,21 @@ async def ensure_default_chat_engine(session: AsyncSession) -> None:
print(Fore.YELLOW + "Default chat engine already exists, skipping...")


async def bootstrap() -> None:
async def bootstrap(email: str | None = None, password: str | None = None) -> None:
async with get_db_async_session_context() as session:
await ensure_admin_user(session)
await ensure_admin_user(session, email, password)
await ensure_default_chat_engine(session)


if __name__ == "__main__":
@click.command()
@click.option("--email", default=None, help="Admin user email, [email protected]")
@click.option("--password", default=None, help="Admin user password, default=random generated")
def main(email: str | None, password: str | None):
"""Bootstrap the application with optional admin credentials."""
print(Fore.GREEN + "Bootstrapping the application..." + Style.RESET_ALL)
asyncio.run(bootstrap())
asyncio.run(bootstrap(email, password))
print(Fore.GREEN + "Bootstrapping completed." + Style.RESET_ALL)


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "tidb-ai-python"
version = "0.1.0"
description = "Add your description here"
version = "0.2.9"
description = "AutoFlow Python Backend"
authors = [
{ name = "wd0517", email = "[email protected]" }
]
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/src/pages/docs/deploy-with-docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ If you want to use a different embedding model after deployment, you need to rec
5. Bootstrap the database with initial data:

```bash
# Use default admin credentials ([email protected] with random password)
docker compose run backend /bin/sh -c "python bootstrap.py"

# Or specify a custom admin email
docker compose run backend /bin/sh -c "python bootstrap.py --email [email protected]"
```

Running the bootstrap script creates an admin user. You can find the username and password in the output.
Expand Down
Loading