Move lab2 to lab3
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
ktor {
|
||||
application {
|
||||
modules = [com.mtusi.messenger.main.AppKt.module]
|
||||
}
|
||||
|
||||
deployment {
|
||||
host = "0.0.0.0"
|
||||
host = ${?APP_HOST}
|
||||
port = 8080
|
||||
port = ${?APP_PORT}
|
||||
shutdownGracePeriod = 3000
|
||||
shutdownTimeout = 10000
|
||||
}
|
||||
}
|
||||
|
||||
database {
|
||||
host = "localhost"
|
||||
host = ${?DB_HOST}
|
||||
port = 5432
|
||||
port = ${?DB_PORT}
|
||||
name = "messenger"
|
||||
name = ${?DB_NAME}
|
||||
username = "messenger"
|
||||
username = ${?DB_USER}
|
||||
password = ${?DB_PASSWORD}
|
||||
passwordFile = ${?DB_PASSWORD_FILE}
|
||||
maxPoolSize = 10
|
||||
maxPoolSize = ${?DB_MAX_POOL_SIZE}
|
||||
connectionTimeoutMs = 2000
|
||||
statementTimeoutMs = 5000
|
||||
}
|
||||
|
||||
redis {
|
||||
host = "localhost"
|
||||
host = ${?REDIS_HOST}
|
||||
port = 6379
|
||||
port = ${?REDIS_PORT}
|
||||
password = ${?REDIS_PASSWORD}
|
||||
passwordFile = ${?REDIS_PASSWORD_FILE}
|
||||
connectTimeoutMs = 500
|
||||
commandTimeoutMs = 500
|
||||
}
|
||||
|
||||
authentication {
|
||||
realm = "messenger"
|
||||
sessionTtlSeconds = 3600
|
||||
sessionTtlSeconds = ${?SESSION_TTL_SECONDS}
|
||||
sessionCacheTtlSeconds = 60
|
||||
# Collapse concurrent cache misses for one token into a single database lookup (track 1 compares on/off).
|
||||
sessionCacheSingleFlight = true
|
||||
sessionCacheSingleFlight = ${?SESSION_CACHE_SINGLE_FLIGHT}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX} %-5level [%thread] %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
<logger name="io.netty" level="WARN"/>
|
||||
<logger name="org.eclipse.jetty" level="WARN"/>
|
||||
</configuration>
|
||||
@@ -0,0 +1,50 @@
|
||||
-- Users, chats, membership, messages and sessions. PostgreSQL is the source of truth.
|
||||
-- Timestamps are timestamptz: an absolute instant, independent of server/JVM time zone.
|
||||
|
||||
CREATE TABLE users (
|
||||
id uuid PRIMARY KEY,
|
||||
username varchar(32) NOT NULL,
|
||||
display_name varchar(100) NOT NULL,
|
||||
password_hash varchar(255) NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
CONSTRAINT users_username_key UNIQUE (username),
|
||||
CONSTRAINT users_username_format CHECK (username ~ '^[a-z0-9_]{3,32}$')
|
||||
);
|
||||
|
||||
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,
|
||||
position integer NOT NULL,
|
||||
PRIMARY KEY (chat_id, user_id)
|
||||
);
|
||||
|
||||
-- "Chats of a user": the PK leads with chat_id, so the reverse lookup needs its own index.
|
||||
CREATE INDEX chat_members_user_id_idx ON chat_members (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) ON DELETE CASCADE,
|
||||
text varchar(4000) NOT NULL,
|
||||
created_at timestamptz NOT NULL
|
||||
);
|
||||
|
||||
-- Keyset pagination of a chat history: WHERE chat_id = ? AND (created_at, id) > (?, ?) ORDER BY created_at, id.
|
||||
CREATE INDEX messages_chat_id_created_at_id_idx ON messages (chat_id, created_at, id);
|
||||
|
||||
CREATE TABLE sessions (
|
||||
id uuid PRIMARY KEY,
|
||||
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||
token_hash varchar(64) NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
expires_at timestamptz NOT NULL,
|
||||
CONSTRAINT sessions_token_hash_key UNIQUE (token_hash)
|
||||
);
|
||||
|
||||
CREATE INDEX sessions_user_id_idx ON sessions (user_id);
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Logouts whose tombstone has not reached Redis yet. Written in the same transaction as the session delete and
|
||||
-- removed once the tombstone is stored, so a copy cached before an outage cannot outlive the logout.
|
||||
CREATE TABLE session_revocations (
|
||||
token_hash varchar(64) PRIMARY KEY,
|
||||
expires_at timestamptz NOT NULL
|
||||
);
|
||||
Reference in New Issue
Block a user