- Nowa tabela user_blocks do przechowywania blokad - Model UserBlock w database.py - Sprawdzanie blokad przed wysłaniem wiadomości (messages_send, messages_reply) - UI zarządzania blokadami w /settings/blocks - Nawigacja między ustawieniami (prywatność, blokady, 2FA) - Blokada działa w obie strony Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
33 lines
1.3 KiB
SQL
33 lines
1.3 KiB
SQL
-- Migration: Add user blocks table
|
|
-- Date: 2026-01-28
|
|
-- Description: Allows users to block other users from sending messages
|
|
|
|
-- Create user_blocks table
|
|
CREATE TABLE IF NOT EXISTS user_blocks (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
blocked_user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
reason TEXT, -- optional reason for blocking
|
|
|
|
-- Prevent duplicate blocks
|
|
UNIQUE(user_id, blocked_user_id),
|
|
|
|
-- Prevent self-blocking
|
|
CHECK (user_id != blocked_user_id)
|
|
);
|
|
|
|
-- Index for efficient lookups
|
|
CREATE INDEX IF NOT EXISTS idx_user_blocks_user_id ON user_blocks(user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_user_blocks_blocked_user_id ON user_blocks(blocked_user_id);
|
|
|
|
-- Comments for documentation
|
|
COMMENT ON TABLE user_blocks IS 'Stores user blocking relationships - blocked users cannot send messages';
|
|
COMMENT ON COLUMN user_blocks.user_id IS 'User who created the block';
|
|
COMMENT ON COLUMN user_blocks.blocked_user_id IS 'User who is blocked';
|
|
COMMENT ON COLUMN user_blocks.reason IS 'Optional reason for blocking';
|
|
|
|
-- Grant permissions
|
|
GRANT ALL ON TABLE user_blocks TO nordabiz_app;
|
|
GRANT USAGE, SELECT ON SEQUENCE user_blocks_id_seq TO nordabiz_app;
|