WSU-Software-Development-Club / WSU-Software-Development-Club/self-hosting

Set up SQLAlchemy + Alembic with a User model

Open
#5 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

intermediate
Dominant language
JavaScript
Stars
2
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Why

This is the first real database code and it establishes how models and migrations work for every feature after it.

Depends on: the healthchecks issue (api must wait for Postgres before running migrations).

Files to touch

  • backend/app/db.py (new): engine + session
  • backend/app/models.py (new): User model
  • backend/alembic/ (new): migration environment
  • backend/requirements.txt
  • api service command in docker-compose.yml

Definition of done

  • User model with id, email (unique, indexed), password_hash, created_at
  • Database URL is built from the env vars in .env
  • alembic upgrade head runs automatically when the api container starts
  • After docker compose up, a users table exists in Postgres (verify with docker compose exec db psql -U $POSTGRES_USER -d $POSTGRES_DB -c '\dt')
  • CI workflow updated with a Postgres service so tests still pass

Hints

Run alembic init alembic inside the backend container, then point env.py at the app's metadata. Alembic tutorial: https://alembic.sqlalchemy.org/en/latest/tutorial.html

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with backend/requirements.txt, backend/app/db.py, backend/app/models.py, and the Alembic tutorial; then inspect the api command in docker-compose.yml and the existing CI workflow. Set up the migration environment and User model, run migrations on container startup, and verify the users table with the provided docker compose exec command while ensuring CI tests still pass with Postgres.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose, postgresql, python, sqlalchemy
Domain
backend, ci-cd, database, devops
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.