forked from gotson/komga
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
existing fields moved from book to series: publisher, age rating, reading direction new book fields: tags new series fields: tags, genres, language, summary closes gotson#276
- Loading branch information
Showing
37 changed files
with
1,087 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
komga/src/flyway/kotlin/db/migration/sqlite/V20200820150923__metadata_fields_part_2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package db.migration.sqlite | ||
|
||
import org.flywaydb.core.api.migration.BaseJavaMigration | ||
import org.flywaydb.core.api.migration.Context | ||
import org.springframework.jdbc.core.JdbcTemplate | ||
import org.springframework.jdbc.datasource.SingleConnectionDataSource | ||
|
||
class V20200820150923__metadata_fields_part_2 : BaseJavaMigration() { | ||
override fun migrate(context: Context) { | ||
val jdbcTemplate = JdbcTemplate(SingleConnectionDataSource(context.connection, true)) | ||
|
||
val bookMetadata = jdbcTemplate.queryForList( | ||
"""select m.AGE_RATING, m.AGE_RATING_LOCK, m.PUBLISHER, m.PUBLISHER_LOCK, m.READING_DIRECTION, m.READING_DIRECTION_LOCK, b.SERIES_ID, m.NUMBER_SORT | ||
from BOOK_METADATA m | ||
left join BOOK B on B.ID = m.BOOK_ID""" | ||
) | ||
|
||
if (bookMetadata.isNotEmpty()) { | ||
val parameters = bookMetadata | ||
.groupBy { it["SERIES_ID"] } | ||
.map { (seriesId, v) -> | ||
val ageRating = v.mapNotNull { it["AGE_RATING"] as Int? }.max() | ||
val ageRatingLock = v.mapNotNull { it["AGE_RATING_LOCK"] as Int? }.max() | ||
|
||
val publisher = | ||
v.filter { (it["PUBLISHER"] as String).isNotEmpty() } | ||
.sortedByDescending { it["NUMBER_SORT"] as Double? } | ||
.map { it["PUBLISHER"] as String } | ||
.firstOrNull() | ||
val publisherLock = v.mapNotNull { it["PUBLISHER_LOCK"] as Int? }.max() | ||
|
||
val readingDir = | ||
v.mapNotNull { it["READING_DIRECTION"] as String? } | ||
.groupingBy { it } | ||
.eachCount() | ||
.maxBy { it.value }?.key | ||
val readingDirLock = v.mapNotNull { it["READING_DIRECTION_LOCK"] as Int? }.max() | ||
|
||
arrayOf(ageRating, ageRatingLock, publisher, publisherLock, readingDir, readingDirLock, seriesId) | ||
} | ||
|
||
jdbcTemplate.batchUpdate( | ||
"UPDATE SERIES_METADATA SET AGE_RATING = ?, AGE_RATING_LOCK = ?, PUBLISHER = ?, PUBLISHER_LOCK = ?, READING_DIRECTION = ?, READING_DIRECTION_LOCK = ? WHERE SERIES_ID = ?", | ||
parameters | ||
) | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
komga/src/flyway/resources/db/migration/sqlite/V20200820141405__metadata_fields_part_1.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
alter table series_metadata | ||
add column PUBLISHER varchar NOT NULL DEFAULT ''; | ||
alter table series_metadata | ||
add column PUBLISHER_LOCK boolean NOT NULL DEFAULT 0; | ||
|
||
alter table series_metadata | ||
add column READING_DIRECTION varchar NULL; | ||
alter table series_metadata | ||
add column READING_DIRECTION_LOCK boolean NOT NULL DEFAULT 0; | ||
|
||
alter table series_metadata | ||
add column AGE_RATING int NULL; | ||
alter table series_metadata | ||
add column AGE_RATING_LOCK boolean NOT NULL DEFAULT 0; | ||
|
||
alter table SERIES_METADATA | ||
add column SUMMARY varchar NOT NULL DEFAULT ''; | ||
alter table SERIES_METADATA | ||
add column SUMMARY_LOCK boolean NOT NULL DEFAULT 0; | ||
|
||
alter table SERIES_METADATA | ||
add column LANGUAGE varchar NOT NULL DEFAULT ''; | ||
alter table SERIES_METADATA | ||
add column LANGUAGE_LOCK boolean NOT NULL DEFAULT 0; | ||
|
||
alter table SERIES_METADATA | ||
add column GENRES_LOCK boolean NOT NULL DEFAULT 0; | ||
|
||
alter table SERIES_METADATA | ||
add column TAGS_LOCK boolean NOT NULL DEFAULT 0; | ||
|
||
|
||
CREATE TABLE SERIES_METADATA_GENRE | ||
( | ||
GENRE varchar NOT NULL, | ||
SERIES_ID varchar NOT NULL, | ||
FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) | ||
); | ||
|
||
CREATE TABLE SERIES_METADATA_TAG | ||
( | ||
TAG varchar NOT NULL, | ||
SERIES_ID varchar NOT NULL, | ||
FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) | ||
); | ||
|
||
CREATE TABLE BOOK_METADATA_TAG | ||
( | ||
TAG varchar NOT NULL, | ||
BOOK_ID varchar NOT NULL, | ||
FOREIGN KEY (BOOK_ID) REFERENCES BOOK (ID) | ||
); |
47 changes: 47 additions & 0 deletions
47
komga/src/flyway/resources/db/migration/sqlite/V20200820154318__metadata_fields_part_3.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
PRAGMA foreign_keys= OFF; | ||
|
||
ALTER TABLE BOOK_METADATA | ||
RENAME TO _BOOK_METADATA_OLD; | ||
|
||
CREATE TABLE BOOK_METADATA | ||
( | ||
CREATED_DATE datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
LAST_MODIFIED_DATE datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
NUMBER varchar NOT NULL, | ||
NUMBER_LOCK boolean NOT NULL DEFAULT 0, | ||
NUMBER_SORT real NOT NULL, | ||
NUMBER_SORT_LOCK boolean NOT NULL DEFAULT 0, | ||
RELEASE_DATE date NULL, | ||
RELEASE_DATE_LOCK boolean NOT NULL DEFAULT 0, | ||
SUMMARY varchar NOT NULL DEFAULT '', | ||
SUMMARY_LOCK boolean NOT NULL DEFAULT 0, | ||
TITLE varchar NOT NULL, | ||
TITLE_LOCK boolean NOT NULL DEFAULT 0, | ||
AUTHORS_LOCK boolean NOT NULL DEFAULT 0, | ||
TAGS_LOCK boolean NOT NULL DEFAULT 0, | ||
BOOK_ID varchar NOT NULL PRIMARY KEY, | ||
FOREIGN KEY (BOOK_ID) REFERENCES BOOK (ID) | ||
); | ||
|
||
INSERT INTO BOOK_METADATA (CREATED_DATE, LAST_MODIFIED_DATE, NUMBER, NUMBER_LOCK, NUMBER_SORT, NUMBER_SORT_LOCK, | ||
RELEASE_DATE, RELEASE_DATE_LOCK, SUMMARY, SUMMARY_LOCK, TITLE, TITLE_LOCK, AUTHORS_LOCK, | ||
BOOK_ID) | ||
SELECT CREATED_DATE, | ||
LAST_MODIFIED_DATE, | ||
NUMBER, | ||
NUMBER_LOCK, | ||
NUMBER_SORT, | ||
NUMBER_SORT_LOCK, | ||
RELEASE_DATE, | ||
RELEASE_DATE_LOCK, | ||
SUMMARY, | ||
SUMMARY_LOCK, | ||
TITLE, | ||
TITLE_LOCK, | ||
AUTHORS_LOCK, | ||
BOOK_ID | ||
FROM _BOOK_METADATA_OLD; | ||
|
||
DROP TABLE _BOOK_METADATA_OLD; | ||
|
||
PRAGMA foreign_keys= ON; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
komga/src/main/kotlin/org/gotson/komga/domain/persistence/ReferentialRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.gotson.komga.domain.persistence | ||
|
||
interface ReferentialRepository { | ||
fun findAuthorsByName(search: String): List<String> | ||
fun findAllGenres(): Set<String> | ||
fun findAllTags(): Set<String> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.