Add a way to make it easy to reset the database with some testing data.
This commit is contained in:
parent
e2cb4b220d
commit
21b59467ea
4 changed files with 47 additions and 0 deletions
14
Justfile
14
Justfile
|
@ -10,6 +10,20 @@ build:
|
||||||
@echo "Building the app"
|
@echo "Building the app"
|
||||||
docker compose build
|
docker compose build
|
||||||
|
|
||||||
|
down_with_volumes:
|
||||||
|
@echo "Taking the docker compose stack down, including volumes"
|
||||||
|
docker compose down -v
|
||||||
|
|
||||||
|
migrate:
|
||||||
|
@echo "Migrating the database"
|
||||||
|
docker compose run -w /app/src --rm -u `id -u` app python manage.py migrate
|
||||||
|
|
||||||
|
bootstrap_dev_data:
|
||||||
|
@echo "Bootstrapping development data"
|
||||||
|
docker compose run -w /app/src --rm -u `id -u` app python manage.py bootstrap_dev_data
|
||||||
|
|
||||||
|
reset_db: down_with_volumes migrate bootstrap_dev_data
|
||||||
|
|
||||||
typecheck:
|
typecheck:
|
||||||
docker compose run -w /app/src --rm app mypy .
|
docker compose run -w /app/src --rm app mypy .
|
||||||
|
|
||||||
|
|
0
src/utils/management/__init__.py
Normal file
0
src/utils/management/__init__.py
Normal file
0
src/utils/management/commands/__init__.py
Normal file
0
src/utils/management/commands/__init__.py
Normal file
33
src/utils/management/commands/bootstrap_dev_data.py
Normal file
33
src/utils/management/commands/bootstrap_dev_data.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
"""Command to bootstrap development data."""
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""Command to bootstrap development data."""
|
||||||
|
|
||||||
|
help = "Bootstrap dev data"
|
||||||
|
|
||||||
|
superuser: User
|
||||||
|
normal_users: list[User]
|
||||||
|
|
||||||
|
def handle(self, *args: str, **options: str) -> None:
|
||||||
|
"""Handle the command."""
|
||||||
|
self.create_superuser()
|
||||||
|
self.create_normal_users()
|
||||||
|
|
||||||
|
def create_superuser(self) -> None:
|
||||||
|
"""Create superuser."""
|
||||||
|
self.stdout.write("Creating superuser")
|
||||||
|
self.superuser = User.objects.create_superuser("admin", "admin@example.com")
|
||||||
|
self.superuser.set_password("admin")
|
||||||
|
self.superuser.save()
|
||||||
|
|
||||||
|
def create_normal_users(self) -> None:
|
||||||
|
"""Create normal users."""
|
||||||
|
self.stdout.write("Creating normal users")
|
||||||
|
self.normal_users = [User.objects.create_user(f"user{i}", email=f"user{i}@example.com") for i in range(1, 4)]
|
||||||
|
for user in self.normal_users:
|
||||||
|
user.set_password(user.username)
|
||||||
|
user.save()
|
Loading…
Add table
Reference in a new issue