mirror of https://github.com/usbharu/Hideout.git
commit
f4d4380c7f
|
@ -17,6 +17,8 @@ hideout:
|
||||||
secret-key: ""
|
secret-key: ""
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
flyway:
|
||||||
|
enabled: false
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: org.h2.Driver
|
driver-class-name: org.h2.Driver
|
||||||
url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1"
|
url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1"
|
||||||
|
|
|
@ -39,9 +39,8 @@ class APResourceResolveServiceImpl(
|
||||||
return (cacheManager.getOrWait(key) as APResolveResponse<T>).objects
|
return (cacheManager.getOrWait(key) as APResolveResponse<T>).objects
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun <T : Object> runResolve(url: String, singer: User?, clazz: Class<T>): ResolveResponse {
|
private suspend fun <T : Object> runResolve(url: String, singer: User?, clazz: Class<T>): ResolveResponse =
|
||||||
return APResolveResponse(apRequestService.apGet(url, singer, clazz))
|
APResolveResponse(apRequestService.apGet(url, singer, clazz))
|
||||||
}
|
|
||||||
|
|
||||||
private fun genCacheKey(url: String, singerId: Long?): String {
|
private fun genCacheKey(url: String, singerId: Long?): String {
|
||||||
if (singerId != null) {
|
if (singerId != null) {
|
||||||
|
|
|
@ -80,26 +80,27 @@ class APUserServiceImpl(
|
||||||
override suspend fun fetchPersonWithEntity(url: String, targetActor: String?): Pair<Person, User> {
|
override suspend fun fetchPersonWithEntity(url: String, targetActor: String?): Pair<Person, User> {
|
||||||
return try {
|
return try {
|
||||||
val userEntity = userQueryService.findByUrl(url)
|
val userEntity = userQueryService.findByUrl(url)
|
||||||
|
val id = userEntity.url
|
||||||
return Person(
|
return Person(
|
||||||
type = emptyList(),
|
type = emptyList(),
|
||||||
name = userEntity.name,
|
name = userEntity.name,
|
||||||
id = url,
|
id = id,
|
||||||
preferredUsername = userEntity.name,
|
preferredUsername = userEntity.name,
|
||||||
summary = userEntity.description,
|
summary = userEntity.description,
|
||||||
inbox = "$url/inbox",
|
inbox = "$id/inbox",
|
||||||
outbox = "$url/outbox",
|
outbox = "$id/outbox",
|
||||||
url = url,
|
url = id,
|
||||||
icon = Image(
|
icon = Image(
|
||||||
type = emptyList(),
|
type = emptyList(),
|
||||||
name = "$url/icon.png",
|
name = "$id/icon.png",
|
||||||
mediaType = "image/png",
|
mediaType = "image/png",
|
||||||
url = "$url/icon.png"
|
url = "$id/icon.png"
|
||||||
),
|
),
|
||||||
publicKey = Key(
|
publicKey = Key(
|
||||||
type = emptyList(),
|
type = emptyList(),
|
||||||
name = "Public Key",
|
name = "Public Key",
|
||||||
id = userEntity.keyId,
|
id = userEntity.keyId,
|
||||||
owner = url,
|
owner = id,
|
||||||
publicKeyPem = userEntity.publicKey
|
publicKeyPem = userEntity.publicKey
|
||||||
),
|
),
|
||||||
endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"),
|
endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"),
|
||||||
|
@ -109,17 +110,48 @@ class APUserServiceImpl(
|
||||||
} catch (ignore: FailedToGetResourcesException) {
|
} catch (ignore: FailedToGetResourcesException) {
|
||||||
val person = apResourceResolveService.resolve<Person>(url, null as Long?)
|
val person = apResourceResolveService.resolve<Person>(url, null as Long?)
|
||||||
|
|
||||||
|
val id = person.id ?: throw IllegalActivityPubObjectException("id is null")
|
||||||
|
try {
|
||||||
|
val userEntity = userQueryService.findByUrl(id)
|
||||||
|
return Person(
|
||||||
|
type = emptyList(),
|
||||||
|
name = userEntity.name,
|
||||||
|
id = id,
|
||||||
|
preferredUsername = userEntity.name,
|
||||||
|
summary = userEntity.description,
|
||||||
|
inbox = "$id/inbox",
|
||||||
|
outbox = "$id/outbox",
|
||||||
|
url = id,
|
||||||
|
icon = Image(
|
||||||
|
type = emptyList(),
|
||||||
|
name = "$id/icon.png",
|
||||||
|
mediaType = "image/png",
|
||||||
|
url = "$id/icon.png"
|
||||||
|
),
|
||||||
|
publicKey = Key(
|
||||||
|
type = emptyList(),
|
||||||
|
name = "Public Key",
|
||||||
|
id = userEntity.keyId,
|
||||||
|
owner = id,
|
||||||
|
publicKeyPem = userEntity.publicKey
|
||||||
|
),
|
||||||
|
endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"),
|
||||||
|
followers = userEntity.followers,
|
||||||
|
following = userEntity.following
|
||||||
|
) to userEntity
|
||||||
|
} catch (_: FailedToGetResourcesException) {
|
||||||
|
}
|
||||||
person to userService.createRemoteUser(
|
person to userService.createRemoteUser(
|
||||||
RemoteUserCreateDto(
|
RemoteUserCreateDto(
|
||||||
name = person.preferredUsername
|
name = person.preferredUsername
|
||||||
?: throw IllegalActivityPubObjectException("preferredUsername is null"),
|
?: throw IllegalActivityPubObjectException("preferredUsername is null"),
|
||||||
domain = url.substringAfter("://").substringBefore("/"),
|
domain = id.substringAfter("://").substringBefore("/"),
|
||||||
screenName = (person.name ?: person.preferredUsername)
|
screenName = (person.name ?: person.preferredUsername)
|
||||||
?: throw IllegalActivityPubObjectException("preferredUsername is null"),
|
?: throw IllegalActivityPubObjectException("preferredUsername is null"),
|
||||||
description = person.summary.orEmpty(),
|
description = person.summary.orEmpty(),
|
||||||
inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"),
|
inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"),
|
||||||
outbox = person.outbox ?: throw IllegalActivityPubObjectException("outbox is null"),
|
outbox = person.outbox ?: throw IllegalActivityPubObjectException("outbox is null"),
|
||||||
url = url,
|
url = id,
|
||||||
publicKey = person.publicKey?.publicKeyPem
|
publicKey = person.publicKey?.publicKeyPem
|
||||||
?: throw IllegalActivityPubObjectException("publicKey is null"),
|
?: throw IllegalActivityPubObjectException("publicKey is null"),
|
||||||
keyId = person.publicKey?.id ?: throw IllegalActivityPubObjectException("publicKey keyId is null"),
|
keyId = person.publicKey?.id ?: throw IllegalActivityPubObjectException("publicKey keyId is null"),
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.nimbusds.jose.jwk.RSAKey
|
||||||
import com.nimbusds.jose.jwk.source.ImmutableJWKSet
|
import com.nimbusds.jose.jwk.source.ImmutableJWKSet
|
||||||
import com.nimbusds.jose.jwk.source.JWKSource
|
import com.nimbusds.jose.jwk.source.JWKSource
|
||||||
import com.nimbusds.jose.proc.SecurityContext
|
import com.nimbusds.jose.proc.SecurityContext
|
||||||
|
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureFilter
|
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureFilter
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureUserDetailsService
|
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureUserDetailsService
|
||||||
|
@ -113,8 +114,14 @@ class SecurityConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun getHttpSignatureFilter(authenticationManager: AuthenticationManager): HttpSignatureFilter {
|
fun getHttpSignatureFilter(
|
||||||
val httpSignatureFilter = HttpSignatureFilter(DefaultSignatureHeaderParser())
|
authenticationManager: AuthenticationManager,
|
||||||
|
transaction: Transaction,
|
||||||
|
apUserService: APUserService,
|
||||||
|
userQueryService: UserQueryService
|
||||||
|
): HttpSignatureFilter {
|
||||||
|
val httpSignatureFilter =
|
||||||
|
HttpSignatureFilter(DefaultSignatureHeaderParser(), transaction, apUserService, userQueryService)
|
||||||
httpSignatureFilter.setAuthenticationManager(authenticationManager)
|
httpSignatureFilter.setAuthenticationManager(authenticationManager)
|
||||||
httpSignatureFilter.setContinueFilterChainOnUnsuccessfulAuthentication(false)
|
httpSignatureFilter.setContinueFilterChainOnUnsuccessfulAuthentication(false)
|
||||||
val authenticationEntryPointFailureHandler =
|
val authenticationEntryPointFailureHandler =
|
||||||
|
|
|
@ -4,12 +4,11 @@ import dev.usbharu.hideout.application.external.Transaction
|
||||||
import kotlinx.coroutines.slf4j.MDCContext
|
import kotlinx.coroutines.slf4j.MDCContext
|
||||||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.sql.Connection
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ExposedTransaction : Transaction {
|
class ExposedTransaction : Transaction {
|
||||||
override suspend fun <T> transaction(block: suspend () -> T): T {
|
override suspend fun <T> transaction(block: suspend () -> T): T {
|
||||||
return newSuspendedTransaction(MDCContext(), transactionIsolation = Connection.TRANSACTION_SERIALIZABLE) {
|
return newSuspendedTransaction(MDCContext()) {
|
||||||
block()
|
block()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,5 +12,5 @@ import dev.usbharu.hideout.core.domain.model.instance.Instance as InstanceEntity
|
||||||
@Repository
|
@Repository
|
||||||
class InstanceQueryServiceImpl : InstanceQueryService {
|
class InstanceQueryServiceImpl : InstanceQueryService {
|
||||||
override suspend fun findByUrl(url: String): InstanceEntity = Instance.select { Instance.url eq url }
|
override suspend fun findByUrl(url: String): InstanceEntity = Instance.select { Instance.url eq url }
|
||||||
.singleOr { FailedToGetResourcesException("url is doesn't exist") }.toInstance()
|
.singleOr { FailedToGetResourcesException("$url is doesn't exist", it) }.toInstance()
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,9 +79,9 @@ object Instance : Table("instance") {
|
||||||
val id = long("id")
|
val id = long("id")
|
||||||
val name = varchar("name", 1000)
|
val name = varchar("name", 1000)
|
||||||
val description = varchar("description", 5000)
|
val description = varchar("description", 5000)
|
||||||
val url = varchar("url", 255)
|
val url = varchar("url", 255).uniqueIndex()
|
||||||
val iconUrl = varchar("icon_url", 255)
|
val iconUrl = varchar("icon_url", 255)
|
||||||
val sharedInbox = varchar("shared_inbox", 255).nullable()
|
val sharedInbox = varchar("shared_inbox", 255).nullable().uniqueIndex()
|
||||||
val software = varchar("software", 255)
|
val software = varchar("software", 255)
|
||||||
val version = varchar("version", 255)
|
val version = varchar("version", 255)
|
||||||
val isBlocked = bool("is_blocked")
|
val isBlocked = bool("is_blocked")
|
||||||
|
|
|
@ -17,7 +17,7 @@ class UserRepositoryImpl(
|
||||||
UserRepository {
|
UserRepository {
|
||||||
|
|
||||||
override suspend fun save(user: User): User {
|
override suspend fun save(user: User): User {
|
||||||
val singleOrNull = Users.select { Users.id eq user.id or (Users.url eq user.url) }.empty()
|
val singleOrNull = Users.select { Users.id eq user.id }.empty()
|
||||||
if (singleOrNull) {
|
if (singleOrNull) {
|
||||||
Users.insert {
|
Users.insert {
|
||||||
it[id] = user.id
|
it[id] = user.id
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature
|
package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||||
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
|
import dev.usbharu.hideout.core.query.UserQueryService
|
||||||
import dev.usbharu.httpsignature.common.HttpHeaders
|
import dev.usbharu.httpsignature.common.HttpHeaders
|
||||||
import dev.usbharu.httpsignature.common.HttpMethod
|
import dev.usbharu.httpsignature.common.HttpMethod
|
||||||
import dev.usbharu.httpsignature.common.HttpRequest
|
import dev.usbharu.httpsignature.common.HttpRequest
|
||||||
import dev.usbharu.httpsignature.verify.SignatureHeaderParser
|
import dev.usbharu.httpsignature.verify.SignatureHeaderParser
|
||||||
import jakarta.servlet.http.HttpServletRequest
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter
|
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
class HttpSignatureFilter(private val httpSignatureHeaderParser: SignatureHeaderParser) :
|
class HttpSignatureFilter(
|
||||||
|
private val httpSignatureHeaderParser: SignatureHeaderParser,
|
||||||
|
private val transaction: Transaction,
|
||||||
|
private val apUserService: APUserService,
|
||||||
|
private val userQueryService: UserQueryService
|
||||||
|
) :
|
||||||
AbstractPreAuthenticatedProcessingFilter() {
|
AbstractPreAuthenticatedProcessingFilter() {
|
||||||
override fun getPreAuthenticatedPrincipal(request: HttpServletRequest?): Any? {
|
override fun getPreAuthenticatedPrincipal(request: HttpServletRequest?): Any? {
|
||||||
val headersList = request?.headerNames?.toList().orEmpty()
|
val headersList = request?.headerNames?.toList().orEmpty()
|
||||||
|
@ -23,6 +33,15 @@ class HttpSignatureFilter(private val httpSignatureHeaderParser: SignatureHeader
|
||||||
} catch (_: RuntimeException) {
|
} catch (_: RuntimeException) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
runBlocking {
|
||||||
|
transaction.transaction {
|
||||||
|
try {
|
||||||
|
userQueryService.findByKeyId(signature.keyId)
|
||||||
|
} catch (e: FailedToGetResourcesException) {
|
||||||
|
apUserService.fetchPerson(signature.keyId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return signature.keyId
|
return signature.keyId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class InstanceServiceImpl(
|
||||||
val resolveInstanceUrl = u.protocol + "://" + u.host
|
val resolveInstanceUrl = u.protocol + "://" + u.host
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return instanceQueryService.findByUrl(url)
|
return instanceQueryService.findByUrl(resolveInstanceUrl)
|
||||||
} catch (e: FailedToGetResourcesException) {
|
} catch (e: FailedToGetResourcesException) {
|
||||||
logger.info("Instance not found. try fetch instance info. url: {}", resolveInstanceUrl)
|
logger.info("Instance not found. try fetch instance info. url: {}", resolveInstanceUrl)
|
||||||
logger.debug("Failed to get resources. url: {}", resolveInstanceUrl, e)
|
logger.debug("Failed to get resources. url: {}", resolveInstanceUrl, e)
|
||||||
|
|
|
@ -18,9 +18,9 @@ spring:
|
||||||
WRITE_DATES_AS_TIMESTAMPS: false
|
WRITE_DATES_AS_TIMESTAMPS: false
|
||||||
default-property-inclusion: always
|
default-property-inclusion: always
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: org.h2.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
url: "jdbc:h2:./test-dev4;MODE=POSTGRESQL;TRACE_LEVEL_FILE=4"
|
url: "jdbc:postgresql:hideout2"
|
||||||
username: ""
|
username: "postgres"
|
||||||
password: ""
|
password: ""
|
||||||
# data:
|
# data:
|
||||||
# mongodb:
|
# mongodb:
|
||||||
|
|
|
@ -1,188 +1,189 @@
|
||||||
CREATE TABLE IF NOT EXISTS "INSTANCE"
|
create table if not exists instance
|
||||||
(
|
(
|
||||||
ID BIGINT PRIMARY KEY,
|
id bigint primary key,
|
||||||
"NAME" VARCHAR(1000) NOT NULL,
|
"name" varchar(1000) not null,
|
||||||
DESCRIPTION VARCHAR(5000) NOT NULL,
|
description varchar(5000) not null,
|
||||||
URL VARCHAR(255) NOT NULL,
|
url varchar(255) not null unique,
|
||||||
ICON_URL VARCHAR(255) NOT NULL,
|
icon_url varchar(255) not null,
|
||||||
SHARED_INBOX VARCHAR(255) NULL,
|
shared_inbox varchar(255) null unique,
|
||||||
SOFTWARE VARCHAR(255) NOT NULL,
|
software varchar(255) not null,
|
||||||
VERSION VARCHAR(255) NOT NULL,
|
version varchar(255) not null,
|
||||||
IS_BLOCKED BOOLEAN NOT NULL,
|
is_blocked boolean not null,
|
||||||
IS_MUTED BOOLEAN NOT NULL,
|
is_muted boolean not null,
|
||||||
MODERATION_NOTE VARCHAR(10000) NOT NULL,
|
moderation_note varchar(10000) not null,
|
||||||
CREATED_AT TIMESTAMP NOT NULL
|
created_at timestamp not null
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS USERS
|
create table if not exists users
|
||||||
(
|
(
|
||||||
ID BIGINT PRIMARY KEY,
|
id bigint primary key,
|
||||||
"NAME" VARCHAR(300) NOT NULL,
|
"name" varchar(300) not null,
|
||||||
"DOMAIN" VARCHAR(1000) NOT NULL,
|
"domain" varchar(1000) not null,
|
||||||
SCREEN_NAME VARCHAR(300) NOT NULL,
|
screen_name varchar(300) not null,
|
||||||
DESCRIPTION VARCHAR(10000) NOT NULL,
|
description varchar(10000) not null,
|
||||||
PASSWORD VARCHAR(255) NULL,
|
password varchar(255) null,
|
||||||
INBOX VARCHAR(1000) NOT NULL,
|
inbox varchar(1000) not null unique,
|
||||||
OUTBOX VARCHAR(1000) NOT NULL,
|
outbox varchar(1000) not null unique,
|
||||||
URL VARCHAR(1000) NOT NULL,
|
url varchar(1000) not null unique,
|
||||||
PUBLIC_KEY VARCHAR(10000) NOT NULL,
|
public_key varchar(10000) not null,
|
||||||
PRIVATE_KEY VARCHAR(10000) NULL,
|
private_key varchar(10000) null,
|
||||||
CREATED_AT BIGINT NOT NULL,
|
created_at bigint not null,
|
||||||
KEY_ID VARCHAR(1000) NOT NULL,
|
key_id varchar(1000) not null,
|
||||||
"FOLLOWING" VARCHAR(1000) NULL,
|
"following" varchar(1000) null,
|
||||||
FOLLOWERS VARCHAR(1000) NULL,
|
followers varchar(1000) null,
|
||||||
"INSTANCE" BIGINT NULL,
|
"instance" bigint null,
|
||||||
CONSTRAINT FK_USERS_INSTANCE__ID FOREIGN KEY ("INSTANCE") REFERENCES "INSTANCE" (ID) ON DELETE RESTRICT ON UPDATE RESTRICT
|
unique (name, domain),
|
||||||
|
constraint fk_users_instance__id foreign key ("instance") references instance (id) on delete restrict on update restrict
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS FOLLOW_REQUESTS
|
create table if not exists follow_requests
|
||||||
(
|
(
|
||||||
ID BIGSERIAL PRIMARY KEY,
|
id bigserial primary key,
|
||||||
USER_ID BIGINT NOT NULL,
|
user_id bigint not null,
|
||||||
FOLLOWER_ID BIGINT NOT NULL,
|
follower_id bigint not null,
|
||||||
CONSTRAINT FK_FOLLOW_REQUESTS_USER_ID__ID FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
constraint fk_follow_requests_user_id__id foreign key (user_id) references users (id) on delete restrict on update restrict,
|
||||||
CONSTRAINT FK_FOLLOW_REQUESTS_FOLLOWER_ID__ID FOREIGN KEY (FOLLOWER_ID) REFERENCES USERS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT
|
constraint fk_follow_requests_follower_id__id foreign key (follower_id) references users (id) on delete restrict on update restrict
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS MEDIA
|
create table if not exists media
|
||||||
(
|
(
|
||||||
ID BIGINT PRIMARY KEY,
|
id bigint primary key,
|
||||||
"NAME" VARCHAR(255) NOT NULL,
|
"name" varchar(255) not null,
|
||||||
URL VARCHAR(255) NOT NULL,
|
url varchar(255) not null,
|
||||||
REMOTE_URL VARCHAR(255) NULL,
|
remote_url varchar(255) null,
|
||||||
THUMBNAIL_URL VARCHAR(255) NULL,
|
thumbnail_url varchar(255) null,
|
||||||
"TYPE" INT NOT NULL,
|
"type" int not null,
|
||||||
BLURHASH VARCHAR(255) NULL,
|
blurhash varchar(255) null,
|
||||||
MIME_TYPE VARCHAR(255) NOT NULL,
|
mime_type varchar(255) not null,
|
||||||
DESCRIPTION VARCHAR(4000) NULL
|
description varchar(4000) null
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS META_INFO
|
create table if not exists meta_info
|
||||||
(
|
(
|
||||||
ID BIGINT PRIMARY KEY,
|
id bigint primary key,
|
||||||
VERSION VARCHAR(1000) NOT NULL,
|
version varchar(1000) not null,
|
||||||
KID VARCHAR(1000) NOT NULL,
|
kid varchar(1000) not null,
|
||||||
JWT_PRIVATE_KEY VARCHAR(100000) NOT NULL,
|
jwt_private_key varchar(100000) not null,
|
||||||
JWT_PUBLIC_KEY VARCHAR(100000) NOT NULL
|
jwt_public_key varchar(100000) not null
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS POSTS
|
create table if not exists posts
|
||||||
(
|
(
|
||||||
ID BIGINT PRIMARY KEY,
|
id bigint primary key,
|
||||||
USER_ID BIGINT NOT NULL,
|
user_id bigint not null,
|
||||||
OVERVIEW VARCHAR(100) NULL,
|
overview varchar(100) null,
|
||||||
TEXT VARCHAR(3000) NOT NULL,
|
text varchar(3000) not null,
|
||||||
CREATED_AT BIGINT NOT NULL,
|
created_at bigint not null,
|
||||||
VISIBILITY INT DEFAULT 0 NOT NULL,
|
visibility int default 0 not null,
|
||||||
URL VARCHAR(500) NOT NULL,
|
url varchar(500) not null,
|
||||||
REPOST_ID BIGINT NULL,
|
repost_id bigint null,
|
||||||
REPLY_ID BIGINT NULL,
|
reply_id bigint null,
|
||||||
"SENSITIVE" BOOLEAN DEFAULT FALSE NOT NULL,
|
"sensitive" boolean default false not null,
|
||||||
AP_ID VARCHAR(100) NOT NULL
|
ap_id varchar(100) not null unique
|
||||||
);
|
);
|
||||||
ALTER TABLE POSTS
|
alter table posts
|
||||||
ADD CONSTRAINT FK_POSTS_USERID__ID FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
add constraint fk_posts_userid__id foreign key (user_id) references users (id) on delete restrict on update restrict;
|
||||||
ALTER TABLE POSTS
|
alter table posts
|
||||||
ADD CONSTRAINT FK_POSTS_REPOSTID__ID FOREIGN KEY (REPOST_ID) REFERENCES POSTS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
add constraint fk_posts_repostid__id foreign key (repost_id) references posts (id) on delete restrict on update restrict;
|
||||||
ALTER TABLE POSTS
|
alter table posts
|
||||||
ADD CONSTRAINT FK_POSTS_REPLYID__ID FOREIGN KEY (REPLY_ID) REFERENCES POSTS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
add constraint fk_posts_replyid__id foreign key (reply_id) references posts (id) on delete restrict on update restrict;
|
||||||
CREATE TABLE IF NOT EXISTS POSTS_MEDIA
|
create table if not exists posts_media
|
||||||
(
|
(
|
||||||
POST_ID BIGINT,
|
post_id bigint,
|
||||||
MEDIA_ID BIGINT,
|
media_id bigint,
|
||||||
CONSTRAINT pk_PostsMedia PRIMARY KEY (POST_ID, MEDIA_ID)
|
constraint pk_postsmedia primary key (post_id, media_id)
|
||||||
);
|
);
|
||||||
ALTER TABLE POSTS_MEDIA
|
alter table posts_media
|
||||||
ADD CONSTRAINT FK_POSTS_MEDIA_POST_ID__ID FOREIGN KEY (POST_ID) REFERENCES POSTS (ID) ON DELETE CASCADE ON UPDATE CASCADE;
|
add constraint fk_posts_media_post_id__id foreign key (post_id) references posts (id) on delete cascade on update cascade;
|
||||||
ALTER TABLE POSTS_MEDIA
|
alter table posts_media
|
||||||
ADD CONSTRAINT FK_POSTS_MEDIA_MEDIA_ID__ID FOREIGN KEY (MEDIA_ID) REFERENCES MEDIA (ID) ON DELETE CASCADE ON UPDATE CASCADE;
|
add constraint fk_posts_media_media_id__id foreign key (media_id) references media (id) on delete cascade on update cascade;
|
||||||
CREATE TABLE IF NOT EXISTS REACTIONS
|
create table if not exists reactions
|
||||||
(
|
(
|
||||||
ID BIGSERIAL PRIMARY KEY,
|
id bigserial primary key,
|
||||||
EMOJI_ID BIGINT NOT NULL,
|
emoji_id bigint not null,
|
||||||
POST_ID BIGINT NOT NULL,
|
post_id bigint not null,
|
||||||
USER_ID BIGINT NOT NULL
|
user_id bigint not null
|
||||||
);
|
);
|
||||||
ALTER TABLE REACTIONS
|
alter table reactions
|
||||||
ADD CONSTRAINT FK_REACTIONS_POST_ID__ID FOREIGN KEY (POST_ID) REFERENCES POSTS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
add constraint fk_reactions_post_id__id foreign key (post_id) references posts (id) on delete restrict on update restrict;
|
||||||
ALTER TABLE REACTIONS
|
alter table reactions
|
||||||
ADD CONSTRAINT FK_REACTIONS_USER_ID__ID FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
add constraint fk_reactions_user_id__id foreign key (user_id) references users (id) on delete restrict on update restrict;
|
||||||
CREATE TABLE IF NOT EXISTS TIMELINES
|
create table if not exists timelines
|
||||||
(
|
(
|
||||||
ID BIGINT PRIMARY KEY,
|
id bigint primary key,
|
||||||
USER_ID BIGINT NOT NULL,
|
user_id bigint not null,
|
||||||
TIMELINE_ID BIGINT NOT NULL,
|
timeline_id bigint not null,
|
||||||
POST_ID BIGINT NOT NULL,
|
post_id bigint not null,
|
||||||
POST_USER_ID BIGINT NOT NULL,
|
post_user_id bigint not null,
|
||||||
CREATED_AT BIGINT NOT NULL,
|
created_at bigint not null,
|
||||||
REPLY_ID BIGINT NULL,
|
reply_id bigint null,
|
||||||
REPOST_ID BIGINT NULL,
|
repost_id bigint null,
|
||||||
VISIBILITY INT NOT NULL,
|
visibility int not null,
|
||||||
"SENSITIVE" BOOLEAN NOT NULL,
|
"sensitive" boolean not null,
|
||||||
IS_LOCAL BOOLEAN NOT NULL,
|
is_local boolean not null,
|
||||||
IS_PURE_REPOST BOOLEAN NOT NULL,
|
is_pure_repost boolean not null,
|
||||||
MEDIA_IDS VARCHAR(255) NOT NULL
|
media_ids varchar(255) not null
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS USERS_FOLLOWERS
|
create table if not exists users_followers
|
||||||
(
|
(
|
||||||
ID BIGSERIAL PRIMARY KEY,
|
id bigserial primary key,
|
||||||
USER_ID BIGINT NOT NULL,
|
user_id bigint not null,
|
||||||
FOLLOWER_ID BIGINT NOT NULL,
|
follower_id bigint not null,
|
||||||
CONSTRAINT FK_USERS_FOLLOWERS_USER_ID__ID FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
constraint fk_users_followers_user_id__id foreign key (user_id) references users (id) on delete restrict on update restrict,
|
||||||
CONSTRAINT FK_USERS_FOLLOWERS_FOLLOWER_ID__ID FOREIGN KEY (FOLLOWER_ID) REFERENCES USERS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT
|
constraint fk_users_followers_follower_id__id foreign key (follower_id) references users (id) on delete restrict on update restrict
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS APPLICATION_AUTHORIZATION
|
create table if not exists application_authorization
|
||||||
(
|
(
|
||||||
ID VARCHAR(255) PRIMARY KEY,
|
id varchar(255) primary key,
|
||||||
REGISTERED_CLIENT_ID VARCHAR(255) NOT NULL,
|
registered_client_id varchar(255) not null,
|
||||||
PRINCIPAL_NAME VARCHAR(255) NOT NULL,
|
principal_name varchar(255) not null,
|
||||||
AUTHORIZATION_GRANT_TYPE VARCHAR(255) NOT NULL,
|
authorization_grant_type varchar(255) not null,
|
||||||
AUTHORIZED_SCOPES VARCHAR(1000) DEFAULT NULL NULL,
|
authorized_scopes varchar(1000) default null null,
|
||||||
"ATTRIBUTES" VARCHAR(4000) DEFAULT NULL NULL,
|
"attributes" varchar(4000) default null null,
|
||||||
"STATE" VARCHAR(500) DEFAULT NULL NULL,
|
"state" varchar(500) default null null,
|
||||||
AUTHORIZATION_CODE_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
authorization_code_value varchar(4000) default null null,
|
||||||
AUTHORIZATION_CODE_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
authorization_code_issued_at timestamp default null null,
|
||||||
AUTHORIZATION_CODE_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
authorization_code_expires_at timestamp default null null,
|
||||||
AUTHORIZATION_CODE_METADATA VARCHAR(2000) DEFAULT NULL NULL,
|
authorization_code_metadata varchar(2000) default null null,
|
||||||
ACCESS_TOKEN_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
access_token_value varchar(4000) default null null,
|
||||||
ACCESS_TOKEN_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
access_token_issued_at timestamp default null null,
|
||||||
ACCESS_TOKEN_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
access_token_expires_at timestamp default null null,
|
||||||
ACCESS_TOKEN_METADATA VARCHAR(2000) DEFAULT NULL NULL,
|
access_token_metadata varchar(2000) default null null,
|
||||||
ACCESS_TOKEN_TYPE VARCHAR(255) DEFAULT NULL NULL,
|
access_token_type varchar(255) default null null,
|
||||||
ACCESS_TOKEN_SCOPES VARCHAR(1000) DEFAULT NULL NULL,
|
access_token_scopes varchar(1000) default null null,
|
||||||
REFRESH_TOKEN_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
refresh_token_value varchar(4000) default null null,
|
||||||
REFRESH_TOKEN_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
refresh_token_issued_at timestamp default null null,
|
||||||
REFRESH_TOKEN_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
refresh_token_expires_at timestamp default null null,
|
||||||
REFRESH_TOKEN_METADATA VARCHAR(2000) DEFAULT NULL NULL,
|
refresh_token_metadata varchar(2000) default null null,
|
||||||
OIDC_ID_TOKEN_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
oidc_id_token_value varchar(4000) default null null,
|
||||||
OIDC_ID_TOKEN_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
oidc_id_token_issued_at timestamp default null null,
|
||||||
OIDC_ID_TOKEN_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
oidc_id_token_expires_at timestamp default null null,
|
||||||
OIDC_ID_TOKEN_METADATA VARCHAR(2000) DEFAULT NULL NULL,
|
oidc_id_token_metadata varchar(2000) default null null,
|
||||||
OIDC_ID_TOKEN_CLAIMS VARCHAR(2000) DEFAULT NULL NULL,
|
oidc_id_token_claims varchar(2000) default null null,
|
||||||
USER_CODE_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
user_code_value varchar(4000) default null null,
|
||||||
USER_CODE_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
user_code_issued_at timestamp default null null,
|
||||||
USER_CODE_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
user_code_expires_at timestamp default null null,
|
||||||
USER_CODE_METADATA VARCHAR(2000) DEFAULT NULL NULL,
|
user_code_metadata varchar(2000) default null null,
|
||||||
DEVICE_CODE_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
device_code_value varchar(4000) default null null,
|
||||||
DEVICE_CODE_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
device_code_issued_at timestamp default null null,
|
||||||
DEVICE_CODE_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
device_code_expires_at timestamp default null null,
|
||||||
DEVICE_CODE_METADATA VARCHAR(2000) DEFAULT NULL NULL
|
device_code_metadata varchar(2000) default null null
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS OAUTH2_AUTHORIZATION_CONSENT
|
create table if not exists oauth2_authorization_consent
|
||||||
(
|
(
|
||||||
REGISTERED_CLIENT_ID VARCHAR(100),
|
registered_client_id varchar(100),
|
||||||
PRINCIPAL_NAME VARCHAR(200),
|
principal_name varchar(200),
|
||||||
AUTHORITIES VARCHAR(1000) NOT NULL,
|
authorities varchar(1000) not null,
|
||||||
CONSTRAINT pk_oauth2_authorization_consent PRIMARY KEY (REGISTERED_CLIENT_ID, PRINCIPAL_NAME)
|
constraint pk_oauth2_authorization_consent primary key (registered_client_id, principal_name)
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS REGISTERED_CLIENT
|
create table if not exists registered_client
|
||||||
(
|
(
|
||||||
ID VARCHAR(100) PRIMARY KEY,
|
id varchar(100) primary key,
|
||||||
CLIENT_ID VARCHAR(100) NOT NULL,
|
client_id varchar(100) not null,
|
||||||
CLIENT_ID_ISSUED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
client_id_issued_at timestamp default current_timestamp not null,
|
||||||
CLIENT_SECRET VARCHAR(200) DEFAULT NULL NULL,
|
client_secret varchar(200) default null null,
|
||||||
CLIENT_SECRET_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
client_secret_expires_at timestamp default null null,
|
||||||
CLIENT_NAME VARCHAR(200) NOT NULL,
|
client_name varchar(200) not null,
|
||||||
CLIENT_AUTHENTICATION_METHODS VARCHAR(1000) NOT NULL,
|
client_authentication_methods varchar(1000) not null,
|
||||||
AUTHORIZATION_GRANT_TYPES VARCHAR(1000) NOT NULL,
|
authorization_grant_types varchar(1000) not null,
|
||||||
REDIRECT_URIS VARCHAR(1000) DEFAULT NULL NULL,
|
redirect_uris varchar(1000) default null null,
|
||||||
POST_LOGOUT_REDIRECT_URIS VARCHAR(1000) DEFAULT NULL NULL,
|
post_logout_redirect_uris varchar(1000) default null null,
|
||||||
SCOPES VARCHAR(1000) NOT NULL,
|
scopes varchar(1000) not null,
|
||||||
CLIENT_SETTINGS VARCHAR(2000) NOT NULL,
|
client_settings varchar(2000) not null,
|
||||||
TOKEN_SETTINGS VARCHAR(2000) NOT NULL
|
token_settings varchar(2000) not null
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue