v0.0.18.3 Добавлении миграции для подписок/подписчиков. Добавлена проверка на userID = 0 для MessageStream
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
cadf06a932
commit
60c8c8e7bb
@ -120,6 +120,11 @@ func (r *queryResolver) GetUserChats(ctx context.Context, userID int) ([]*domain
|
|||||||
|
|
||||||
// MessageStream реализация подписки на новые сообщения
|
// MessageStream реализация подписки на новые сообщения
|
||||||
func (r *subscriptionResolver) MessageStream(ctx context.Context, userID int) (<-chan *domain.Message, error) {
|
func (r *subscriptionResolver) MessageStream(ctx context.Context, userID int) (<-chan *domain.Message, error) {
|
||||||
|
|
||||||
|
if userID == 0 {
|
||||||
|
return nil, fmt.Errorf("user not authenticated")
|
||||||
|
}
|
||||||
|
|
||||||
stream, err := r.MessageClient.StreamMessages(ctx, &proto.StreamMessagesRequest{
|
stream, err := r.MessageClient.StreamMessages(ctx, &proto.StreamMessagesRequest{
|
||||||
UserId: int32(userID),
|
UserId: int32(userID),
|
||||||
})
|
})
|
||||||
|
|||||||
2
migrations/0002_initial_schema.down.sql
Normal file
2
migrations/0002_initial_schema.down.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
DROP TABLE IF EXISTS subscription_notifications CASCADE;
|
||||||
|
DROP TABLE IF EXISTS subscriptions CASCADE;
|
||||||
21
migrations/0002_initial_schema.up.sql
Normal file
21
migrations/0002_initial_schema.up.sql
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
CREATE TABLE subscriptions (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
follower_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, -- Кто подписывается
|
||||||
|
following_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, -- На кого подписываются
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
||||||
|
UNIQUE(follower_id, following_id), -- Уникальная подписка
|
||||||
|
CHECK (follower_id <> following_id) -- Запрет подписки на самого себя
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Уведомления о подписках
|
||||||
|
CREATE TABLE subscription_notifications (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
subscription_id INTEGER NOT NULL REFERENCES subscriptions(id) ON DELETE CASCADE,
|
||||||
|
is_read BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Индексы для улучшения производительности
|
||||||
|
CREATE INDEX idx_subscriptions_follower_id ON subscriptions(follower_id);
|
||||||
|
CREATE INDEX idx_subscriptions_following_id ON subscriptions(following_id);
|
||||||
|
CREATE INDEX idx_subscription_notifications_subscription_id ON subscription_notifications(subscription_id);
|
||||||
Loading…
x
Reference in New Issue
Block a user