Skip to content

Commit

Permalink
feat: change database from H2 to SQLite
Browse files Browse the repository at this point in the history
This is a major change, but done transparently.

At startup, a migration from H2 to SQLite will be triggered:
- if the H2 database is a file (not in memory)
- if the H2 database has not been migrated yet
- if the SQLite database is newly minted

All the data will be transferred from H2 to SQLite before the startup of the application (before the API can serve any requests).
After the migration, an empty file will be stored next to the H2 database file (same name with ".imported" suffix).

The H2 database files will be automatically removed in a later version.

A new configuration key is available to customize the file path of the SQLite database: `komga.database.file`

The database backup feature has been removed. It might be re-added later on using a different logic.

The IDs of entities have been changed from number to string in the API.

closes gotson#218
  • Loading branch information
gotson committed Jul 15, 2020
1 parent 1965415 commit 20b2b39
Show file tree
Hide file tree
Showing 152 changed files with 1,707 additions and 1,193 deletions.
4 changes: 2 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Komga is composed of 2 projects:

Komga uses Spring Profiles extensively:
- `dev`: add more logging, disable periodic scanning, in-memory database
- `localdb`: a dev profile that stores the database in `./testdb`.
- `localdb`: a dev profile that stores the database in `./localdb`.
- `noclaim`: will create initial users at startup if none exist and output users and passwords in the standard output
- if `dev` is active, will create `admin@example.org` with password `admin`, and `user@example.org` with password `user`
- if `dev` is not active, will create `admin@example.org` with a random password
- if `dev` is not active, will create `admin@example.org` with a random password that will be shown in the logs

### Gradle tasks

