-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updatable via API linked to #48
- Loading branch information
Showing
9 changed files
with
168 additions
and
44 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
komga/src/main/kotlin/db/migration/V20200121154334__create_series_metadata_from_series.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,23 @@ | ||
package db.migration | ||
|
||
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 | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
class V20200121154334__create_series_metadata_from_series : BaseJavaMigration() { | ||
override fun migrate(context: Context) { | ||
val jdbcTemplate = JdbcTemplate(SingleConnectionDataSource(context.connection, true)) | ||
|
||
val seriesIds = jdbcTemplate.queryForList("SELECT id FROM series", Long::class.java) | ||
|
||
val now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")) | ||
seriesIds.forEach { seriesId -> | ||
val metadataId = jdbcTemplate.queryForObject("SELECT NEXTVAL('hibernate_sequence')", Int::class.java) | ||
jdbcTemplate.execute("INSERT INTO series_metadata (ID, CREATED_DATE, LAST_MODIFIED_DATE, STATUS) VALUES ($metadataId, '$now', '$now', 'ONGOING')") | ||
jdbcTemplate.execute("UPDATE series SET metadata_id = $metadataId WHERE id = $seriesId") | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
komga/src/main/kotlin/org/gotson/komga/domain/model/SeriesMetadata.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,32 @@ | ||
package org.gotson.komga.domain.model | ||
|
||
import org.hibernate.annotations.Cache | ||
import org.hibernate.annotations.CacheConcurrencyStrategy | ||
import javax.persistence.Cacheable | ||
import javax.persistence.Column | ||
import javax.persistence.Entity | ||
import javax.persistence.EnumType | ||
import javax.persistence.Enumerated | ||
import javax.persistence.GeneratedValue | ||
import javax.persistence.Id | ||
import javax.persistence.Table | ||
|
||
@Entity | ||
@Table(name = "series_metadata") | ||
@Cacheable | ||
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "cache.series_metadata") | ||
class SeriesMetadata( | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "status", nullable = false) | ||
var status: Status = Status.ONGOING | ||
|
||
) : AuditableEntity() { | ||
@Id | ||
@GeneratedValue | ||
@Column(name = "id", nullable = false, unique = true) | ||
val id: Long = 0 | ||
|
||
enum class Status { | ||
ENDED, ONGOING, ABANDONED, HIATUS | ||
} | ||
} |
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/interfaces/rest/dto/SeriesMetadataUpdateDto.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.interfaces.rest.dto | ||
|
||
import org.gotson.komga.domain.model.SeriesMetadata | ||
|
||
data class SeriesMetadataUpdateDto( | ||
val status: SeriesMetadata.Status? | ||
) |
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
15 changes: 15 additions & 0 deletions
15
komga/src/main/resources/db/migration/V20200121153351__series_metadata.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,15 @@ | ||
create table series_metadata | ||
( | ||
id bigint not null, | ||
created_date timestamp not null, | ||
last_modified_date timestamp not null, | ||
status varchar not null, | ||
primary key (id) | ||
); | ||
|
||
alter table series | ||
add (metadata_id bigint); | ||
|
||
alter table series | ||
add constraint fk_series_series_metadata_metadata_id foreign key (metadata_id) references series_metadata (id); | ||
|
2 changes: 2 additions & 0 deletions
2
komga/src/main/resources/db/migration/V20200121154845__series_metadata_id_not_null.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,2 @@ | ||
alter table series | ||
alter column metadata_id set not null; |