-
Notifications
You must be signed in to change notification settings - Fork 111
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
chethanuk
wants to merge
2
commits into
pingcap:main
Choose a base branch
from
chethanuk:default_user
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+22
−9
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,20 @@ | |
from sqlmodel import select, func | ||
from sqlmodel.ext.asyncio.session import AsyncSession | ||
from colorama import Fore, Style | ||
import click | ||
|
||
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, | ||
|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]" } | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
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 😂