Expand Down
6 changes: 3 additions & 3 deletions komga-webui/src/components/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ export default Vue.extend({
this.$router.push({ name: 'search', query: { q: s } }).catch(e => {
})
},
seriesThumbnailUrl (seriesId: number): string {
seriesThumbnailUrl (seriesId: string): string {
return seriesThumbnailUrl(seriesId)
},
bookThumbnailUrl (bookId: number): string {
bookThumbnailUrl (bookId: string): string {
return bookThumbnailUrl(bookId)
},
collectionThumbnailUrl (collectionId: number): string {
collectionThumbnailUrl (collectionId: string): string {
return collectionThumbnailUrl(collectionId)
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default Vue.extend({
},
computed: {
seriesIds (): number[] {
seriesIds (): string[] {
if (Array.isArray(this.series)) return this.series.map(s => s.id)
else return [this.series.id]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default Vue.extend({
type: Boolean,
},
bookId: {
type: Number,
type: String,
},
},
data: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default Vue.extend({
snackText: '',
modal: false,
allLibraries: true,
selectedLibraries: [] as number[],
selectedLibraries: [] as string[],
}
},
props: {
Expand Down
12 changes: 6 additions & 6 deletions komga-webui/src/functions/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ const urls = {

export default urls

export function bookThumbnailUrl (bookId: number): string {
export function bookThumbnailUrl (bookId: string): string {
return `${urls.originNoSlash}/api/v1/books/${bookId}/thumbnail`
}

export function bookFileUrl (bookId: number): string {
export function bookFileUrl (bookId: string): string {
return `${urls.originNoSlash}/api/v1/books/${bookId}/file`
}

export function bookPageUrl (bookId: number, page: number, convertTo?: string): string {
export function bookPageUrl (bookId: string, page: number, convertTo?: string): string {
let url = `${urls.originNoSlash}/api/v1/books/${bookId}/pages/${page}`
if (convertTo) {
url += `?convert=${convertTo}`
}
return url
}

export function bookPageThumbnailUrl (bookId: number, page: number): string {
export function bookPageThumbnailUrl (bookId: string, page: number): string {
return `${urls.originNoSlash}/api/v1/books/${bookId}/pages/${page}/thumbnail`
}

export function seriesThumbnailUrl (seriesId: number): string {
export function seriesThumbnailUrl (seriesId: string): string {
return `${urls.originNoSlash}/api/v1/series/${seriesId}/thumbnail`
}

export function collectionThumbnailUrl (collectionId: number): string {
export function collectionThumbnailUrl (collectionId: string): string {
return `${urls.originNoSlash}/api/v1/collections/${collectionId}/thumbnail`
}
2 changes: 1 addition & 1 deletion komga-webui/src/plugins/komga-users.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const vuexModule: Module<any, any> = {
await service.postUser(user)
dispatch('getAllUsers')
},
async updateUserRoles ({ dispatch }, { userId, roles }: { userId: number, roles: RolesUpdateDto }) {
async updateUserRoles ({ dispatch }, { userId, roles }: { userId: string, roles: RolesUpdateDto }) {
await service.patchUserRoles(userId, roles)
dispatch('getAllUsers')
},
Expand Down
12 changes: 6 additions & 6 deletions komga-webui/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,32 @@ const router = new Router({
name: 'browse-libraries',
beforeEnter: noLibraryGuard,
component: () => import(/* webpackChunkName: "browse-libraries" */ './views/BrowseLibraries.vue'),
props: (route) => ({ libraryId: Number(route.params.libraryId) }),
props: (route) => ({ libraryId: route.params.libraryId }),
},
{
path: '/libraries/:libraryId/collections',
name: 'browse-collections',
beforeEnter: noLibraryGuard,
component: () => import(/* webpackChunkName: "browse-collections" */ './views/BrowseCollections.vue'),
props: (route) => ({ libraryId: Number(route.params.libraryId) }),
props: (route) => ({ libraryId: route.params.libraryId }),
},
{
path: '/collections/:collectionId',
name: 'browse-collection',
component: () => import(/* webpackChunkName: "browse-collection" */ './views/BrowseCollection.vue'),
props: (route) => ({ collectionId: Number(route.params.collectionId) }),
props: (route) => ({ collectionId: route.params.collectionId }),
},
{
path: '/series/:seriesId',
name: 'browse-series',
component: () => import(/* webpackChunkName: "browse-series" */ './views/BrowseSeries.vue'),
props: (route) => ({ seriesId: Number(route.params.seriesId) }),
props: (route) => ({ seriesId: route.params.seriesId }),
},
{
path: '/book/:bookId',
name: 'browse-book',
component: () => import(/* webpackChunkName: "browse-book" */ './views/BrowseBook.vue'),
props: (route) => ({ bookId: Number(route.params.bookId) }),
props: (route) => ({ bookId: route.params.bookId }),
},
{
path: '/search',
Expand All @@ -124,7 +124,7 @@ const router = new Router({
path: '/book/:bookId/read',
name: 'read-book',
component: () => import(/* webpackChunkName: "read-book" */ './views/BookReader.vue'),
props: (route) => ({ bookId: Number(route.params.bookId) }),
props: (route) => ({ bookId: route.params.bookId }),
},
{
path: '*',
Expand Down
16 changes: 8 additions & 8 deletions komga-webui/src/services/komga-books.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class KomgaBooksService {
this.http = http
}

async getBooks (libraryId?: number, pageRequest?: PageRequest, search?: string, mediaStatus?: string[], readStatus?: string[]): Promise<Page<BookDto>> {
async getBooks (libraryId?: string, pageRequest?: PageRequest, search?: string, mediaStatus?: string[], readStatus?: string[]): Promise<Page<BookDto>> {
try {
const params = { ...pageRequest } as any
if (libraryId) {
Expand Down Expand Up @@ -53,7 +53,7 @@ export default class KomgaBooksService {
}
}

async getBook (bookId: number): Promise<BookDto> {
async getBook (bookId: string): Promise<BookDto> {
try {
return (await this.http.get(`${API_BOOKS}/${bookId}`)).data
} catch (e) {
Expand All @@ -65,7 +65,7 @@ export default class KomgaBooksService {
}
}

async getBookSiblingNext (bookId: number): Promise<BookDto> {
async getBookSiblingNext (bookId: string): Promise<BookDto> {
try {
return (await this.http.get(`${API_BOOKS}/${bookId}/next`)).data
} catch (e) {
Expand All @@ -77,7 +77,7 @@ export default class KomgaBooksService {
}
}

async getBookSiblingPrevious (bookId: number): Promise<BookDto> {
async getBookSiblingPrevious (bookId: string): Promise<BookDto> {
try {
return (await this.http.get(`${API_BOOKS}/${bookId}/previous`)).data
} catch (e) {
Expand All @@ -89,7 +89,7 @@ export default class KomgaBooksService {
}
}

async getBookPages (bookId: number): Promise<PageDto[]> {
async getBookPages (bookId: string): Promise<PageDto[]> {
try {
return (await this.http.get(`${API_BOOKS}/${bookId}/pages`)).data
} catch (e) {
Expand Down Expand Up @@ -125,7 +125,7 @@ export default class KomgaBooksService {
}
}

async updateMetadata (bookId: number, metadata: BookMetadataUpdateDto) {
async updateMetadata (bookId: string, metadata: BookMetadataUpdateDto) {
try {
await this.http.patch(`${API_BOOKS}/${bookId}/metadata`, metadata)
} catch (e) {
Expand All @@ -137,7 +137,7 @@ export default class KomgaBooksService {
}
}

async updateReadProgress (bookId: number, readProgress: ReadProgressUpdateDto) {
async updateReadProgress (bookId: string, readProgress: ReadProgressUpdateDto) {
try {
await this.http.patch(`${API_BOOKS}/${bookId}/read-progress`, readProgress)
} catch (e) {
Expand All @@ -149,7 +149,7 @@ export default class KomgaBooksService {
}
}

async deleteReadProgress (bookId: number) {
async deleteReadProgress (bookId: string) {
try {
await this.http.delete(`${API_BOOKS}/${bookId}/read-progress`)
} catch (e) {
Expand Down
10 changes: 5 additions & 5 deletions komga-webui/src/services/komga-collections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class KomgaCollectionsService {
this.http = http
}

async getCollections (libraryIds?: number[], pageRequest?: PageRequest, search?: string): Promise<Page<CollectionDto>> {
async getCollections (libraryIds?: string[], pageRequest?: PageRequest, search?: string): Promise<Page<CollectionDto>> {
try {
const params = { ...pageRequest } as any
if (libraryIds) params.library_id = libraryIds
Expand All @@ -30,7 +30,7 @@ export default class KomgaCollectionsService {
}
}

async getOneCollection (collectionId: number): Promise<CollectionDto> {
async getOneCollection (collectionId: string): Promise<CollectionDto> {
try {
return (await this.http.get(`${API_COLLECTIONS}/${collectionId}`)).data
} catch (e) {
Expand All @@ -54,7 +54,7 @@ export default class KomgaCollectionsService {
}
}

async patchCollection (collectionId: number, collection: CollectionUpdateDto) {
async patchCollection (collectionId: string, collection: CollectionUpdateDto) {
try {
await this.http.patch(`${API_COLLECTIONS}/${collectionId}`, collection)
} catch (e) {
Expand All @@ -66,7 +66,7 @@ export default class KomgaCollectionsService {
}
}

async deleteCollection (collectionId: number) {
async deleteCollection (collectionId: string) {
try {
await this.http.delete(`${API_COLLECTIONS}/${collectionId}`)
} catch (e) {
Expand All @@ -78,7 +78,7 @@ export default class KomgaCollectionsService {
}
}

async getSeries (collectionId: number, pageRequest?: PageRequest): Promise<Page<SeriesDto>> {
async getSeries (collectionId: string, pageRequest?: PageRequest): Promise<Page<SeriesDto>> {
try {
const params = { ...pageRequest }
return (await this.http.get(`${API_COLLECTIONS}/${collectionId}/series`, {
Expand Down
4 changes: 2 additions & 2 deletions komga-webui/src/services/komga-libraries.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class KomgaLibrariesService {
}
}

async getLibrary (libraryId: number): Promise<LibraryDto> {
async getLibrary (libraryId: string): Promise<LibraryDto> {
try {
return (await this.http.get(`${API_LIBRARIES}/${libraryId}`)).data
} catch (e) {
Expand All @@ -45,7 +45,7 @@ export default class KomgaLibrariesService {
}
}

async updateLibrary (libraryId: number, library: LibraryUpdateDto) {
async updateLibrary (libraryId: string, library: LibraryUpdateDto) {
try {
await this.http.put(`${API_LIBRARIES}/${libraryId}`, library)
} catch (e) {
Expand Down
14 changes: 7 additions & 7 deletions komga-webui/src/services/komga-series.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class KomgaSeriesService {
this.http = http
}

async getSeries (libraryId?: number, pageRequest?: PageRequest, search?: string, status?: string[], readStatus?: string[]): Promise<Page<SeriesDto>> {
async getSeries (libraryId?: string, pageRequest?: PageRequest, search?: string, status?: string[], readStatus?: string[]): Promise<Page<SeriesDto>> {
try {
const params = { ...pageRequest } as any
if (libraryId) {
Expand Down Expand Up @@ -69,7 +69,7 @@ export default class KomgaSeriesService {
}
}

async getOneSeries (seriesId: number): Promise<SeriesDto> {
async getOneSeries (seriesId: string): Promise<SeriesDto> {
try {
return (await this.http.get(`${API_SERIES}/${seriesId}`)).data
} catch (e) {
Expand All @@ -81,7 +81,7 @@ export default class KomgaSeriesService {
}
}

async getBooks (seriesId: number, pageRequest?: PageRequest, readStatus?: string[]): Promise<Page<BookDto>> {
async getBooks (seriesId: string, pageRequest?: PageRequest, readStatus?: string[]): Promise<Page<BookDto>> {
try {
const params = { ...pageRequest } as any
if (readStatus) {
Expand All @@ -100,7 +100,7 @@ export default class KomgaSeriesService {
}
}

async getCollections (seriesId: number): Promise<CollectionDto[]> {
async getCollections (seriesId: string): Promise<CollectionDto[]> {
try {
return (await this.http.get(`${API_SERIES}/${seriesId}/collections`)).data
} catch (e) {
Expand Down Expand Up @@ -136,7 +136,7 @@ export default class KomgaSeriesService {
}
}

async updateMetadata (seriesId: number, metadata: SeriesMetadataUpdateDto) {
async updateMetadata (seriesId: string, metadata: SeriesMetadataUpdateDto) {
try {
await this.http.patch(`${API_SERIES}/${seriesId}/metadata`, metadata)
} catch (e) {
Expand All @@ -148,7 +148,7 @@ export default class KomgaSeriesService {
}
}

async markAsRead (seriesId: number) {
async markAsRead (seriesId: string) {
try {
await this.http.post(`${API_SERIES}/${seriesId}/read-progress`)
} catch (e) {
Expand All @@ -160,7 +160,7 @@ export default class KomgaSeriesService {
}
}

async markAsUnread (seriesId: number) {
async markAsUnread (seriesId: string) {
try {
await this.http.delete(`${API_SERIES}/${seriesId}/read-progress`)
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion komga-webui/src/services/komga-users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class KomgaUsersService {
}
}

async patchUserRoles (userId: number, roles: RolesUpdateDto): Promise<UserDto> {
async patchUserRoles (userId: string, roles: RolesUpdateDto): Promise<UserDto> {
try {
return (await this.http.patch(`${API_USERS}/${userId}`, roles)).data
} catch (e) {
Expand Down
18 changes: 9 additions & 9 deletions komga-webui/src/types/events-payloads.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
interface EventBookChanged {
id: number,
seriesId: number
id: string,
seriesId: string
}

interface EventSeriesChanged {
id: number,
libraryId: number
id: string,
libraryId: string
}

interface EventCollectionChanged {
id: number
id: string
}

interface EventCollectionDeleted {
id: number
id: string
}

interface EventLibraryAdded {
id: number
id: string
}

interface EventLibraryChanged {
id: number
id: string
}

interface EventLibraryDeleted {
id: number
id: string
}

0 comments on commit 20b2b39

Please sign in to comment.