Procházet zdrojové kódy

Add 7 new columns to persons table: alive, private, gender, description, notes, timezone, birth_time_known

- storage.py: updated CREATE TABLE, migration block, add_person(), update_person()
- tools.py: updated person_manage() MCP tool params and storage calls
- Renamed 'timezone' param to 'tz' to avoid shadowing datetime.timezone import
- All 102 tests pass
Lukas Goldschmidt před 1 měsícem
rodič
revize
b3f5e85d9c
2 změnil soubory, kde provedl 88 přidání a 3 odebrání
  1. 60 3
      src/astro_mcp/storage.py
  2. 28 0
      src/astro_mcp/tools.py

+ 60 - 3
src/astro_mcp/storage.py

@@ -45,6 +45,14 @@ def _init_db_sync() -> None:
             latitude    REAL NOT NULL,
             longitude   REAL NOT NULL,
             elevation   REAL DEFAULT 0.0,
+            birthplace  TEXT,
+            alive       BOOLEAN DEFAULT 1,
+            private     BOOLEAN DEFAULT 0,
+            gender      TEXT,
+            description TEXT,
+            notes       TEXT,
+            timezone    TEXT,
+            birth_time_known BOOLEAN DEFAULT 1,
             created_at  TEXT NOT NULL,
             updated_at  TEXT
         );
@@ -55,6 +63,20 @@ def _init_db_sync() -> None:
     cols = [row[1] for row in conn.execute("PRAGMA table_info(persons)")]
     if "birthplace" not in cols:
         conn.execute("ALTER TABLE persons ADD COLUMN birthplace TEXT")
+    if "alive" not in cols:
+        conn.execute("ALTER TABLE persons ADD COLUMN alive BOOLEAN DEFAULT 1")
+    if "private" not in cols:
+        conn.execute("ALTER TABLE persons ADD COLUMN private BOOLEAN DEFAULT 0")
+    if "gender" not in cols:
+        conn.execute("ALTER TABLE persons ADD COLUMN gender TEXT")
+    if "description" not in cols:
+        conn.execute("ALTER TABLE persons ADD COLUMN description TEXT")
+    if "notes" not in cols:
+        conn.execute("ALTER TABLE persons ADD COLUMN notes TEXT")
+    if "timezone" not in cols:
+        conn.execute("ALTER TABLE persons ADD COLUMN timezone TEXT")
+    if "birth_time_known" not in cols:
+        conn.execute("ALTER TABLE persons ADD COLUMN birth_time_known BOOLEAN DEFAULT 1")
     conn.commit()
     conn.close()
 
@@ -87,6 +109,13 @@ async def add_person(
     elevation: float = 0.0,
     nickname: str | None = None,
     birthplace: str | None = None,
+    alive: bool = True,
+    private: bool = False,
+    gender: str | None = None,
+    description: str | None = None,
+    notes: str | None = None,
+    tz: str | None = None,
+    birth_time_known: bool = True,
 ) -> dict[str, Any]:
     """Add a new person to the database."""
     await init_db()
@@ -96,9 +125,9 @@ async def add_person(
     def _insert():
         conn = _get_conn()
         conn.execute(
-            """INSERT INTO persons (id, name, nickname, birth_datetime, birthplace, latitude, longitude, elevation, created_at)
-               VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""",
-            (person_id, name, nickname, birth_datetime, birthplace, latitude, longitude, elevation, now),
+            """INSERT INTO persons (id, name, nickname, birth_datetime, birthplace, latitude, longitude, elevation, alive, private, gender, description, notes, timezone, birth_time_known, created_at)
+               VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
+            (person_id, name, nickname, birth_datetime, birthplace, latitude, longitude, elevation, alive, private, gender, description, notes, tz, birth_time_known, now),
         )
         conn.commit()
         row = conn.execute("SELECT * FROM persons WHERE id = ?", (person_id,)).fetchone()
@@ -167,6 +196,13 @@ async def update_person(
     latitude: float | None = None,
     longitude: float | None = None,
     elevation: float | None = None,
+    alive: bool | None = None,
+    private: bool | None = None,
+    gender: str | None = None,
+    description: str | None = None,
+    notes: str | None = None,
+    tz: str | None = None,
+    birth_time_known: bool | None = None,
 ) -> dict[str, Any] | None:
     """Update a person's data. Only provided fields are updated."""
     await init_db()
@@ -202,6 +238,27 @@ async def update_person(
         if elevation is not None:
             fields.append("elevation = ?")
             values.append(elevation)
+        if alive is not None:
+            fields.append("alive = ?")
+            values.append(alive)
+        if private is not None:
+            fields.append("private = ?")
+            values.append(private)
+        if gender is not None:
+            fields.append("gender = ?")
+            values.append(gender)
+        if description is not None:
+            fields.append("description = ?")
+            values.append(description)
+        if notes is not None:
+            fields.append("notes = ?")
+            values.append(notes)
+        if tz is not None:
+            fields.append("timezone = ?")
+            values.append(tz)
+        if birth_time_known is not None:
+            fields.append("birth_time_known = ?")
+            values.append(birth_time_known)
 
         if not fields:
             conn.close()

+ 28 - 0
src/astro_mcp/tools.py

@@ -642,6 +642,13 @@ async def person_manage(
     latitude: float | None = None,
     longitude: float | None = None,
     elevation: float | None = None,
+    alive: bool | None = None,
+    private: bool | None = None,
+    gender: str | None = None,
+    description: str | None = None,
+    notes: str | None = None,
+    tz: str | None = None,
+    birth_time_known: bool | None = None,
 ) -> dict[str, Any]:
     """Manage persons in the birth data database.
 
@@ -655,6 +662,13 @@ async def person_manage(
         latitude: Birth latitude (required for add).
         longitude: Birth longitude (required for add).
         elevation: Birth elevation in meters.
+        alive: Whether the person is alive (default: True).
+        private: Whether the person is hidden from public listing (default: False).
+        gender: Person's gender (male/female/other).
+        description: Short one-line description or summary.
+        notes: Freeform longer notes.
+        tz: IANA timezone name for birthplace (e.g., "Europe/Vienna").
+        birth_time_known: Whether the birth time is accurate (default: True).
 
     Returns:
         Operation result with person data or error.
@@ -674,6 +688,13 @@ async def person_manage(
             elevation=elevation if elevation is not None else 0.0,
             nickname=nickname,
             birthplace=birthplace,
+            alive=alive if alive is not None else True,
+            private=private if private is not None else False,
+            gender=gender,
+            description=description,
+            notes=notes,
+            tz=tz,
+            birth_time_known=birth_time_known if birth_time_known is not None else True,
         )
         return {"action": "add", "person": person}
 
@@ -701,6 +722,13 @@ async def person_manage(
             latitude=latitude,
             longitude=longitude,
             elevation=elevation,
+            alive=alive,
+            private=private,
+            gender=gender,
+            description=description,
+            notes=notes,
+            tz=tz,
+            birth_time_known=birth_time_known,
         )
         if not person:
             return {"action": "update", "error": "not_found"}