feat: add admin apis
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE feedback DROP COLUMN IF EXISTS reply_message;
|
||||
ALTER TABLE feedback DROP COLUMN IF EXISTS replied_at;
|
||||
ALTER TABLE notifications DROP COLUMN IF EXISTS body;
|
||||
@@ -0,0 +1,15 @@
|
||||
-- Admin panel support. All additive — existing columns/queries are untouched,
|
||||
-- so the public API and the existing frontend keep working unchanged.
|
||||
|
||||
-- Feedback replies: an admin can write a reply that gets emailed to the
|
||||
-- submitter. reply_message holds the text, replied_at stamps when it was sent
|
||||
-- (one-way, like resolved_at). Replying also resolves the row.
|
||||
ALTER TABLE feedback
|
||||
ADD COLUMN IF NOT EXISTS reply_message TEXT,
|
||||
ADD COLUMN IF NOT EXISTS replied_at TIMESTAMPTZ;
|
||||
|
||||
-- Admin → user direct messages reuse the notifications feed. Event-driven
|
||||
-- notifications carry no free text, so add an optional body column that only
|
||||
-- the 'admin_message' kind populates (all existing kinds leave it NULL).
|
||||
ALTER TABLE notifications
|
||||
ADD COLUMN IF NOT EXISTS body TEXT;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS banned_at;
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Account suspension (ban) support for the admin panel. Additive: the column
|
||||
-- is nullable and defaults to NULL (not banned), so existing rows and queries
|
||||
-- are unaffected. Enforcement: RequireAuth rejects a user whose banned_at is
|
||||
-- set, and LogIn refuses to issue a new session for one.
|
||||
ALTER TABLE users
|
||||
ADD COLUMN IF NOT EXISTS banned_at TIMESTAMPTZ;
|
||||
@@ -0,0 +1,4 @@
|
||||
DROP INDEX IF EXISTS posts_not_deleted_idx;
|
||||
DROP INDEX IF EXISTS post_comments_not_deleted_idx;
|
||||
ALTER TABLE posts DROP COLUMN IF EXISTS deleted_at;
|
||||
ALTER TABLE post_comments DROP COLUMN IF EXISTS deleted_at;
|
||||
@@ -0,0 +1,18 @@
|
||||
-- Soft-delete (admin moderation) for posts and comments. Additive: the column
|
||||
-- is nullable and defaults to NULL, and every read query now filters
|
||||
-- `deleted_at IS NULL` — a no-op for existing rows (all NULL), so nothing in
|
||||
-- the live app changes until an admin actually deletes something. A soft-
|
||||
-- deleted row disappears from all reads but stays in the table, recoverable
|
||||
-- via the admin "restore" action.
|
||||
ALTER TABLE posts
|
||||
ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ;
|
||||
|
||||
ALTER TABLE post_comments
|
||||
ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ;
|
||||
|
||||
-- Partial indexes keep the hot "not deleted" reads fast (they match the
|
||||
-- deleted_at IS NULL predicate now on every posts/comments query).
|
||||
CREATE INDEX IF NOT EXISTS posts_not_deleted_idx
|
||||
ON posts (created_at DESC) WHERE deleted_at IS NULL;
|
||||
CREATE INDEX IF NOT EXISTS post_comments_not_deleted_idx
|
||||
ON post_comments (post_id) WHERE deleted_at IS NULL;
|
||||
Reference in New Issue
Block a user