Skip to content

Commit afa186a

Browse files
committed
docs: update instructions for FastAPI, pytest, alembic, and Copilot
Generated-by: aiautocommit
1 parent 683bb17 commit afa186a

6 files changed

Lines changed: 43 additions & 3 deletions

File tree

.cursor/rules/alembic-migrations.mdc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description:
33
globs: migrations/versions/*.py
44
alwaysApply: false
55
---
6-
76
## Alembic Migrations
87

98
### Data Migrations

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ session_id = client_secret_id.split("_secret")[0]
3434

3535
### Agent instructions
3636

37-
- Run python tests with `pytest` only. If tests fail because of a configuration or system error, do not attempt to fix and let me know. I will fix it.
37+
- Run python tests with `pytest` only. Do not `cat` the output and do not use `-q`. If tests fail because of a configuration or system error, do not attempt to fix and let me know. I will fix it.
3838
- If you added models, generate a migration with `just migration {add,delete,update}_model_other_description`
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
applyTo: "migrations/versions/*.py"
3+
---
4+
## Alembic Migrations
5+
6+
### Data Migrations
7+
8+
For migrations that include data mutation, and not only schema modifications, use this pattern to setup a session:
9+
10+
```python
11+
from alembic import op
12+
from sqlmodel import Session
13+
from activemodel.session_manager import global_session
14+
from app import log
15+
16+
def run_migration_helper():
17+
pass
18+
19+
def upgrade() -> None:
20+
session = Session(bind=op.get_bind())
21+
22+
with global_session(session):
23+
run_migration_helper()
24+
flip_point_coordinates()
25+
backfill_screening_host_data()
26+
27+
# flush before running any other operations, otherwise not all changes will persist to the transaction
28+
session.flush()
29+
```

.github/instructions/fastapi.instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ applyTo: "app/routes/**/*.py"
55

66
- When throwing a `HTTPException`, do not add a `detail=` and use a named status code (`status.HTTP_400_BAD_REQUEST`)
77
- Do not return a `dict`, instead create a `class RouteNameResponse`
8+
- Locate these classes right above the `def route_name():` function which uses them.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
applyTo: "tests/**/*.py"
3+
---
4+
## Pytest Tests
5+
6+
- Look to tests/factories.py to generate any required database state
7+
- Here's an example of how to create + persist a factory `DistributionFactory.save()`
8+
- Use the `faker` factory to generate emails, etc.
9+
- Do not mock or patch unless I instruct you to. Test as much of the application stack as possible in each test.

constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
"Python": "**/*.py",
1010
"Python App": "**/*.py",
1111
"Pytest Integration Tests": "tests/integration/**/*.py",
12+
"Pytest Tests": "tests/**/*.py",
1213
"Python Route Tests": "tests/routes/**/*.py",
14+
"Alembic Migrations": "migrations/versions/*.py",
1315
"FastAPI": "app/routes/**/*.py",
1416

15-
"React": "**/*.tsx",
17+
"React": "**/*.tsx",
1618
"React Router": "web/app/routes/**/*.tsx",
1719
"React Router Client Loader": None,
1820

0 commit comments

Comments
 (0)