notatki
This commit is contained in:
+47
-12
@@ -2,9 +2,9 @@
|
||||
|
||||
Two Flask services with separate responsibilities and separate databases:
|
||||
|
||||
- **main app** (`app.py`) — all user-facing views: login, home, API docs and
|
||||
the `/sensors` dashboard. It owns the **users** database (`main_app.db`) and
|
||||
proxies data requests to the sensors API.
|
||||
- **main app** (`app.py`) — all user-facing views: login, home, notes, API docs
|
||||
and the `/sensors` dashboard. It owns the **main app** database
|
||||
(`main_app.db`: users and notes) and proxies data requests to the sensors API.
|
||||
- **sensors app** (`sensors_app.py`) — API only. It owns the **sensors**
|
||||
database (`sensors.db`, tables `sensor` and `sensor_readout`) and has no
|
||||
knowledge of users. Its API is open to every user on the local machine.
|
||||
@@ -28,13 +28,13 @@ browser ──> main app :8000 ──HTTP──> sensors API :8001
|
||||
|
||||
```
|
||||
server/
|
||||
├── app.py # Main app: views + API proxy
|
||||
├── app.py # Main app: views, notes + API proxy
|
||||
├── sensors_app.py # Sensors app: API + sensors database
|
||||
├── sensors_client.py # HTTP client used by the main app
|
||||
├── auth.py # Flask-Login setup
|
||||
├── config.py # Config (databases, secret key, sensors URL)
|
||||
├── models.py # Sensor, SensorReadout (sensors DB)
|
||||
├── user_models.py # User (main_app.db)
|
||||
├── user_models.py # User, Note, NoteItem (main_app.db)
|
||||
├── seed.py # Sample sensor data
|
||||
├── migrate_legacy_db.py # Import old combined data.db into split DBs
|
||||
├── run.sh # Development launcher (main/sensors + port)
|
||||
@@ -51,6 +51,7 @@ server/
|
||||
└── templates/
|
||||
├── home.html
|
||||
├── login.html
|
||||
├── notes.html
|
||||
├── docs.html
|
||||
└── sensors.html
|
||||
```
|
||||
@@ -101,11 +102,11 @@ After verifying the new databases you can archive or remove `data.db`.
|
||||
|
||||
## Users
|
||||
|
||||
User accounts live only in `main_app.db` (main app). There is no public
|
||||
registration; accounts are created by an administrator.
|
||||
User accounts and notes live only in `main_app.db` (main app). There is no
|
||||
public registration; accounts are created by an administrator.
|
||||
|
||||
Main app pages (`/`, `/home`, `/api/docs`, `/sensors`) and dashboard read
|
||||
endpoints (`GET /api/sensors/:id/types`, `/readouts`, `/readouts/hourly`)
|
||||
Main app pages (`/`, `/home`, `/notes`, `/api/docs`, `/sensors`) and dashboard
|
||||
read endpoints (`GET /api/sensors/:id/types`, `/readouts`, `/readouts/hourly`)
|
||||
require login. Device endpoints (`GET/POST /api/sensors`,
|
||||
`POST /api/sensors/:id/readouts`) stay open so devices can push data without a
|
||||
browser session.
|
||||
@@ -161,6 +162,21 @@ sudo -u mateusz env USERS_DB_PATH=/data/main_app.db \
|
||||
The service does not need to be restarted; the new account is used on the next
|
||||
login.
|
||||
|
||||
## Notes
|
||||
|
||||
Logged-in users manage their own private short notes at `/notes`. Each note has
|
||||
a title, a text body and an optional checklist. Unchecked items are shown first;
|
||||
when an item is checked it is saved as done, moves to the bottom of the checklist
|
||||
and is displayed with a line through it.
|
||||
|
||||
Notes are stored in `main_app.db` in the `note` and `note_item` tables. Apply
|
||||
the users database migration once (the production launcher does this
|
||||
automatically):
|
||||
|
||||
```bash
|
||||
alembic -c alembic_users.ini upgrade head
|
||||
```
|
||||
|
||||
## Running
|
||||
|
||||
The first argument selects the app (`main` or `sensors`), the second the port.
|
||||
@@ -270,7 +286,7 @@ deployment path or user is different.
|
||||
|
||||
| Service | Port | Routes |
|
||||
|---|---|---|
|
||||
| main | 8000 | `/`, `/login`, `/home`, `/sensors`, `/api/docs`, `/api/*` (proxy) |
|
||||
| main | 8000 | `/`, `/login`, `/home`, `/notes`, `/sensors`, `/api/docs`, `/api/*` (proxy) |
|
||||
| sensors | 8001 | `/api/*` (sensors and readouts) |
|
||||
|
||||
### Tests
|
||||
@@ -301,9 +317,9 @@ Owned by the sensors app. Contains only sensor data.
|
||||
| `value` | Float | Measured value |
|
||||
| `timestamp` | DateTime | Readout timestamp (UTC) |
|
||||
|
||||
### main_app.db (users)
|
||||
### main_app.db (users and notes)
|
||||
|
||||
Owned by the main app. Contains only accounts.
|
||||
Owned by the main app. Contains accounts and notes.
|
||||
|
||||
**user**
|
||||
| Column | Type | Description |
|
||||
@@ -314,6 +330,25 @@ Owned by the main app. Contains only accounts.
|
||||
| `is_admin` | Boolean | Administrator flag |
|
||||
| `created_at` | DateTime | Creation timestamp (UTC) |
|
||||
|
||||
**note**
|
||||
| Column | Type | Description |
|
||||
|---|---|---|
|
||||
| `id` | Integer | Primary key |
|
||||
| `user_id` | Integer | Foreign key to `user.id` (note owner) |
|
||||
| `title` | String(200) | Note title (existing notes get `Untitled`) |
|
||||
| `content` | Text | Note body |
|
||||
| `created_at` | DateTime | Creation timestamp (UTC) |
|
||||
| `updated_at` | DateTime | Last modification timestamp (UTC) |
|
||||
|
||||
**note_item**
|
||||
| Column | Type | Description |
|
||||
|---|---|---|
|
||||
| `id` | Integer | Primary key |
|
||||
| `note_id` | Integer | Foreign key to `note.id` |
|
||||
| `text` | String(255) | Checklist item text |
|
||||
| `is_done` | Boolean | Checked state (checked items render last, struck through) |
|
||||
| `created_at` | DateTime | Creation timestamp (UTC) |
|
||||
|
||||
### Inspecting the databases on Linux
|
||||
|
||||
The databases are ordinary SQLite files. Use the `sqlite3` CLI (install it with
|
||||
|
||||
Reference in New Issue
Block a user