Skip to content

Commit

Permalink
feat(users): rename last_active_at to last_login_at for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj-Gupta4 committed Jan 20, 2025
1 parent 5181db3 commit 7d51d19
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/backend/app/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class DbUser(BaseModel):
tasks_invalidated: Optional[int] = None
projects_mapped: Optional[list[int]] = None
registered_at: Optional[AwareDatetime] = None
last_active_at: Optional[AwareDatetime] = None
last_login_at: Optional[AwareDatetime] = None

# Relationships
project_roles: Optional[dict[int, ProjectRole]] = None # project:role pairs
Expand All @@ -187,7 +187,7 @@ async def one(cls, db: Connection, user_identifier: int | str) -> Self:
sql = """
WITH updated_user AS (
UPDATE users
SET last_active_at = NOW()
SET last_login_at = NOW()
WHERE id = %(user_id)s
RETURNING *
)
Expand Down
8 changes: 4 additions & 4 deletions src/backend/app/users/user_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ async def process_inactive_users(
async with db.cursor(row_factory=class_row(DbUser)) as cur:
await cur.execute(
"""
SELECT id, username, last_active_at
SELECT id, username, last_login_at
FROM users
WHERE last_active_at < %(warning_date)s
AND last_active_at >= %(next_warning_date)s;
WHERE last_login_at < %(warning_date)s
AND last_login_at >= %(next_warning_date)s;
""",
{
"warning_date": warning_date,
Expand All @@ -77,7 +77,7 @@ async def process_inactive_users(
"""
SELECT id, username
FROM users
WHERE last_active_at < %(deletion_threshold)s;
WHERE last_login_at < %(deletion_threshold)s;
""",
{"deletion_threshold": deletion_threshold},
)
Expand Down
6 changes: 3 additions & 3 deletions src/backend/migrations/005-add-user-lastactiveat.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- ## Migration add some extra fields.
-- * Add last_active_at to users.
-- * Add last_login_at to users.
-- * Remove NOT NULL constraint from author_id in projects.

-- Related issues:
Expand All @@ -15,9 +15,9 @@ BEGIN
SELECT 1
FROM information_schema.columns
WHERE table_name = 'users'
AND column_name = 'last_active_at'
AND column_name = 'last_login_at'
) THEN
ALTER TABLE users ADD COLUMN last_active_at TIMESTAMPTZ DEFAULT now();
ALTER TABLE users ADD COLUMN last_login_at TIMESTAMPTZ DEFAULT now();
END IF;
END $$;

Expand Down
8 changes: 4 additions & 4 deletions src/backend/migrations/revert/005-add-user-lastactiveat.sql
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
-- * Remove last_active_at from users.
-- * Remove last_login_at from users.
-- * Restore NOT NULL constraint on author_id in projects.

-- Start a transaction
BEGIN;

-- Remove last_active_at column from users
-- Remove last_login_at column from users
DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_name = 'users'
AND column_name = 'last_active_at'
AND column_name = 'last_login_at'
) THEN
ALTER TABLE users DROP COLUMN last_active_at;
ALTER TABLE users DROP COLUMN last_login_at;
END IF;
END $$;

Expand Down

0 comments on commit 7d51d19

Please sign in to comment.