mirror of https://github.com/usbharu/Hideout.git
feat: DBのマイグレーションをFlywayで行うように
This commit is contained in:
parent
f2ab68adcb
commit
ff0416ee83
|
@ -182,6 +182,7 @@ dependencies {
|
|||
implementation("org.apache.tika:tika-core:2.9.1")
|
||||
implementation("net.coobird:thumbnailator:0.4.20")
|
||||
implementation("org.bytedeco:javacv-platform:1.5.9")
|
||||
implementation("org.flywaydb:flyway-core")
|
||||
|
||||
implementation("io.ktor:ktor-client-logging-jvm:$ktor_version")
|
||||
|
||||
|
|
|
@ -75,20 +75,20 @@ class PostRepositoryImpl(
|
|||
|
||||
object Posts : Table() {
|
||||
val id: Column<Long> = long("id")
|
||||
val userId: Column<Long> = long("userId").references(Users.id)
|
||||
val userId: Column<Long> = long("user_id").references(Users.id)
|
||||
val overview: Column<String?> = varchar("overview", 100).nullable()
|
||||
val text: Column<String> = varchar("text", 3000)
|
||||
val createdAt: Column<Long> = long("createdAt")
|
||||
val createdAt: Column<Long> = long("created_at")
|
||||
val visibility: Column<Int> = integer("visibility").default(0)
|
||||
val url: Column<String> = varchar("url", 500)
|
||||
val repostId: Column<Long?> = long("repostId").references(id).nullable()
|
||||
val replyId: Column<Long?> = long("replyId").references(id).nullable()
|
||||
val repostId: Column<Long?> = long("repost_id").references(id).nullable()
|
||||
val replyId: Column<Long?> = long("reply_id").references(id).nullable()
|
||||
val sensitive: Column<Boolean> = bool("sensitive").default(false)
|
||||
val apId: Column<String> = varchar("ap_id", 100).uniqueIndex()
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
||||
object PostsMedia : Table() {
|
||||
object PostsMedia : Table("posts_media") {
|
||||
val postId = long("post_id").references(Posts.id, ReferenceOption.CASCADE, ReferenceOption.CASCADE)
|
||||
val mediaId = long("media_id").references(Media.id, ReferenceOption.CASCADE, ReferenceOption.CASCADE)
|
||||
override val primaryKey = PrimaryKey(postId, mediaId)
|
||||
|
|
|
@ -19,7 +19,7 @@ spring:
|
|||
default-property-inclusion: always
|
||||
datasource:
|
||||
driver-class-name: org.h2.Driver
|
||||
url: "jdbc:h2:./test-dev3;MODE=POSTGRESQL;TRACE_LEVEL_FILE=4"
|
||||
url: "jdbc:h2:./test-dev4;MODE=POSTGRESQL;TRACE_LEVEL_FILE=4"
|
||||
username: ""
|
||||
password: ""
|
||||
# data:
|
||||
|
@ -37,9 +37,6 @@ spring:
|
|||
h2:
|
||||
console:
|
||||
enabled: true
|
||||
exposed:
|
||||
generate-ddl: true
|
||||
excluded-packages: dev.usbharu.hideout.core.infrastructure.kjobexposed
|
||||
server:
|
||||
tomcat:
|
||||
basedir: tomcat
|
||||
|
|
|
@ -0,0 +1,188 @@
|
|||
CREATE TABLE IF NOT EXISTS "INSTANCE"
|
||||
(
|
||||
ID BIGINT PRIMARY KEY,
|
||||
"NAME" VARCHAR(1000) NOT NULL,
|
||||
DESCRIPTION VARCHAR(5000) NOT NULL,
|
||||
URL VARCHAR(255) NOT NULL,
|
||||
ICON_URL VARCHAR(255) NOT NULL,
|
||||
SHARED_INBOX VARCHAR(255) NULL,
|
||||
SOFTWARE VARCHAR(255) NOT NULL,
|
||||
VERSION VARCHAR(255) NOT NULL,
|
||||
IS_BLOCKED BOOLEAN NOT NULL,
|
||||
IS_MUTED BOOLEAN NOT NULL,
|
||||
MODERATION_NOTE VARCHAR(10000) NOT NULL,
|
||||
CREATED_AT TIMESTAMP NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS USERS
|
||||
(
|
||||
ID BIGINT PRIMARY KEY,
|
||||
"NAME" VARCHAR(300) NOT NULL,
|
||||
"DOMAIN" VARCHAR(1000) NOT NULL,
|
||||
SCREEN_NAME VARCHAR(300) NOT NULL,
|
||||
DESCRIPTION VARCHAR(10000) NOT NULL,
|
||||
PASSWORD VARCHAR(255) NULL,
|
||||
INBOX VARCHAR(1000) NOT NULL,
|
||||
OUTBOX VARCHAR(1000) NOT NULL,
|
||||
URL VARCHAR(1000) NOT NULL,
|
||||
PUBLIC_KEY VARCHAR(10000) NOT NULL,
|
||||
PRIVATE_KEY VARCHAR(10000) NULL,
|
||||
CREATED_AT BIGINT NOT NULL,
|
||||
KEY_ID VARCHAR(1000) NOT NULL,
|
||||
"FOLLOWING" VARCHAR(1000) NULL,
|
||||
FOLLOWERS VARCHAR(1000) NULL,
|
||||
"INSTANCE" BIGINT NULL,
|
||||
CONSTRAINT FK_USERS_INSTANCE__ID FOREIGN KEY ("INSTANCE") REFERENCES "INSTANCE" (ID) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS FOLLOW_REQUESTS
|
||||
(
|
||||
ID BIGSERIAL PRIMARY KEY,
|
||||
USER_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_FOLLOWER_ID__ID FOREIGN KEY (FOLLOWER_ID) REFERENCES USERS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS MEDIA
|
||||
(
|
||||
ID BIGINT PRIMARY KEY,
|
||||
"NAME" VARCHAR(255) NOT NULL,
|
||||
URL VARCHAR(255) NOT NULL,
|
||||
REMOTE_URL VARCHAR(255) NULL,
|
||||
THUMBNAIL_URL VARCHAR(255) NULL,
|
||||
"TYPE" INT NOT NULL,
|
||||
BLURHASH VARCHAR(255) NULL,
|
||||
MIME_TYPE VARCHAR(255) NOT NULL,
|
||||
DESCRIPTION VARCHAR(4000) NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS META_INFO
|
||||
(
|
||||
ID BIGINT PRIMARY KEY,
|
||||
VERSION VARCHAR(1000) NOT NULL,
|
||||
KID VARCHAR(1000) NOT NULL,
|
||||
JWT_PRIVATE_KEY VARCHAR(100000) NOT NULL,
|
||||
JWT_PUBLIC_KEY VARCHAR(100000) NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS POSTS
|
||||
(
|
||||
ID BIGINT PRIMARY KEY,
|
||||
USER_ID BIGINT NOT NULL,
|
||||
OVERVIEW VARCHAR(100) NULL,
|
||||
TEXT VARCHAR(3000) NOT NULL,
|
||||
CREATED_AT BIGINT NOT NULL,
|
||||
VISIBILITY INT DEFAULT 0 NOT NULL,
|
||||
URL VARCHAR(500) NOT NULL,
|
||||
REPOST_ID BIGINT NULL,
|
||||
REPLY_ID BIGINT NULL,
|
||||
"SENSITIVE" BOOLEAN DEFAULT FALSE NOT NULL,
|
||||
AP_ID VARCHAR(100) NOT NULL
|
||||
);
|
||||
ALTER TABLE POSTS
|
||||
ADD CONSTRAINT FK_POSTS_USERID__ID FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
||||
ALTER TABLE POSTS
|
||||
ADD CONSTRAINT FK_POSTS_REPOSTID__ID FOREIGN KEY (REPOST_ID) REFERENCES POSTS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
||||
ALTER TABLE POSTS
|
||||
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
|
||||
(
|
||||
POST_ID BIGINT,
|
||||
MEDIA_ID BIGINT,
|
||||
CONSTRAINT pk_PostsMedia PRIMARY KEY (POST_ID, MEDIA_ID)
|
||||
);
|
||||
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;
|
||||
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;
|
||||
CREATE TABLE IF NOT EXISTS REACTIONS
|
||||
(
|
||||
ID BIGSERIAL PRIMARY KEY,
|
||||
EMOJI_ID BIGINT NOT NULL,
|
||||
POST_ID BIGINT NOT NULL,
|
||||
USER_ID BIGINT NOT NULL
|
||||
);
|
||||
ALTER TABLE REACTIONS
|
||||
ADD CONSTRAINT FK_REACTIONS_POST_ID__ID FOREIGN KEY (POST_ID) REFERENCES POSTS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
||||
ALTER TABLE REACTIONS
|
||||
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
|
||||
(
|
||||
ID BIGINT PRIMARY KEY,
|
||||
USER_ID BIGINT NOT NULL,
|
||||
TIMELINE_ID BIGINT NOT NULL,
|
||||
POST_ID BIGINT NOT NULL,
|
||||
POST_USER_ID BIGINT NOT NULL,
|
||||
CREATED_AT BIGINT NOT NULL,
|
||||
REPLY_ID BIGINT NULL,
|
||||
REPOST_ID BIGINT NULL,
|
||||
VISIBILITY INT NOT NULL,
|
||||
"SENSITIVE" BOOLEAN NOT NULL,
|
||||
IS_LOCAL BOOLEAN NOT NULL,
|
||||
IS_PURE_REPOST BOOLEAN NOT NULL,
|
||||
MEDIA_IDS VARCHAR(255) NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS USERS_FOLLOWERS
|
||||
(
|
||||
ID BIGSERIAL PRIMARY KEY,
|
||||
USER_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_FOLLOWER_ID__ID FOREIGN KEY (FOLLOWER_ID) REFERENCES USERS (ID) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS APPLICATION_AUTHORIZATION
|
||||
(
|
||||
ID VARCHAR(255) PRIMARY KEY,
|
||||
REGISTERED_CLIENT_ID VARCHAR(255) NOT NULL,
|
||||
PRINCIPAL_NAME VARCHAR(255) NOT NULL,
|
||||
AUTHORIZATION_GRANT_TYPE VARCHAR(255) NOT NULL,
|
||||
AUTHORIZED_SCOPES VARCHAR(1000) DEFAULT NULL NULL,
|
||||
"ATTRIBUTES" VARCHAR(4000) DEFAULT NULL NULL,
|
||||
"STATE" VARCHAR(500) DEFAULT NULL NULL,
|
||||
AUTHORIZATION_CODE_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
||||
AUTHORIZATION_CODE_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
AUTHORIZATION_CODE_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
AUTHORIZATION_CODE_METADATA VARCHAR(2000) DEFAULT NULL NULL,
|
||||
ACCESS_TOKEN_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
||||
ACCESS_TOKEN_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
ACCESS_TOKEN_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
ACCESS_TOKEN_METADATA VARCHAR(2000) DEFAULT NULL NULL,
|
||||
ACCESS_TOKEN_TYPE VARCHAR(255) DEFAULT NULL NULL,
|
||||
ACCESS_TOKEN_SCOPES VARCHAR(1000) DEFAULT NULL NULL,
|
||||
REFRESH_TOKEN_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
||||
REFRESH_TOKEN_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
REFRESH_TOKEN_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
REFRESH_TOKEN_METADATA VARCHAR(2000) DEFAULT NULL NULL,
|
||||
OIDC_ID_TOKEN_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
||||
OIDC_ID_TOKEN_ISSUED_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_CLAIMS VARCHAR(2000) DEFAULT NULL NULL,
|
||||
USER_CODE_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
||||
USER_CODE_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
USER_CODE_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
USER_CODE_METADATA VARCHAR(2000) DEFAULT NULL NULL,
|
||||
DEVICE_CODE_VALUE VARCHAR(4000) DEFAULT NULL NULL,
|
||||
DEVICE_CODE_ISSUED_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
DEVICE_CODE_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
DEVICE_CODE_METADATA VARCHAR(2000) DEFAULT NULL NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS OAUTH2_AUTHORIZATION_CONSENT
|
||||
(
|
||||
REGISTERED_CLIENT_ID VARCHAR(100),
|
||||
PRINCIPAL_NAME VARCHAR(200),
|
||||
AUTHORITIES VARCHAR(1000) NOT NULL,
|
||||
CONSTRAINT pk_oauth2_authorization_consent PRIMARY KEY (REGISTERED_CLIENT_ID, PRINCIPAL_NAME)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS REGISTERED_CLIENT
|
||||
(
|
||||
ID VARCHAR(100) PRIMARY KEY,
|
||||
CLIENT_ID VARCHAR(100) NOT NULL,
|
||||
CLIENT_ID_ISSUED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
CLIENT_SECRET VARCHAR(200) DEFAULT NULL NULL,
|
||||
CLIENT_SECRET_EXPIRES_AT TIMESTAMP DEFAULT NULL NULL,
|
||||
CLIENT_NAME VARCHAR(200) NOT NULL,
|
||||
CLIENT_AUTHENTICATION_METHODS VARCHAR(1000) NOT NULL,
|
||||
AUTHORIZATION_GRANT_TYPES VARCHAR(1000) NOT NULL,
|
||||
REDIRECT_URIS VARCHAR(1000) DEFAULT NULL NULL,
|
||||
POST_LOGOUT_REDIRECT_URIS VARCHAR(1000) DEFAULT NULL NULL,
|
||||
SCOPES VARCHAR(1000) NOT NULL,
|
||||
CLIENT_SETTINGS VARCHAR(2000) NOT NULL,
|
||||
TOKEN_SETTINGS VARCHAR(2000) NOT NULL
|
||||
)
|
Loading…
Reference in New Issue