added flyway for db migrations

This commit is contained in:
Gauthier Roebroeck 2019-08-19 17:56:26 +08:00
parent fbb93b7266
commit 1c674916ce
12 changed files with 80 additions and 33 deletions

View file

@ -1,26 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="komga [bootRun] localdb,dev" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="SPRING_PROFILES_ACTIVE" value="localdb,dev" />
</map>
</option>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="bootRun" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled>
<method v="2" />
</configuration>
</component>

View file

@ -38,6 +38,8 @@ dependencies {
kapt("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.flywaydb:flyway-core:5.2.4")
// implementation("com.github.ben-manes.caffeine:caffeine:2.7.0")
implementation("io.github.microutils:kotlin-logging:1.6.26")

View file

@ -33,7 +33,7 @@ class Book(
) {
@Id
@GeneratedValue
@Column(name = "id", nullable = false, unique = true)
@Column(name = "id", nullable = false)
@PrimaryKeyJoinColumn
var id: Long = 0

View file

@ -39,8 +39,7 @@ class BookMetadata(
lateinit var book: Book
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "book_metadata_pages", joinColumns = [JoinColumn(name = "book_metadata_id")])
@Column(name = "pages")
@CollectionTable(name = "book_metadata_page", joinColumns = [JoinColumn(name = "book_metadata_id")])
private val _pages: MutableList<BookPage> = mutableListOf()
val pages: List<BookPage>

View file

@ -2,3 +2,6 @@
komga:
root-folder: D:\\files
# root-folder-scan-cron: 0 0 * * * ?
spring:
profiles:
include: flyway

View file

@ -0,0 +1,6 @@
spring:
flyway:
enabled: true
jpa:
hibernate:
ddl-auto: validate

View file

@ -2,6 +2,8 @@ spring:
flyway:
enabled: false
jpa:
hibernate:
ddl-auto: none
properties:
javax:
persistence:

View file

@ -1,6 +1,4 @@
spring:
datasource:
url: jdbc:h2:./testdb;DB_CLOSE_DELAY=-1
jpa:
hibernate:
ddl-auto: update

View file

@ -0,0 +1,6 @@
spring:
flyway:
enabled: false
jpa:
hibernate:
ddl-auto: create

View file

@ -0,0 +1,3 @@
spring:
profiles:
include: flyway

View file

@ -0,0 +1,49 @@
create sequence hibernate_sequence start with 1 increment by 1;
create table book
(
id bigint generated by default as identity,
name varchar not null,
updated timestamp not null,
url varchar not null,
book_metadata_id bigint not null,
serie_id bigint not null,
primary key (id)
);
create table book_metadata
(
id bigint generated by default as identity,
media_type varchar,
status varchar not null,
thumbnail blob,
primary key (id)
);
create table book_metadata_page
(
book_metadata_id bigint not null,
file_name varchar not null,
media_type varchar not null
);
create table serie
(
id bigint generated by default as identity,
name varchar not null,
updated timestamp not null,
url varchar not null,
primary key (id)
);
alter table book
add constraint uk_book_book_metadata_id unique (book_metadata_id);
alter table book
add constraint fk_book_book_metadata_book_metadata_id foreign key (book_metadata_id) references book_metadata (id);
alter table book
add constraint fk_book_serie_serie_id foreign key (serie_id) references serie (id);
alter table book_metadata_page
add constraint fk_book_metadata_page_book_metadata_book_metadata_id foreign key (book_metadata_id) references book_metadata (id);

View file

@ -1,6 +1,11 @@
application.version: TESTING
spring:
flyway:
enabled: true
jpa:
hibernate:
ddl-auto: validate
jpa:
properties:
hibernate: