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