lab3 gusak

This commit is contained in:
2026-11-12 21:23:41 +03:00
parent 0ab3a341aa
commit 353ec4441d
36 changed files with 1706 additions and 32 deletions
+32
View File
@@ -0,0 +1,32 @@
spring.application.name=messenger-lab2
server.address=${APP_HOST:0.0.0.0}
server.port=${APP_PORT:8080}
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=5s
spring.datasource.url=${DATABASE_URL:jdbc:postgresql://${DB_HOST:postgres}:${DB_PORT:5432}/${DB_NAME:messenger}?socketTimeout=1&options=-c%20statement_timeout%3D1000}
spring.datasource.username=${DB_USERNAME:messenger}
spring.datasource.password=${DB_PASSWORD:messenger}
spring.datasource.hikari.maximum-pool-size=${DB_POOL_SIZE:10}
spring.datasource.hikari.connection-timeout=${DB_CONNECTION_TIMEOUT_MS:3000}
spring.datasource.hikari.validation-timeout=250
spring.datasource.hikari.transaction-isolation=TRANSACTION_READ_COMMITTED
# Connection timeout only limits waiting for a free pool slot. These settings
# also bound an already running PostgreSQL statement and socket read.
spring.datasource.hikari.data-source-properties.[socketTimeout]=${DB_SOCKET_TIMEOUT_SECONDS:1}
spring.datasource.hikari.data-source-properties.[options]=-c statement_timeout=${DB_STATEMENT_TIMEOUT_MS:1000}
spring.jdbc.template.query-timeout=${DB_QUERY_TIMEOUT_SECONDS:1}s
spring.data.redis.host=${REDIS_HOST:redis}
spring.data.redis.port=${REDIS_PORT:6379}
spring.data.redis.timeout=${REDIS_TIMEOUT:2s}
spring.data.redis.connect-timeout=${REDIS_CONNECT_TIMEOUT:2s}
spring.flyway.enabled=true
spring.jackson.property-naming-strategy=SNAKE_CASE
spring.jackson.deserialization.fail-on-trailing-tokens=true
spring.jackson.parser.strict-duplicate-detection=true
server.error.include-message=never
server.error.include-stacktrace=never
spring.main.banner-mode=off
logging.level.root=INFO
@@ -0,0 +1,30 @@
CREATE TABLE users (
id UUID PRIMARY KEY,
username VARCHAR(32) NOT NULL UNIQUE,
display_name VARCHAR(100) NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL
);
CREATE TABLE chats (
id UUID PRIMARY KEY,
title VARCHAR(100) NOT NULL,
created_at TIMESTAMPTZ NOT NULL
);
CREATE TABLE chat_members (
chat_id UUID NOT NULL REFERENCES chats(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
PRIMARY KEY (chat_id, user_id)
);
CREATE TABLE messages (
id UUID PRIMARY KEY,
chat_id UUID NOT NULL REFERENCES chats(id) ON DELETE CASCADE,
sender_id UUID NOT NULL REFERENCES users(id),
text VARCHAR(4000) NOT NULL,
created_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX idx_messages_chat_created_id ON messages(chat_id, created_at, id);
CREATE INDEX idx_chat_members_user_chat ON chat_members(user_id, chat_id);
@@ -0,0 +1,13 @@
CREATE TABLE message_idempotency (
actor_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
method VARCHAR(10) NOT NULL,
request_path VARCHAR(200) NOT NULL,
idempotency_key VARCHAR(128) NOT NULL,
request_hash CHAR(64) NOT NULL,
message_id UUID REFERENCES messages(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL,
PRIMARY KEY (actor_id, method, request_path, idempotency_key)
);
CREATE INDEX idx_message_idempotency_created
ON message_idempotency(created_at);