Watch
1
0
Fork
You've already forked arc
0
forked from hesabix/arc
arc/hesabixAPI/scripts/migrations/20260429_users_last_activity_at.sql
2026-05-07 22:21:45 +03:30

16 lines
599 B
SQL
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- آخرین فعالیت کاربر (ضربان اپ)
-- PostgreSQL: ADD COLUMN IF NOT EXISTS فقط از نسخهٔ ۱۱ موجود است؛ برای PG قدیمی‌تر از بلاک شرطی استفاده می‌شود.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = current_schema()
AND table_name = 'users'
AND column_name = 'last_activity_at'
) THEN
ALTER TABLE users ADD COLUMN last_activity_at TIMESTAMP WITHOUT TIME ZONE NULL;
END IF;
END $$;
CREATE INDEX IF NOT EXISTS ix_users_last_activity_at ON users (last_activity_at);