feat(csv-parser): Implement CSV import functionality with mapping and type conversion
- Added permissions for editing and deleting CSV field mappings. - Created type converter for CSV cells to handle various data types. - Implemented database migrations for CSV field mappings and import logs. - Seeded initial system templates for nutrition and activity data imports. - Developed admin endpoints for managing system CSV templates. - Introduced user endpoints for CSV import analysis and mapping retrieval. - Added tests for core CSV parser functionalities, including delimiter detection and value conversion.
This commit is contained in:
1 parent
73963e7140
commit
4a771f6a83
16 files changed
+3252
-1
No files matched your search
@@ -0,0 +1,460 @@
|
||||
-- Migration XXX: CSV Parser - System Templates Seed Data
|
||||
-- Legt Standard-Import-Konfigurationen für bekannte CSV-Formate an
|
||||
-- Diese Templates sind für alle User verfügbar (is_system = true, profile_id = NULL)
|
||||
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
-- NUTRITION (Ernährung)
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
-- 1. FDDB Export (Deutsch)
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'nutrition',
|
||||
'FDDB Export (Standard)',
|
||||
'Standard-Format für FDDB.de CSV-Exporte (Deutsch). Delimiter Semikolon, kJ → kcal Konvertierung.',
|
||||
ARRAY['datum_tag_monat_jahr_stunde_minute', 'fett_g', 'kh_g', 'kj', 'protein_g']::TEXT[],
|
||||
';',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"datum_tag_monat_jahr_stunde_minute": "date",
|
||||
"kj": "kcal",
|
||||
"fett_g": "fat_g",
|
||||
"kh_g": "carbs_g",
|
||||
"protein_g": "protein_g"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"date": {
|
||||
"type": "date",
|
||||
"format": "dd.mm.yyyy HH:MM",
|
||||
"extract": "date_only"
|
||||
},
|
||||
"kcal": {
|
||||
"type": "float",
|
||||
"source_unit": "kJ",
|
||||
"target_unit": "kcal",
|
||||
"conversion_factor": 0.239,
|
||||
"decimal_separator": ","
|
||||
},
|
||||
"fat_g": {
|
||||
"type": "float",
|
||||
"decimal_separator": ","
|
||||
},
|
||||
"carbs_g": {
|
||||
"type": "float",
|
||||
"decimal_separator": ","
|
||||
},
|
||||
"protein_g": {
|
||||
"type": "float",
|
||||
"decimal_separator": ","
|
||||
}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- 2. MyFitnessPal Export (English)
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'nutrition',
|
||||
'MyFitnessPal Export',
|
||||
'Standard CSV export from MyFitnessPal (English)',
|
||||
ARRAY['Carbohydrates (g)', 'Calories', 'Date', 'Fat (g)', 'Protein (g)']::TEXT[],
|
||||
',',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"Date": "date",
|
||||
"Calories": "kcal",
|
||||
"Fat (g)": "fat_g",
|
||||
"Carbohydrates (g)": "carbs_g",
|
||||
"Protein (g)": "protein_g"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"date": {
|
||||
"type": "date",
|
||||
"format": "yyyy-mm-dd"
|
||||
},
|
||||
"kcal": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
},
|
||||
"fat_g": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
},
|
||||
"carbs_g": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
},
|
||||
"protein_g": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- 3. Cronometer Export
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'nutrition',
|
||||
'Cronometer Export',
|
||||
'Cronometer daily nutrition export (English)',
|
||||
ARRAY['Day', 'Energy (kcal)', 'Fat (g)', 'Net Carbs (g)', 'Protein (g)']::TEXT[],
|
||||
',',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"Day": "date",
|
||||
"Energy (kcal)": "kcal",
|
||||
"Fat (g)": "fat_g",
|
||||
"Net Carbs (g)": "carbs_g",
|
||||
"Protein (g)": "protein_g"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"date": {
|
||||
"type": "date",
|
||||
"format": "yyyy-mm-dd"
|
||||
},
|
||||
"kcal": {"type": "float", "decimal_separator": "."},
|
||||
"fat_g": {"type": "float", "decimal_separator": "."},
|
||||
"carbs_g": {"type": "float", "decimal_separator": "."},
|
||||
"protein_g": {"type": "float", "decimal_separator": "."}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
-- ACTIVITY (Aktivität)
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
-- 1. Apple Health Workout Export (English)
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'activity',
|
||||
'Apple Health Workout Export (English)',
|
||||
'Apple Health CSV-Export für Workouts (English). Automatisches Training-Type-Mapping.',
|
||||
ARRAY['Active Energy (kcal)', 'Distance (km)', 'Duration', 'End', 'Heart Rate Average (bpm)', 'Start', 'Workout Type']::TEXT[],
|
||||
',',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"Workout Type": "activity_type",
|
||||
"Start": "start_time",
|
||||
"End": "end_time",
|
||||
"Duration": "duration_min",
|
||||
"Distance (km)": "distance_km",
|
||||
"Active Energy (kcal)": "kcal_active",
|
||||
"Heart Rate Average (bpm)": "hr_avg"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"start_time": {
|
||||
"type": "datetime",
|
||||
"format": "yyyy-mm-dd HH:MM:SS",
|
||||
"extract": "date_and_time"
|
||||
},
|
||||
"end_time": {
|
||||
"type": "datetime",
|
||||
"format": "yyyy-mm-dd HH:MM:SS"
|
||||
},
|
||||
"duration_min": {
|
||||
"type": "duration",
|
||||
"format": "HH:MM:SS",
|
||||
"target_unit": "minutes"
|
||||
},
|
||||
"distance_km": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
},
|
||||
"kcal_active": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
},
|
||||
"hr_avg": {
|
||||
"type": "int"
|
||||
}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- 2. Apple Health Workout Export (Deutsch)
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'activity',
|
||||
'Apple Health Workout Export (Deutsch)',
|
||||
'Apple Health CSV-Export für Workouts (Deutsch). Automatisches Training-Type-Mapping.',
|
||||
ARRAY['Aktive Energie (kcal)', 'Dauer', 'Durchschnittliche Herzfrequenz (bpm)', 'Ende', 'Start', 'Strecke (km)', 'Trainingsart']::TEXT[],
|
||||
',',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"Trainingsart": "activity_type",
|
||||
"Start": "start_time",
|
||||
"Ende": "end_time",
|
||||
"Dauer": "duration_min",
|
||||
"Strecke (km)": "distance_km",
|
||||
"Aktive Energie (kcal)": "kcal_active",
|
||||
"Durchschnittliche Herzfrequenz (bpm)": "hr_avg"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"start_time": {
|
||||
"type": "datetime",
|
||||
"format": "yyyy-mm-dd HH:MM:SS",
|
||||
"extract": "date_and_time"
|
||||
},
|
||||
"end_time": {
|
||||
"type": "datetime",
|
||||
"format": "yyyy-mm-dd HH:MM:SS"
|
||||
},
|
||||
"duration_min": {
|
||||
"type": "duration",
|
||||
"format": "HH:MM:SS",
|
||||
"target_unit": "minutes"
|
||||
},
|
||||
"distance_km": {
|
||||
"type": "float",
|
||||
"decimal_separator": ","
|
||||
},
|
||||
"kcal_active": {
|
||||
"type": "float",
|
||||
"decimal_separator": ","
|
||||
},
|
||||
"hr_avg": {
|
||||
"type": "int"
|
||||
}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- 3. Garmin Connect Export
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'activity',
|
||||
'Garmin Connect Export',
|
||||
'Garmin Connect activity CSV export (English)',
|
||||
ARRAY['Activity Type', 'Avg HR', 'Calories', 'Date', 'Distance', 'Duration', 'Time']::TEXT[],
|
||||
',',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"Activity Type": "activity_type",
|
||||
"Date": "date",
|
||||
"Time": "start_time",
|
||||
"Duration": "duration_min",
|
||||
"Distance": "distance_km",
|
||||
"Calories": "kcal_active",
|
||||
"Avg HR": "hr_avg"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"date": {
|
||||
"type": "date",
|
||||
"format": "yyyy-mm-dd"
|
||||
},
|
||||
"start_time": {
|
||||
"type": "time",
|
||||
"format": "HH:MM:SS"
|
||||
},
|
||||
"duration_min": {
|
||||
"type": "duration",
|
||||
"format": "HH:MM:SS",
|
||||
"target_unit": "minutes"
|
||||
},
|
||||
"distance_km": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
},
|
||||
"kcal_active": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
},
|
||||
"hr_avg": {
|
||||
"type": "int"
|
||||
}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
-- BLOOD PRESSURE (Blutdruck)
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
-- 1. Omron Export (Deutsch)
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'blood_pressure',
|
||||
'Omron Export (Deutsch)',
|
||||
'Omron Blutdruckmessgerät CSV-Export (Deutsch)',
|
||||
ARRAY['Datum', 'Diastolisch (mmHg)', 'Puls (bpm)', 'Systolisch (mmHg)', 'Zeit']::TEXT[],
|
||||
',',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"Datum": "measured_date",
|
||||
"Zeit": "measured_time",
|
||||
"Systolisch (mmHg)": "systolic",
|
||||
"Diastolisch (mmHg)": "diastolic",
|
||||
"Puls (bpm)": "pulse"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"measured_date": {
|
||||
"type": "date",
|
||||
"format": "dd.mm.yyyy"
|
||||
},
|
||||
"measured_time": {
|
||||
"type": "time",
|
||||
"format": "HH:MM"
|
||||
},
|
||||
"systolic": {"type": "int"},
|
||||
"diastolic": {"type": "int"},
|
||||
"pulse": {"type": "int"}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- 2. Omron Export (English)
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'blood_pressure',
|
||||
'Omron Export (English)',
|
||||
'Omron blood pressure monitor CSV export (English)',
|
||||
ARRAY['Date', 'Diastolic (mmHg)', 'Pulse (bpm)', 'Systolic (mmHg)', 'Time']::TEXT[],
|
||||
',',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"Date": "measured_date",
|
||||
"Time": "measured_time",
|
||||
"Systolic (mmHg)": "systolic",
|
||||
"Diastolic (mmHg)": "diastolic",
|
||||
"Pulse (bpm)": "pulse"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"measured_date": {
|
||||
"type": "date",
|
||||
"format": "mm/dd/yyyy"
|
||||
},
|
||||
"measured_time": {
|
||||
"type": "time",
|
||||
"format": "HH:MM"
|
||||
},
|
||||
"systolic": {"type": "int"},
|
||||
"diastolic": {"type": "int"},
|
||||
"pulse": {"type": "int"}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
-- WEIGHT (Gewicht)
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
-- 1. Apple Health Weight Export
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'weight',
|
||||
'Apple Health Weight Export',
|
||||
'Apple Health body mass CSV export',
|
||||
ARRAY['Body Mass (kg)', 'Start']::TEXT[],
|
||||
',',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"Start": "date",
|
||||
"Body Mass (kg)": "weight"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"date": {
|
||||
"type": "datetime",
|
||||
"format": "yyyy-mm-dd HH:MM:SS",
|
||||
"extract": "date_only"
|
||||
},
|
||||
"weight": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- 2. Withings Export
|
||||
INSERT INTO csv_field_mappings (
|
||||
profile_id, is_system, module, mapping_name, description,
|
||||
column_signature, delimiter, encoding, has_header,
|
||||
field_mappings, type_conversions
|
||||
) VALUES (
|
||||
NULL,
|
||||
true,
|
||||
'weight',
|
||||
'Withings Export',
|
||||
'Withings smart scale CSV export (weight, body fat, muscle mass)',
|
||||
ARRAY['Body Fat (%)', 'Date', 'Muscle Mass (kg)', 'Weight (kg)']::TEXT[],
|
||||
',',
|
||||
'utf-8',
|
||||
true,
|
||||
'{
|
||||
"Date": "date",
|
||||
"Weight (kg)": "weight"
|
||||
}'::JSONB,
|
||||
'{
|
||||
"date": {
|
||||
"type": "date",
|
||||
"format": "yyyy-mm-dd"
|
||||
},
|
||||
"weight": {
|
||||
"type": "float",
|
||||
"decimal_separator": "."
|
||||
}
|
||||
}'::JSONB
|
||||
);
|
||||
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
-- SUMMARY
|
||||
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
template_count INTEGER;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO template_count FROM csv_field_mappings WHERE is_system = true;
|
||||
RAISE NOTICE '✓ CSV Parser: % System-Templates created', template_count;
|
||||
RAISE NOTICE ' - Nutrition: 3 (FDDB, MyFitnessPal, Cronometer)';
|
||||
RAISE NOTICE ' - Activity: 3 (Apple Health DE/EN, Garmin)';
|
||||
RAISE NOTICE ' - Blood Pressure: 2 (Omron DE/EN)';
|
||||
RAISE NOTICE ' - Weight: 2 (Apple Health, Withings)';
|
||||
END $$;
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,339 @@
|
||||
# Architektur-Regeln – Mitai Jinkendo
|
||||
|
||||
> **PFLICHTLEKTÜRE für Claude Code vor jeder Implementierung.**
|
||||
> Diese Regeln sind verbindlich und dürfen nicht ohne explizite
|
||||
> Genehmigung des Nutzers abgeändert werden.
|
||||
|
||||
---
|
||||
|
||||
## 1. Router-Architektur
|
||||
|
||||
### 1.1 Ein Modul = Ein Router
|
||||
Jedes fachliche Modul hat genau eine Router-Datei in `backend/routers/`.
|
||||
|
||||
```
|
||||
backend/routers/
|
||||
├── auth.py # Authentifizierung
|
||||
├── profiles.py # Nutzerprofile
|
||||
├── weight.py # Gewichts-Tracking
|
||||
├── sleep.py # Schlaf-Modul
|
||||
├── training_types.py # Trainingstypen + HF
|
||||
└── ... # je neues Modul = neue Datei
|
||||
```
|
||||
|
||||
**Regeln:**
|
||||
- Kein Endpoint darf außerhalb seines thematischen Routers definiert werden
|
||||
- Neue Module immer als neue Router-Datei anlegen, nie in bestehende einfügen
|
||||
- Router in `main.py` registrieren: `app.include_router(modul.router, prefix="/api")`
|
||||
- Router-Datei-Name = Modul-Name in `version.py` MODULE_VERSIONS
|
||||
|
||||
### 1.2 API-First Prinzip
|
||||
Jede Funktion ist zuerst als API-Endpoint implementiert – die UI nutzt ausschließlich
|
||||
diese Endpoints über `api.js`. Keine Business-Logik im Frontend.
|
||||
|
||||
```python
|
||||
# ✅ Richtig: Logik im Backend-Endpoint
|
||||
@router.get("/sleep/stats")
|
||||
def get_sleep_stats(session=Depends(require_auth)):
|
||||
# Berechnung hier
|
||||
return {"avg_duration": ..., "sleep_debt": ...}
|
||||
|
||||
# ❌ Falsch: Berechnung im Frontend
|
||||
const sleepDebt = entries.reduce((sum, e) => sum + (goal - e.duration), 0)
|
||||
```
|
||||
|
||||
### 1.3 Einheitliche Fehlerbehandlung
|
||||
```python
|
||||
# ✅ Immer dieses Format:
|
||||
raise HTTPException(status_code=404, detail="Eintrag nicht gefunden")
|
||||
# Response: {"detail": "Eintrag nicht gefunden"}
|
||||
|
||||
# ❌ Nie eigene Formate:
|
||||
return {"error": "not found"}
|
||||
return {"message": "Fehler", "success": False}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Versionskontrollsystem
|
||||
|
||||
### 2.1 Versionierungsschema
|
||||
**Semantic Versioning: `MAJOR.MINOR.PATCH`**
|
||||
|
||||
| Typ | Wann | Beispiel |
|
||||
|-----|------|---------|
|
||||
| MAJOR | Breaking Change, DB-Migration inkompatibel | 9.0.0 → 10.0.0 |
|
||||
| MINOR | Neues Feature, neues Modul | 9.2.0 → 9.3.0 |
|
||||
| PATCH | Bugfix, kleine Änderung, Refactor | 9.3.0 → 9.3.1 |
|
||||
|
||||
### 2.2 Versions-Dateien
|
||||
|
||||
**Backend: `backend/version.py`**
|
||||
```python
|
||||
APP_VERSION = "9.3.0"
|
||||
BUILD_DATE = "2026-03-22"
|
||||
|
||||
MODULE_VERSIONS = {
|
||||
"auth": "1.2.0",
|
||||
"profiles": "1.1.0",
|
||||
"weight": "1.0.3",
|
||||
"circumference": "1.0.1",
|
||||
"caliper": "1.0.1",
|
||||
"activity": "1.1.0",
|
||||
"nutrition": "1.0.2",
|
||||
"photos": "1.0.0",
|
||||
"insights": "1.3.0",
|
||||
"prompts": "1.1.0",
|
||||
"admin": "1.2.0",
|
||||
"stats": "1.0.1",
|
||||
"exportdata": "1.1.0",
|
||||
"importdata": "1.0.0",
|
||||
"membership": "2.1.0",
|
||||
}
|
||||
|
||||
CHANGELOG = [
|
||||
{
|
||||
"version": "9.3.0",
|
||||
"date": "2026-03-22",
|
||||
"changes": [
|
||||
"Feature: Sleep Module (sleep_log, JSONB-Segmente)",
|
||||
"Feature: Vitalwerte-Seite in Navigation",
|
||||
"Feature: Trainingstypen-Kategorisierung",
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "9.2.1",
|
||||
"date": "2026-03-20",
|
||||
"changes": [
|
||||
"Fix: Feature-Enforcement Rollback",
|
||||
"Fix: Erholungsstatus-Gewichtung korrigiert",
|
||||
]
|
||||
},
|
||||
]
|
||||
```
|
||||
|
||||
**Frontend: `frontend/src/version.js`**
|
||||
```javascript
|
||||
export const APP_VERSION = "9.3.0"
|
||||
export const BUILD_DATE = "2026-03-22"
|
||||
|
||||
export const PAGE_VERSIONS = {
|
||||
Dashboard: "1.3.0",
|
||||
LoginScreen: "1.1.0",
|
||||
WeightPage: "1.0.3",
|
||||
ActivityPage: "1.2.0",
|
||||
NutritionPage: "1.1.0",
|
||||
AnalysisPage: "1.3.0",
|
||||
SettingsPage: "1.4.0",
|
||||
AdminPanel: "1.2.0",
|
||||
SubscriptionPage: "1.0.0",
|
||||
// Neue Seiten hier eintragen
|
||||
}
|
||||
```
|
||||
|
||||
### 2.3 Versions-Endpoint
|
||||
|
||||
**`GET /api/version`** – öffentlich (kein Auth erforderlich)
|
||||
|
||||
```json
|
||||
{
|
||||
"app_version": "9.3.0",
|
||||
"build_date": "2026-03-22",
|
||||
"backend_version": "9.3.0",
|
||||
"modules": {
|
||||
"auth": "1.2.0",
|
||||
"sleep": "1.0.0"
|
||||
},
|
||||
"db_schema_version": "20260322",
|
||||
"environment": "production"
|
||||
}
|
||||
```
|
||||
|
||||
Dieser Endpoint wird in `backend/routers/version.py` implementiert und liest
|
||||
direkt aus `version.py`.
|
||||
|
||||
### 2.4 Versions-Anzeige in der App
|
||||
|
||||
**Settings-Seite – Versions-Panel:**
|
||||
```
|
||||
System-Versionen
|
||||
─────────────────────────────────────
|
||||
App (gesamt) 9.3.0
|
||||
Backend 9.3.0 ✓ erreichbar
|
||||
Frontend 9.3.0 ✓ geladen
|
||||
DB-Schema 20260322
|
||||
Umgebung production
|
||||
─────────────────────────────────────
|
||||
Module
|
||||
auth 1.2.0
|
||||
sleep 1.0.0
|
||||
membership 2.1.0
|
||||
[alle Module...]
|
||||
─────────────────────────────────────
|
||||
[Changelog] [Cache leeren]
|
||||
```
|
||||
|
||||
Frontend ruft beim Laden der Settings-Seite `/api/version` ab und vergleicht
|
||||
mit der eigenen `APP_VERSION` aus `version.js`. Bei Abweichung: Warnung anzeigen.
|
||||
|
||||
### 2.5 Pflicht-Regel: Versions-Bump bei jedem Commit
|
||||
|
||||
**Jede Code-Änderung erfordert:**
|
||||
1. Versions-Bump in `backend/version.py` (APP_VERSION + betroffenes MODULE_VERSION)
|
||||
2. Versions-Bump in `frontend/src/version.js` (APP_VERSION + betroffene PAGE_VERSION)
|
||||
3. Changelog-Eintrag in `backend/version.py` CHANGELOG
|
||||
|
||||
**Claude Code prüft das im `/deploy` Command automatisch.**
|
||||
|
||||
Kein Commit ohne Versions-Bump – keine Ausnahme.
|
||||
|
||||
### 2.6 DB-Schema-Version
|
||||
|
||||
Format: `YYYYMMDD` (Datum der letzten Migration)
|
||||
|
||||
Gespeichert in `backend/version.py`:
|
||||
```python
|
||||
DB_SCHEMA_VERSION = "20260322"
|
||||
```
|
||||
|
||||
Bei jeder Schema-Änderung (ALTER TABLE, neue Tabelle) → DB_SCHEMA_VERSION aktualisieren.
|
||||
|
||||
---
|
||||
|
||||
## 3. Datenbankregeln
|
||||
|
||||
### 3.1 Pflichtfelder für neue Tabellen
|
||||
```sql
|
||||
-- Jede neue Tabelle braucht:
|
||||
id SERIAL PRIMARY KEY,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
```
|
||||
|
||||
### 3.2 Source-Tracking bei Import-Daten
|
||||
Tabellen die Daten aus externen Quellen empfangen brauchen:
|
||||
```sql
|
||||
source VARCHAR(50) DEFAULT 'manual'
|
||||
-- Werte: 'manual' | 'apple_health' | 'garmin' | 'withings'
|
||||
```
|
||||
|
||||
Manuelle Einträge (`source = 'manual'`) haben IMMER Vorrang bei Reimport:
|
||||
```sql
|
||||
-- Reimport überschreibt nur nicht-manuelle Einträge:
|
||||
INSERT INTO sleep_log (...) ON CONFLICT (profile_id, date)
|
||||
DO UPDATE SET ... WHERE sleep_log.source != 'manual'
|
||||
```
|
||||
|
||||
### 3.3 Profile-ID Isolation
|
||||
Jede Tabelle mit Nutzerdaten hat `profile_id` als Foreign Key.
|
||||
Kein Endpoint gibt Daten eines anderen Profils zurück.
|
||||
Profile-ID kommt IMMER aus der Session, nie aus Request-Parametern.
|
||||
|
||||
### 3.4 Boolean-Werte
|
||||
```sql
|
||||
-- PostgreSQL Boolean (nicht SQLite 0/1):
|
||||
WHERE active = true ✓
|
||||
WHERE active = 1 ✗
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Frontend-Regeln
|
||||
|
||||
### 4.1 Alle API-Calls über api.js
|
||||
```javascript
|
||||
// ✅ Richtig:
|
||||
import { api } from '../utils/api'
|
||||
const data = await api.listSleep()
|
||||
|
||||
// ❌ Falsch:
|
||||
const r = await fetch('/api/sleep')
|
||||
```
|
||||
|
||||
### 4.2 Neue Seite = Eintrag in PAGE_VERSIONS
|
||||
Jede neue Seite in `frontend/src/version.js` registrieren.
|
||||
|
||||
### 4.3 CSS-Variablen statt Hardcoded-Farben
|
||||
```javascript
|
||||
// ✅ Richtig:
|
||||
style={{color: 'var(--accent)'}}
|
||||
|
||||
// ❌ Falsch:
|
||||
style={{color: '#1D9E75'}}
|
||||
```
|
||||
|
||||
### 4.4 Fehlerbehandlung in allen async Funktionen
|
||||
```javascript
|
||||
try {
|
||||
const data = await api.meinEndpoint()
|
||||
setData(data)
|
||||
} catch(e) {
|
||||
setError(e.message)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Git & Deployment-Regeln
|
||||
|
||||
### 5.1 Nie direkt auf main pushen
|
||||
Immer über Pull Request in Gitea: develop → main.
|
||||
develop Branch niemals löschen.
|
||||
|
||||
### 5.2 Commit-Message Format
|
||||
```
|
||||
feat: neues Feature oder Modul
|
||||
fix: Bugfix
|
||||
refactor: Umbau ohne Funktionsänderung
|
||||
docs: Dokumentation
|
||||
version: Versions-Bump
|
||||
ci: CI/CD Änderungen
|
||||
chore: Maintenance
|
||||
```
|
||||
|
||||
### 5.3 Versions-Bump im Commit
|
||||
```
|
||||
feat: Sleep Module v1.0.0
|
||||
|
||||
- sleep_log Tabelle mit JSONB-Segmenten
|
||||
- Import aus Apple Health CSV
|
||||
- Korrelationen Schlaf <-> Ruhepuls
|
||||
|
||||
version: 9.3.0 (backend + frontend)
|
||||
module: sleep 1.0.0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Dokumentations-Regeln
|
||||
|
||||
### 6.1 Neue Module dokumentieren
|
||||
Bei jedem neuen Modul:
|
||||
1. Fachliche Spec: `.claude/docs/functional/MODUL_NAME.md`
|
||||
2. Technische Spec: `.claude/docs/technical/MODUL_NAME.md`
|
||||
3. Nach Fertigstellung: `.claude/library/` aktualisieren
|
||||
|
||||
### 6.2 CLAUDE.md aktuell halten
|
||||
Nach größeren Änderungen CLAUDE.md Versions-Tabelle aktualisieren.
|
||||
|
||||
### 6.3 Lessons Learned dokumentieren
|
||||
Jeder Rollback oder schwerer Bug → Eintrag in `.claude/rules/LESSONS_LEARNED.md`
|
||||
|
||||
---
|
||||
|
||||
## Zusammenfassung: Checkliste vor jedem Commit
|
||||
|
||||
```
|
||||
[ ] Versions-Bump in backend/version.py (APP_VERSION + MODULE)
|
||||
[ ] Versions-Bump in frontend/src/version.js (APP_VERSION + PAGE)
|
||||
[ ] Changelog-Eintrag in backend/version.py
|
||||
[ ] DB_SCHEMA_VERSION aktualisiert (wenn Schema geändert)
|
||||
[ ] Neues Modul in PAGE_VERSIONS / MODULE_VERSIONS eingetragen
|
||||
[ ] Auth auf alle neuen Endpoints (require_auth)
|
||||
[ ] Fehlerformat einheitlich (HTTPException mit detail)
|
||||
[ ] Neue Tabellen haben created_at + updated_at
|
||||
[ ] Import-Tabellen haben source-Feld
|
||||
[ ] api.js für alle Frontend API-Calls
|
||||
```
|
||||
Reference in new issue
Block a user