Files
backend/migrations/00007_create_ratings_table.sql
2025-12-13 22:34:01 +05:00

44 lines
1.7 KiB
SQL
Raw 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.

-- +goose Up
-- +goose StatementBegin
-- =========================================
-- ТАБЛИЦА: ratings - Рейтинги волонтёров
-- =========================================
CREATE TABLE ratings (
id BIGSERIAL PRIMARY KEY,
-- Связи
volunteer_response_id BIGINT NOT NULL UNIQUE REFERENCES volunteer_responses(id),
volunteer_id BIGINT NOT NULL REFERENCES users(id),
requester_id BIGINT NOT NULL REFERENCES users(id),
request_id BIGINT NOT NULL REFERENCES requests(id),
-- Оценка
rating INTEGER NOT NULL CHECK (rating >= 1 AND rating <= 5),
comment TEXT,
-- Аудит
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
-- Комментарии
COMMENT ON TABLE ratings IS 'Рейтинги волонтёров за выполненную помощь';
COMMENT ON COLUMN ratings.rating IS 'Оценка от 1 до 5 звёзд';
COMMENT ON COLUMN ratings.volunteer_response_id IS 'Связь с откликом (один рейтинг на один отклик)';
COMMENT ON COLUMN ratings.volunteer_id IS 'Денормализация для быстрого доступа';
COMMENT ON COLUMN ratings.requester_id IS 'Кто оставил рейтинг';
-- Индексы
CREATE INDEX idx_ratings_volunteer_id ON ratings(volunteer_id);
CREATE INDEX idx_ratings_request_id ON ratings(request_id);
CREATE INDEX idx_ratings_requester_id ON ratings(requester_id);
CREATE INDEX idx_ratings_created_at ON ratings(created_at DESC);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS ratings CASCADE;
-- +goose StatementEnd