forked from mtusi2026/mtusi2026lab2
all for lab2
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
spring.application.name=demo
|
||||
# HikariCP
|
||||
spring.datasource.hikari.maximum-pool-size=10
|
||||
spring.datasource.hikari.minimum-idle=2
|
||||
spring.datasource.hikari.connection-timeout=3000
|
||||
spring.datasource.hikari.validation-timeout=1000
|
||||
spring.datasource.hikari.idle-timeout=60000
|
||||
spring.datasource.hikari.max-lifetime=1800000
|
||||
|
||||
# PostgreSQL
|
||||
spring.datasource.hikari.data-source-properties.connectTimeout=3
|
||||
spring.datasource.hikari.data-source-properties.socketTimeout=10
|
||||
|
||||
# Redis
|
||||
spring.data.redis.timeout=2s
|
||||
|
||||
# Транзакции
|
||||
spring.transaction.default-timeout=10s
|
||||
@@ -0,0 +1,30 @@
|
||||
spring:
|
||||
lifecycle:
|
||||
timeout-per-shutdown-phase: 10s
|
||||
|
||||
jackson:
|
||||
default-property-inclusion: always
|
||||
deserialization:
|
||||
fail-on-unknown-properties: true
|
||||
|
||||
datasource:
|
||||
url: ${DB_URL:jdbc:postgresql://localhost:5432/messenger}
|
||||
username: ${DB_USERNAME:messenger}
|
||||
password: ${DB_PASSWORD:messenger}
|
||||
driver-class-name: org.postgresql.Driver
|
||||
|
||||
hikari:
|
||||
maximum-pool-size: 10
|
||||
minimum-idle: 2
|
||||
connection-timeout: 5000
|
||||
|
||||
data:
|
||||
redis:
|
||||
host: ${REDIS_HOST:127.0.0.1}
|
||||
port: ${REDIS_PORT:6379}
|
||||
timeout: 3s
|
||||
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: validate
|
||||
open-in-view: false
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
CREATE TABLE users (
|
||||
id UUID PRIMARY KEY,
|
||||
username VARCHAR(32) NOT NULL UNIQUE,
|
||||
display_name VARCHAR(400) NOT NULL,
|
||||
password_hash TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
|
||||
CONSTRAINT chk_username
|
||||
CHECK (username ~ '^[a-z0-9_]{3,32}$'),
|
||||
CONSTRAINT chk_display_name
|
||||
CHECK (
|
||||
char_length(display_name) BETWEEN 1 AND 100
|
||||
AND length(btrim(display_name)) > 0
|
||||
)
|
||||
);
|
||||
|
||||
CREATE TABLE chats (
|
||||
id UUID PRIMARY KEY,
|
||||
title VARCHAR(400) NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
|
||||
CONSTRAINT chk_chat_title
|
||||
CHECK (
|
||||
char_length(title) BETWEEN 1 AND 100
|
||||
AND length(btrim(title)) > 0
|
||||
)
|
||||
);
|
||||
|
||||
CREATE TABLE chat_members (
|
||||
chat_id UUID NOT NULL REFERENCES chats(id),
|
||||
user_id UUID NOT NULL REFERENCES users(id),
|
||||
|
||||
PRIMARY KEY (chat_id, user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE messages (
|
||||
id UUID PRIMARY KEY,
|
||||
chat_id UUID NOT NULL REFERENCES chats(id),
|
||||
sender_id UUID NOT NULL,
|
||||
text VARCHAR(16000) NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
|
||||
CONSTRAINT fk_message_membership
|
||||
FOREIGN KEY (chat_id, sender_id)
|
||||
REFERENCES chat_members(chat_id, user_id),
|
||||
|
||||
CONSTRAINT chk_message_text
|
||||
CHECK (
|
||||
char_length(text) BETWEEN 1 AND 4000
|
||||
AND length(btrim(text)) > 0
|
||||
)
|
||||
);
|
||||
|
||||
CREATE TABLE sessions (
|
||||
id UUID PRIMARY KEY,
|
||||
user_id UUID NOT NULL REFERENCES users(id),
|
||||
token_hash CHAR(64) NOT NULL UNIQUE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
revoked_at TIMESTAMPTZ,
|
||||
|
||||
CONSTRAINT chk_session_expiry
|
||||
CHECK (expires_at > created_at)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_chat_members_user
|
||||
ON chat_members(user_id, chat_id);
|
||||
|
||||
CREATE INDEX idx_chats_history
|
||||
ON chats(created_at, id);
|
||||
|
||||
CREATE INDEX idx_messages_history
|
||||
ON messages(chat_id, created_at, id);
|
||||
|
||||
CREATE INDEX idx_sessions_user
|
||||
ON sessions(user_id);
|
||||
Reference in New Issue
Block a user