aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/db
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/db')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/c5e93b1a2f60_keep_username_on_ip_logs.py31
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/db/models.py5
2 files changed, 36 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/c5e93b1a2f60_keep_username_on_ip_logs.py b/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/c5e93b1a2f60_keep_username_on_ip_logs.py
new file mode 100644
index 0000000..cfa3229
--- /dev/null
+++ b/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/c5e93b1a2f60_keep_username_on_ip_logs.py
@@ -0,0 +1,31 @@
+"""keep_username_on_ip_logs
+
+The connection log is kept for its legal retention period and is meant to stay
+attributable. It took the name from a join on `users`, and account deletion
+tombstones that row — so the log answered `deleted-3f9a1c` for precisely the
+records someone would be asking about. The name is copied onto the log rows at
+deletion; it stays NULL while the account is alive, where the join is better
+because it cannot go stale.
+
+Revision ID: c5e93b1a2f60
+Revises: b4d82e1c77a9
+Create Date: 2026-08-15
+
+"""
+from typing import Sequence, Union
+
+import sqlalchemy as sa
+from alembic import op
+
+revision: str = 'c5e93b1a2f60'
+down_revision: Union[str, Sequence[str], None] = 'b4d82e1c77a9'
+branch_labels: Union[str, Sequence[str], None] = None
+depends_on: Union[str, Sequence[str], None] = None
+
+
+def upgrade() -> None:
+ op.add_column('ip_logs', sa.Column('username', sa.String(64), nullable=True))
+
+
+def downgrade() -> None:
+ op.drop_column('ip_logs', 'username')
diff --git a/packages/meshbay-hub/src/meshbay_hub/db/models.py b/packages/meshbay-hub/src/meshbay_hub/db/models.py
index f749204..2e36989 100644
--- a/packages/meshbay-hub/src/meshbay_hub/db/models.py
+++ b/packages/meshbay-hub/src/meshbay_hub/db/models.py
@@ -252,6 +252,11 @@ class IPLog(Base):
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
user_id: Mapped[str | None] = mapped_column(ForeignKey("users.id")) # null for failed logins
+ # The name this account had, written when it is deleted. The username is
+ # released on deletion and the row itself is tombstoned, so the join that
+ # normally supplies the name would answer "deleted-3f9a1c" for exactly the
+ # records the log exists to answer questions about.
+ username: Mapped[str | None] = mapped_column(String(64))
event: Mapped[str] = mapped_column(String(32), nullable=False)
ip_address: Mapped[str] = mapped_column(String(45), nullable=False) # IPv4 or IPv6
detail: Mapped[str | None] = mapped_column(String(256)) # e.g. username on fail