Skip to content

Create an admin user from environment variables in migration#650

Merged
AdrianDAlessandro merged 1 commit intomainfrom
initial-admin-user
Mar 25, 2026
Merged

Create an admin user from environment variables in migration#650
AdrianDAlessandro merged 1 commit intomainfrom
initial-admin-user

Conversation

@AdrianDAlessandro
Copy link
Copy Markdown
Collaborator

Description

This PR adds a data migration that creates an admin user based off environment variables. This will mean we can create admin users on the production server.

Some details:

  • If the username and email already exist in one user, that user is given admin access
  • If the username or email is present, but not in the same user, an error is logged and nothing changes in the database
  • If the username and email do not exist, a new admin user is created
  • A random password is assign to the new user, they can create a password with the "lost password" functionality
  • There is no tests for this for two reasons: migrations are extremely difficult to test, and this should only be run once, after that an admin user will exist and user accounts can be managed via that access.

Fixes #635

Type of change

  • Documentation (non-breaking change that adds or improves the documentation)
  • New feature (non-breaking change which adds functionality)
  • Optimization (non-breaking, back-end change that speeds up the code)
  • Technical work (non-breaking, change which is work as part of a new feature)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Key checklist

  • All tests pass (eg. python -m pytest)
  • The documentation builds and looks OK (eg. mkdocs serve)
  • Pre-commit hooks run successfully (eg. pre-commit run --all-files)

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added or an issue has been opened to tackle that in the future. (Indicate issue here: # (issue))

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
main/migrations/0024_create_admin_user.py 50.00% 17 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@Sahil590 Sahil590 left a comment

Choose a reason for hiding this comment

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

Works for me

@Sahil590
Copy link
Copy Markdown
Contributor

Sahil590 commented Mar 25, 2026

I can see there is no password set ENV will it just send an email prompting them to set up one?

@AdrianDAlessandro AdrianDAlessandro merged commit 4e46a8b into main Mar 25, 2026
4 checks passed
@AdrianDAlessandro AdrianDAlessandro deleted the initial-admin-user branch March 25, 2026 10:44
@AdrianDAlessandro
Copy link
Copy Markdown
Collaborator Author

I can see there is no password set will it just send an email prompting them to setup one?

When they first go to sign in, they can use the "Lost password?" link to get an email for creating a new one. This will likely be me or @davehorsfall for the production server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create initial admin user in data migration

2 participants