-
Notifications
You must be signed in to change notification settings - Fork 2
Replace TinyDB with a Postgres #25
Copy link
Copy link
Open
Description
- Add postgres to the docker-compose stack
- Use psycopg3
- Write SQL
- refactor all database objects and operations
- migrate existing database to Postgres on startup
- Make a backup of the tinyDB database before
- Only do this if it was not done before
- Make unit tests work again and make them fast by reusing the application and just truncating tables between tests where possible
Database Patterns
Look at https://github.com/FreeshardBase/freeshard-controller/tree/main/freeshard-controller-backend/freeshard_controller/db for examples. Copy what is needed.
- All functions take
AsyncConnectionas their first param — the caller is responsible for connection lifecycle. - Use
db_conn()context manager fromconnection.pyto get a connection from the pool. - Row-to-model mapping uses
cursor(row_factory=class_row(PydanticModel)). - SQL is written inline as f-strings with parameterized values (psycopg
%(name)sstyle placeholders). Type-annotate SQL strings asLiteralStringwhere possible. - Dynamic SQL construction (for variable columns in UPDATE/INSERT) is built from Pydantic
model_dump()keys. - Explicit
await conn.commit()is needed when autocommit is off (most service-layer callers commit explicitly).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels