Skip to content

Commit 6f7e959

Browse files
authored
Merge pull request #2 from EnergieID/feat/add-directives-from-db
Add directives from the database
2 parents a87107b + e5fa717 commit 6f7e959

10 files changed

Lines changed: 3496 additions & 14 deletions

File tree

.env.example

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# --- Authentication --------------------------------------------------------
2-
ENERGY_ID_COFY_API_TOKEN=foo
2+
ENERGY_ID_COFY_API_TOKEN=foo
3+
4+
# --- Database --------------------------------------------------------------
5+
DB_URL=postgresql+asyncpg://cofy:cofy@localhost:5432/epv
6+
7+
# dev only, not needed for production, but useful for local development with Docker
8+
POSTGRES_DB=epv
9+
POSTGRES_USER=cofy
10+
POSTGRES_PASSWORD=cofy

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This is the [EPV](https://www.enr-citoyennes.fr/) specific instance of the [cofy
88

99
- Python 3.12+
1010
- [uv](https://docs.astral.sh/uv/) (fast Python package manager)
11+
- [poethepoet](https://poethepoet.natn.io/index.html) (task runner `uv tool install poethepoet`)
1112

1213
### 1. Install dependencies
1314

@@ -22,12 +23,26 @@ cp .env.example .env
2223
# Edit .env and fill in your values
2324
```
2425

25-
### 3. Enable your modules
26+
### 3. Start and seed the local Postgres database
27+
28+
The directive source expects a Postgres connection string in `DB_URL`. You can use any Postgres instance, but for local development we recommend the provided Docker setup. Spin up the container and seed the database with sample data:
29+
30+
```bash
31+
poe db-reset
32+
```
33+
34+
If you have your dev database running without docker, you can still use the seeding command to create the `history` table and load the sample data:
35+
36+
```bash
37+
poe db-seed
38+
```
39+
40+
### 4. Enable your modules
2641

2742
Open `main.py` and add the modules you need (tariff, production, …).
2843
See [cofy-api README](https://github.com/EnergieID/cofy-api) for all available modules & options.
2944

30-
### 4. Run the dev server
45+
### 5. Run the dev server
3146

3247
```bash
3348
poe dev # starts FastAPI with auto-reload, reads .env
@@ -36,7 +51,7 @@ poe dev # starts FastAPI with auto-reload, reads .env
3651
The API is now available at `http://localhost:8000`.
3752
Health-check: `GET /health`
3853

39-
### 5. Run a production-like container locally
54+
### 6. Run a production-like container locally
4055

4156
```bash
4257
poe prod # builds the Docker image and runs it on port 8080
@@ -65,6 +80,15 @@ Every commit will automatically run:
6580

6681
You can also run them manually at any time.
6782

83+
### Local database workflow
84+
85+
```bash
86+
poe db-up # start the local postgres container
87+
poe db-seed # recreate the history table and load db/dev-seed.csv
88+
poe db-reset # run both commands above
89+
poe db-down # remove the local postgres container
90+
```
91+
6892
## License
6993

7094
[MIT](LICENSE)

db/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Database helpers for local development."""

0 commit comments

Comments
 (0)