Skip to content

Commit

Permalink
feat(migrations): add last_active_at column to users table
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj-Gupta4 committed Jan 15, 2025
1 parent ecda172 commit 2f1c264
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/backend/migrations/005-add-user-lastactiveat.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- ## Migration add some extra fields.
-- * Add last_active_at to users.

-- Related issues:
-- https://github.com/hotosm/fmtm/issues/1999

-- Start a transaction

BEGIN;

DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_name = 'users'
AND column_name = 'last_active_at'
) THEN
ALTER TABLE users ADD COLUMN last_active_at TIMESTAMPTZ DEFAULT now();
END IF;
END $$;

-- Commit the transaction
COMMIT;
16 changes: 16 additions & 0 deletions src/backend/migrations/revert/005-add-user-lastactiveat.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Start a transaction

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

-- Commit the transaction
COMMIT;

0 comments on commit 2f1c264

Please sign in to comment.