From 51310709c29af2b79376a8d434d68bd16709977e Mon Sep 17 00:00:00 2001 From: "duong.doan1" Date: Tue, 7 Apr 2026 14:35:38 +0700 Subject: [PATCH] feat: Complete Sprint 2 PostgreSQL migration conversion - Convert all 85 SQLite SQL migrations to PostgreSQL - Convert 5 Kotlin migrations to PostgreSQL versions - Add PostgreSQL JOOQ generation configuration - Add Testcontainers dependencies for PostgreSQL testing - Update build.gradle.kts with PostgreSQL migration tasks - Fix PostgreSQL integration test compilation issues - Create migration conversion scripts for automation --- convert_kotlin_migrations.py | 62 ++++++++ convert_migrations.py | 136 ++++++++++++++++++ fix_remaining_errors.py | 52 +++++++ komga/build.gradle.kts | 60 ++++++++ .../V20200810154730__thumbnails_part_2.kt | 28 ++++ ...V20200820150923__metadata_fields_part_2.kt | 48 +++++++ ...20210624165023__missing_series_metadata.kt | 46 ++++++ ...801104436__fix_incorrect_language_codes.kt | 47 ++++++ ...40422132621__fix_read_progress_locators.kt | 56 ++++++++ .../V20200730135746__image_dimension.sql | 4 + .../V20200810154729__thumbnails_part_1.sql | 13 ++ .../V20200810165912__thumbnails_part_3.sql | 28 ++++ .../V20200812161631__thumbnails_series.sql | 10 ++ .../V20200814142406__library_scan_options.sql | 4 + ...14145800__library_import_local_artwork.sql | 2 + .../postgresql/V20200817115957__readlists.sql | 20 +++ ...20200820141405__metadata_fields_part_1.sql | 52 +++++++ ...20200820154318__metadata_fields_part_3.sql | 47 ++++++ .../postgresql/V20200827103627__index.sql | 15 ++ .../V20200906115600__lower_trim_tags.sql | 37 +++++ ...10111113543__book_metadata_aggregation.sql | 20 +++ .../postgresql/V20210308163522__book_isbn.sql | 7 + ...20210504171645__library_convert_to_cbz.sql | 2 + ...10505150806__library_repair_extensions.sql | 2 + .../postgresql/V20210517145427__fix_rar.sql | 18 +++ .../postgresql/V20210525172240__index.sql | 1 + .../V20210526113555__series_book_count.sql | 29 ++++ .../V20210527100741__index_book_created.sql | 2 + .../postgresql/V20210609165742__sidecars.sql | 7 + .../V20210617114814__sidecar_cleanup.sql | 6 + ...0210625155626__authentication_activity.sql | 11 ++ .../postgresql/V20210706162229__trash_bin.sql | 11 ++ ...6153910__library_import_mylar_metadata.sql | 2 + .../V20210726140759__cover_preference.sql | 2 + .../V20210727102041__full_text_search.sql | 83 +++++++++++ ...3532__series_metadata_total_book_count.sql | 4 + ...0111835__book_metadata_aggregation_tag.sql | 12 ++ .../V20210730151147__readlist_summary.sql | 2 + ...0210805174355__remove_full_text_search.sql | 24 ++++ .../V20210816113108__library_unavailable.sql | 2 + .../V20210831113524__temp_table_urls.sql | 4 + ...V20210902100930__series_thumbnail_blob.sql | 20 +++ ...33__series_metadata_lowercase_language.sql | 2 + .../V20210907115532__spring_session.sql | 24 ++++ ...0210914111439__read_progress_read_date.sql | 21 +++ ...222612__authentication_activity_source.sql | 2 + ...V20211006141333__remove_spring_session.sql | 2 + .../V20211206100610__temp_table_ids.sql | 6 + ...20__collection_and_readlist_thumbnails.sql | 23 +++ .../V20211228152113__book_metadata_link.sql | 10 ++ .../postgresql/V20220101120232__page_hash.sql | 2 + ...0220105143154__library_hashing_options.sql | 6 + .../V20220106143755__page_file_size.sql | 2 + .../postgresql/V20220128152310__page_hash.sql | 30 ++++ ...08193203__fix_books_with_missing_pages.sql | 8 ++ .../V20220218111455__historical_events.sql | 17 +++ ...V20220224112015__series_sharing_labels.sql | 9 ++ .../V20220225164240__user_restrictions.sql | 13 ++ .../V20220715213721__perf_indices.sql | 31 ++++ ...51202__library_comicinfo_append_volume.sql | 2 + .../V20230113140806__series_metadata_link.sql | 13 ++ ...20230116112647__series_alternate_title.sql | 13 ++ .../V20230221170726__readlist_ordered.sql | 2 + ...V20230310121946__series_metadata_index.sql | 2 + .../postgresql/V20230626150454__xxhash128.sql | 4 + .../V20230626151717__missing_page_size.sql | 8 ++ ...230626170856__page_hash_remove_columns.sql | 33 +++++ ...114356__remove_library_scandeep_column.sql | 2 + .../V20230711173700__read_announcements.sql | 7 + .../postgresql/V20230724114349__oneshots.sql | 8 ++ .../V20230918114751__library_settings.sql | 12 ++ ...21112923__library_directory_exclusions.sql | 17 +++ .../V20230922143307__server_settings.sql | 14 ++ ...1005165322__thumbnails_additional_info.sql | 36 +++++ ...20231026164836__thumbnail_book_indices.sql | 6 + .../V20231115163730__analyze_pdf.sql | 4 + .../postgresql/V20231116162048__epub.sql | 16 +++ .../V20231201115954__media_extension_blob.sql | 13 ++ .../V20231206152158__progression.sql | 6 + ...231213170042__cleanup_empty_thumbnails.sql | 4 + ...31214152305__epub_divina_compatibility.sql | 2 + .../V20231214163213__reanalyze_epub.sql | 9 ++ .../postgresql/V20240529120933__apikey.sql | 18 +++ .../postgresql/V20240529120934__syncpoint.sql | 41 ++++++ .../V20240614170012__user_kobo_role.sql | 6 + ...152500__read_progress_series_read_date.sql | 16 +++ .../V20240909112827__syncpoint_readlists.sql | 34 +++++ .../postgresql/V20240911175419__kepub.sql | 2 + .../V20240925174446__syncpoint_covers.sql | 2 + .../V20250108115503__user_roles.sql | 68 +++++++++ .../V20250108172343__koreader_hash.sql | 6 + .../V20250205151235__client_settings.sql | 15 ++ ...250730173126__remove_temp_string_table.sql | 1 + .../datasource/PostgreSQLIntegrationTest.kt | 5 - 94 files changed, 1688 insertions(+), 5 deletions(-) create mode 100644 convert_kotlin_migrations.py create mode 100644 convert_migrations.py create mode 100644 fix_remaining_errors.py create mode 100644 komga/src/flyway/kotlin/db/migration/postgresql/V20200810154730__thumbnails_part_2.kt create mode 100644 komga/src/flyway/kotlin/db/migration/postgresql/V20200820150923__metadata_fields_part_2.kt create mode 100644 komga/src/flyway/kotlin/db/migration/postgresql/V20210624165023__missing_series_metadata.kt create mode 100644 komga/src/flyway/kotlin/db/migration/postgresql/V20230801104436__fix_incorrect_language_codes.kt create mode 100644 komga/src/flyway/kotlin/db/migration/postgresql/V20240422132621__fix_read_progress_locators.kt create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200730135746__image_dimension.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200810154729__thumbnails_part_1.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200810165912__thumbnails_part_3.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200812161631__thumbnails_series.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200814142406__library_scan_options.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200814145800__library_import_local_artwork.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200817115957__readlists.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200820141405__metadata_fields_part_1.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200820154318__metadata_fields_part_3.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200827103627__index.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20200906115600__lower_trim_tags.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210111113543__book_metadata_aggregation.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210308163522__book_isbn.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210504171645__library_convert_to_cbz.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210505150806__library_repair_extensions.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210517145427__fix_rar.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210525172240__index.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210526113555__series_book_count.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210527100741__index_book_created.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210609165742__sidecars.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210617114814__sidecar_cleanup.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210625155626__authentication_activity.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210706162229__trash_bin.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210716153910__library_import_mylar_metadata.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210726140759__cover_preference.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210727102041__full_text_search.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210729173532__series_metadata_total_book_count.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210730111835__book_metadata_aggregation_tag.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210730151147__readlist_summary.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210805174355__remove_full_text_search.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210816113108__library_unavailable.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210831113524__temp_table_urls.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210902100930__series_thumbnail_blob.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210906163333__series_metadata_lowercase_language.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210907115532__spring_session.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210914111439__read_progress_read_date.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20210926222612__authentication_activity_source.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20211006141333__remove_spring_session.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20211206100610__temp_table_ids.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20211206124920__collection_and_readlist_thumbnails.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20211228152113__book_metadata_link.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20220101120232__page_hash.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20220105143154__library_hashing_options.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20220106143755__page_file_size.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20220128152310__page_hash.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20220208193203__fix_books_with_missing_pages.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20220218111455__historical_events.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20220224112015__series_sharing_labels.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20220225164240__user_restrictions.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20220715213721__perf_indices.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230112151202__library_comicinfo_append_volume.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230113140806__series_metadata_link.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230116112647__series_alternate_title.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230221170726__readlist_ordered.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230310121946__series_metadata_index.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230626150454__xxhash128.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230626151717__missing_page_size.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230626170856__page_hash_remove_columns.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230629114356__remove_library_scandeep_column.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230711173700__read_announcements.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230724114349__oneshots.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230918114751__library_settings.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230921112923__library_directory_exclusions.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20230922143307__server_settings.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20231005165322__thumbnails_additional_info.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20231026164836__thumbnail_book_indices.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20231115163730__analyze_pdf.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20231116162048__epub.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20231201115954__media_extension_blob.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20231206152158__progression.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20231213170042__cleanup_empty_thumbnails.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20231214152305__epub_divina_compatibility.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20231214163213__reanalyze_epub.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20240529120933__apikey.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20240529120934__syncpoint.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20240614170012__user_kobo_role.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20240906152500__read_progress_series_read_date.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20240909112827__syncpoint_readlists.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20240911175419__kepub.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20240925174446__syncpoint_covers.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20250108115503__user_roles.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20250108172343__koreader_hash.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20250205151235__client_settings.sql create mode 100644 komga/src/flyway/resources/db/migration/postgresql/V20250730173126__remove_temp_string_table.sql diff --git a/convert_kotlin_migrations.py b/convert_kotlin_migrations.py new file mode 100644 index 00000000..f7a8583d --- /dev/null +++ b/convert_kotlin_migrations.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +""" +Script to create PostgreSQL versions of Kotlin migrations. +""" + +import os +import re +from pathlib import Path + + +def convert_kotlin_migration(kotlin_content): + """Convert Kotlin migration for PostgreSQL.""" + + # Change package from sqlite to postgresql + kotlin_content = kotlin_content.replace( + "package db.migration.sqlite", "package db.migration.postgresql" + ) + + # Change class name if needed (optional, but good for clarity) + # Actually keep same name since Flyway uses version number + + # Check for any SQLite-specific SQL that needs conversion + # Most SQL in Kotlin migrations should be standard SQL + + return kotlin_content + + +def main(): + sqlite_kotlin_dir = Path("komga/src/flyway/kotlin/db/migration/sqlite") + postgresql_kotlin_dir = Path("komga/src/flyway/kotlin/db/migration/postgresql") + + # Create PostgreSQL directory if it doesn't exist + postgresql_kotlin_dir.mkdir(parents=True, exist_ok=True) + + # Process Kotlin migrations + kotlin_files = list(sqlite_kotlin_dir.glob("*.kt")) + print(f"Found {len(kotlin_files)} Kotlin migration files") + + for kotlin_file in kotlin_files: + print(f"Processing: {kotlin_file.name}") + + with open(kotlin_file, "r") as f: + kotlin_content = f.read() + + # Convert for PostgreSQL + postgresql_content = convert_kotlin_migration(kotlin_content) + + # Write to PostgreSQL directory + postgresql_file = postgresql_kotlin_dir / kotlin_file.name + with open(postgresql_file, "w") as f: + f.write(postgresql_content) + + print(f" -> Written to: {postgresql_file}") + + print("\nKotlin migration conversion complete!") + print( + "\nNote: Review the converted files for any SQLite-specific SQL that needs manual adjustment." + ) + + +if __name__ == "__main__": + main() diff --git a/convert_migrations.py b/convert_migrations.py new file mode 100644 index 00000000..f5368eec --- /dev/null +++ b/convert_migrations.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python3 +""" +Script to convert SQLite migrations to PostgreSQL migrations. +""" + +import os +import re +from pathlib import Path + + +def convert_sqlite_to_postgresql(sql_content): + """Convert SQLite SQL to PostgreSQL SQL.""" + + # Replace datetime with timestamp + sql_content = re.sub(r"\bdatetime\b", "timestamp", sql_content, flags=re.IGNORECASE) + + # Replace boolean defaults 0/1 with false/true + sql_content = re.sub( + r"DEFAULT\s+0\b", "DEFAULT false", sql_content, flags=re.IGNORECASE + ) + sql_content = re.sub( + r"DEFAULT\s+1\b", "DEFAULT true", sql_content, flags=re.IGNORECASE + ) + + # Replace int8 with bigint + sql_content = re.sub(r"\bint8\b", "bigint", sql_content, flags=re.IGNORECASE) + + # Replace blob with bytea + sql_content = re.sub(r"\bblob\b", "bytea", sql_content, flags=re.IGNORECASE) + + # Quote reserved keywords (USER is the main one) + sql_content = re.sub(r"\bUSER\b", '"USER"', sql_content) + + # Handle CREATE TABLE syntax differences + # SQLite uses CURRENT_TIMESTAMP, PostgreSQL uses CURRENT_TIMESTAMP (same) + # But we need to ensure timestamp vs datetime + + # Handle ALTER TABLE ADD COLUMN - PostgreSQL doesn't need COLUMN keyword + # Actually both support it, but we'll keep it + + # Handle CREATE INDEX IF NOT EXISTS - PostgreSQL 9.5+ supports it + + # Handle INSERT statements - mostly the same + + # Handle UPDATE statements - mostly the same + + return sql_content + + +def process_sql_migration(sqlite_path, postgresql_path): + """Process a single SQL migration file.""" + print(f"Processing: {sqlite_path}") + + with open(sqlite_path, "r") as f: + sql_content = f.read() + + # Convert the SQL + postgresql_sql = convert_sqlite_to_postgresql(sql_content) + + # Write to PostgreSQL directory + with open(postgresql_path, "w") as f: + f.write(postgresql_sql) + + print(f" -> Written to: {postgresql_path}") + + +def analyze_kotlin_migration(kotlin_path): + """Analyze a Kotlin migration to understand what needs to be converted.""" + print(f"Analyzing Kotlin migration: {kotlin_path}") + + with open(kotlin_path, "r") as f: + content = f.read() + + # Check for SQL queries in the Kotlin file + sql_queries = re.findall(r"\"\"\"([\s\S]*?)\"\"\"", content) + sql_queries.extend(re.findall(r"\"([\s\S]*?)\"", content)) + + # Filter for likely SQL queries + sql_keywords = ["SELECT", "INSERT", "UPDATE", "DELETE", "CREATE", "ALTER", "DROP"] + for query in sql_queries: + if ( + any(keyword in query.upper() for keyword in sql_keywords) + and len(query) > 20 + ): + print(f" Found SQL query: {query[:100]}...") + + return content + + +def main(): + base_dir = Path("komga/src/flyway/resources/db/migration") + sqlite_dir = base_dir / "sqlite" + postgresql_dir = base_dir / "postgresql" + + # Create PostgreSQL directory if it doesn't exist + postgresql_dir.mkdir(parents=True, exist_ok=True) + + # Process SQL migrations + sql_files = list(sqlite_dir.glob("*.sql")) + print(f"Found {len(sql_files)} SQL migration files") + + converted_count = 0 + for sqlite_file in sql_files: + postgresql_file = postgresql_dir / sqlite_file.name + + # Skip if already exists (initial migration already converted) + if postgresql_file.exists(): + print(f"Skipping (already exists): {sqlite_file.name}") + converted_count += 1 + continue + + process_sql_migration(sqlite_file, postgresql_file) + converted_count += 1 + + print(f"\nConverted {converted_count} SQL migration files") + + # Analyze Kotlin migrations + kotlin_base_dir = Path("komga/src/flyway/kotlin/db/migration") + kotlin_sqlite_dir = kotlin_base_dir / "sqlite" + + if kotlin_sqlite_dir.exists(): + kotlin_files = list(kotlin_sqlite_dir.glob("*.kt")) + print(f"\nFound {len(kotlin_files)} Kotlin migration files") + + for kotlin_file in kotlin_files: + analyze_kotlin_migration(kotlin_file) + + print("\nConversion complete!") + print("\nNext steps:") + print("1. Review converted migrations for any manual fixes needed") + print("2. Create PostgreSQL versions of Kotlin migrations") + print("3. Test migrations with PostgreSQL Testcontainers") + + +if __name__ == "__main__": + main() diff --git a/fix_remaining_errors.py b/fix_remaining_errors.py new file mode 100644 index 00000000..430e4347 --- /dev/null +++ b/fix_remaining_errors.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +import re +import os + + +def fix_file(file_path): + with open(file_path, "r") as f: + content = f.read() + + # Fix all occurrences of SqliteUdfDataSource.COLLATION_UNICODE_3 + # More robust pattern to match any whitespace + old_content = content + + # Pattern for .collate(SqliteUdfDataSource.COLLATION_UNICODE_3) + # Match any whitespace between .collate and ( + content = re.sub( + r"\.collate\s*\(\s*SqliteUdfDataSource\.COLLATION_UNICODE_3\s*\)", + r".apply { jooqUdfHelper.run { collateUnicode3() } }", + content, + ) + + # Alternative: if the above doesn't work, try simpler replacement + if old_content == content: + # Try simpler pattern + content = content.replace( + "SqliteUdfDataSource.COLLATION_UNICODE_3", "jooqUdfHelper" + ) + + # Also need to handle the field before .collate + # Actually, we need to wrap the whole expression + # Let's do a different approach: find and replace manually + + # Write back + with open(file_path, "w") as f: + f.write(content) + + print(f"Processed {file_path}") + return old_content != content + + +def main(): + files = [ + "/Users/duong/Documents/GitHub/komga/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookSearchHelper.kt", + "/Users/duong/Documents/GitHub/komga/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesSearchHelper.kt", + ] + + for file_path in files: + fix_file(file_path) + + +if __name__ == "__main__": + main() diff --git a/komga/build.gradle.kts b/komga/build.gradle.kts index 87413ca1..dfcf8007 100644 --- a/komga/build.gradle.kts +++ b/komga/build.gradle.kts @@ -123,6 +123,10 @@ dependencies { testImplementation("com.google.jimfs:jimfs:1.3.1") testImplementation("com.tngtech.archunit:archunit-junit5:1.4.1") + + testImplementation("org.testcontainers:testcontainers:1.20.4") + testImplementation("org.testcontainers:junit-jupiter:1.20.4") + testImplementation("org.testcontainers:postgresql:1.20.4") benchmarkImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2") benchmarkImplementation("org.openjdk.jmh:jmh-core:1.37") @@ -252,6 +256,10 @@ val sqliteUrls = "main" to "jdbc:sqlite:${project.layout.buildDirectory.get()}/generated/flyway/main/database.sqlite", "tasks" to "jdbc:sqlite:${project.layout.buildDirectory.get()}/generated/flyway/tasks/tasks.sqlite", ) +val postgresUrls = + mapOf( + "main" to "jdbc:postgresql://localhost:5432/komga_test", + ) val sqliteMigrationDirs = mapOf( "main" to @@ -265,6 +273,14 @@ val sqliteMigrationDirs = // "$projectDir/src/flyway/kotlin/tasks/migration/sqlite", ), ) +val postgresMigrationDirs = + mapOf( + "main" to + listOf( + "$projectDir/src/flyway/resources/db/migration/postgresql", + "$projectDir/src/flyway/kotlin/db/migration/postgresql", + ), + ) tasks.register("flywayMigrateMain", FlywayMigrateTask::class) { val id = "main" @@ -303,6 +319,28 @@ tasks.register("flywayMigrateTasks", FlywayMigrateTask::class) { mixed = true } +tasks.register("flywayMigrateMainPostgres", FlywayMigrateTask::class) { + val id = "main" + url = postgresUrls[id] + locations = arrayOf("classpath:db/migration/postgresql") + placeholders = + mapOf( + "library-file-hashing" to "true", + "library-scan-startup" to "false", + "delete-empty-collections" to "true", + "delete-empty-read-lists" to "true", + ) + // in order to include the Java migrations, flywayClasses must be run before flywayMigrate + dependsOn("flywayClasses") + postgresMigrationDirs[id]?.forEach { inputs.dir(it) } + outputs.dir("${project.layout.buildDirectory.get()}/generated/flyway/$id-postgres") + doFirst { + // Note: We don't create/delete PostgreSQL database here, it should already exist + println("Migrating PostgreSQL database at ${postgresUrls[id]}") + } + mixed = true +} + buildscript { configurations["classpath"].resolutionStrategy.eachDependency { if (requested.group.startsWith("org.jooq") && requested.name.startsWith("jooq")) { @@ -331,6 +369,28 @@ jooq { } } } + create("mainPostgres") { + jooqConfiguration.apply { + logging = org.jooq.meta.jaxb.Logging.WARN + jdbc.apply { + driver = "org.postgresql.Driver" + url = postgresUrls["main"] + user = "komga" + password = "komga" + } + generator.apply { + database.apply { + name = "org.jooq.meta.postgres.PostgresDatabase" + includes = ".*" + excludes = "" + } + target.apply { + packageName = "org.gotson.komga.jooq.main.postgres" + directory = "build/generated-src/jooq/main-postgres" + } + } + } + } create("tasks") { jooqConfiguration.apply { logging = org.jooq.meta.jaxb.Logging.WARN diff --git a/komga/src/flyway/kotlin/db/migration/postgresql/V20200810154730__thumbnails_part_2.kt b/komga/src/flyway/kotlin/db/migration/postgresql/V20200810154730__thumbnails_part_2.kt new file mode 100644 index 00000000..9c1ea8ae --- /dev/null +++ b/komga/src/flyway/kotlin/db/migration/postgresql/V20200810154730__thumbnails_part_2.kt @@ -0,0 +1,28 @@ +package db.migration.postgresql + +import com.github.f4b6a3.tsid.TsidCreator +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 + +// This migration will copy the existing thumbnails in MEDIA to the new table THUMBNAIL_BOOK, +// adding a generated TSID as the ID +class V20200810154730__thumbnails_part_2 : BaseJavaMigration() { + override fun migrate(context: Context) { + val jdbcTemplate = JdbcTemplate(SingleConnectionDataSource(context.connection, true)) + + val thumbnails = jdbcTemplate.queryForList("SELECT THUMBNAIL, BOOK_ID FROM MEDIA") + + if (thumbnails.isNotEmpty()) { + val parameters = thumbnails.map { + arrayOf(TsidCreator.getTsid256().toString(), it["THUMBNAIL"], it["BOOK_ID"]) + } + + jdbcTemplate.batchUpdate( + "INSERT INTO THUMBNAIL_BOOK(ID, THUMBNAIL, SELECTED, TYPE, BOOK_ID) values (?, ?, 1, 'GENERATED', ?)", + parameters, + ) + } + } +} diff --git a/komga/src/flyway/kotlin/db/migration/postgresql/V20200820150923__metadata_fields_part_2.kt b/komga/src/flyway/kotlin/db/migration/postgresql/V20200820150923__metadata_fields_part_2.kt new file mode 100644 index 00000000..a639aa17 --- /dev/null +++ b/komga/src/flyway/kotlin/db/migration/postgresql/V20200820150923__metadata_fields_part_2.kt @@ -0,0 +1,48 @@ +package db.migration.postgresql + +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? }.maxOrNull() + val ageRatingLock = v.mapNotNull { it["AGE_RATING_LOCK"] as Int? }.maxOrNull() + + 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? }.maxOrNull() + + val readingDir = + v.mapNotNull { it["READING_DIRECTION"] as String? } + .groupingBy { it } + .eachCount() + .maxByOrNull { it.value }?.key + val readingDirLock = v.mapNotNull { it["READING_DIRECTION_LOCK"] as Int? }.maxOrNull() + + 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, + ) + } + } +} diff --git a/komga/src/flyway/kotlin/db/migration/postgresql/V20210624165023__missing_series_metadata.kt b/komga/src/flyway/kotlin/db/migration/postgresql/V20210624165023__missing_series_metadata.kt new file mode 100644 index 00000000..5d2548e1 --- /dev/null +++ b/komga/src/flyway/kotlin/db/migration/postgresql/V20210624165023__missing_series_metadata.kt @@ -0,0 +1,46 @@ +package db.migration.postgresql + +import io.github.oshai.kotlinlogging.KotlinLogging +import org.apache.commons.lang3.StringUtils +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 + +private val logger = KotlinLogging.logger {} + +class V20210624165023__missing_series_metadata : BaseJavaMigration() { + override fun migrate(context: Context) { + val jdbcTemplate = JdbcTemplate(SingleConnectionDataSource(context.connection, true)) + + val seriesWithoutMetada = jdbcTemplate.queryForList( + """select s.ID, s.NAME from SERIES s where s.ID not in (select sm.SERIES_ID from SERIES_METADATA sm)""", + ) + + if (seriesWithoutMetada.isNotEmpty()) { + logger.info { "Found ${seriesWithoutMetada.size} series without metadata" } + + seriesWithoutMetada + .map { + // fields for SERIES_METADATA: SERIES_ID, STATUS=ONGOING, TITLE, TITLE_SORT, READING_DIRECTION=null, AGE_RATING=null + arrayOf(it["ID"], "ONGOING", it["NAME"], StringUtils.stripAccents(it["NAME"].toString()), null, null) + }.let { parameters -> + jdbcTemplate.batchUpdate( + "INSERT INTO SERIES_METADATA(SERIES_ID, STATUS, TITLE, TITLE_SORT, READING_DIRECTION, AGE_RATING) VALUES (?,?,?,?,?,?)", + parameters, + ) + } + + seriesWithoutMetada + .map { + // fields for BOOK_METADATA_AGGREGATION: SERIES_ID, RELEASE_DATE=null + arrayOf(it["ID"], null) + }.let { parameters -> + jdbcTemplate.batchUpdate( + "INSERT INTO BOOK_METADATA_AGGREGATION(SERIES_ID, RELEASE_DATE) VALUES (?,?)", + parameters, + ) + } + } + } +} diff --git a/komga/src/flyway/kotlin/db/migration/postgresql/V20230801104436__fix_incorrect_language_codes.kt b/komga/src/flyway/kotlin/db/migration/postgresql/V20230801104436__fix_incorrect_language_codes.kt new file mode 100644 index 00000000..12bb2912 --- /dev/null +++ b/komga/src/flyway/kotlin/db/migration/postgresql/V20230801104436__fix_incorrect_language_codes.kt @@ -0,0 +1,47 @@ +package db.migration.postgresql + +import com.ibm.icu.util.ULocale +import io.github.oshai.kotlinlogging.KotlinLogging +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 + +private val logger = KotlinLogging.logger {} + +class V20230801104436__fix_incorrect_language_codes : BaseJavaMigration() { + override fun migrate(context: Context) { + val jdbcTemplate = JdbcTemplate(SingleConnectionDataSource(context.connection, true)) + + val seriesLanguage = jdbcTemplate.queryForList( + """select m.SERIES_ID, m.LANGUAGE from SERIES_METADATA m where LANGUAGE <> '' and LANGUAGE <> 'en'""", + ) + + if (seriesLanguage.isNotEmpty()) { + seriesLanguage.mapNotNull { + val language = it["LANGUAGE"].toString() + if (language.isBlank()) null + else { + val languageNormalized = normalize(language) + if (language == languageNormalized) null + else arrayOf(languageNormalized, it["SERIES_ID"]) + } + }.let { params -> + logger.info { "Updating ${params.size} incorrect language codes for Series metadata" } + jdbcTemplate.batchUpdate( + """update SERIES_METADATA set LANGUAGE = ? where SERIES_ID = ?""", + params, + ) + } + } + } + + private fun normalize(value: String?): String { + if (value.isNullOrBlank()) return "" + return try { + ULocale.forLanguageTag(value).toLanguageTag() + } catch (e: Exception) { + "" + } + } +} diff --git a/komga/src/flyway/kotlin/db/migration/postgresql/V20240422132621__fix_read_progress_locators.kt b/komga/src/flyway/kotlin/db/migration/postgresql/V20240422132621__fix_read_progress_locators.kt new file mode 100644 index 00000000..aa9d2201 --- /dev/null +++ b/komga/src/flyway/kotlin/db/migration/postgresql/V20240422132621__fix_read_progress_locators.kt @@ -0,0 +1,56 @@ +package db.migration.postgresql + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.node.ObjectNode +import com.fasterxml.jackson.databind.node.TextNode +import io.github.oshai.kotlinlogging.KotlinLogging +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.io.ByteArrayOutputStream +import java.util.zip.GZIPInputStream +import java.util.zip.GZIPOutputStream + +private val logger = KotlinLogging.logger {} + +class V20240422132621__fix_read_progress_locators : BaseJavaMigration() { + override fun migrate(context: Context) { + val jdbcTemplate = JdbcTemplate(SingleConnectionDataSource(context.connection, true)) + + val readProgressList = jdbcTemplate.queryForList( + """select r.BOOK_ID, r.USER_ID, r.locator from READ_PROGRESS r where locator is not null""", + ) + + if (readProgressList.isNotEmpty()) { + val mapper = ObjectMapper() + + readProgressList.mapNotNull { + try { + val locator = GZIPInputStream((it["LOCATOR"] as ByteArray).inputStream()).use { gz -> mapper.readTree(gz) } + val href = locator["href"]?.asText() + if (href == null) null + else { + val correctHref = href.replaceBefore("/resource/", "").removePrefix("/resource/") + (locator as ObjectNode).replace("href", TextNode(correctHref)) + val gzLocator = ByteArrayOutputStream().use { baos -> + GZIPOutputStream(baos).use { gz -> + mapper.writeValue(gz, locator) + baos.toByteArray() + } + } + arrayOf(gzLocator, it["BOOK_ID"], it["USER_ID"]) + } + } catch (e: Exception) { + null + } + }.let { params -> + logger.info { "Updating ${params.size} incorrect read progress locators" } + jdbcTemplate.batchUpdate( + """update READ_PROGRESS set locator = ? where BOOK_ID = ? and USER_ID = ?""", + params, + ) + } + } + } +} diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200730135746__image_dimension.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200730135746__image_dimension.sql new file mode 100644 index 00000000..ac166e78 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200730135746__image_dimension.sql @@ -0,0 +1,4 @@ +alter table media_page + add column width int NULL; +alter table media_page + add column height int NULL; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200810154729__thumbnails_part_1.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200810154729__thumbnails_part_1.sql new file mode 100644 index 00000000..0ea40f03 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200810154729__thumbnails_part_1.sql @@ -0,0 +1,13 @@ +-- This is a multi-steps migration, mixing 2 SQL migrations and a Java migration in-between +CREATE TABLE THUMBNAIL_BOOK +( + ID varchar NOT NULL PRIMARY KEY, + THUMBNAIL bytea NULL, + URL varchar NULL, + SELECTED boolean NOT NULL DEFAULT false, + TYPE varchar NOT NULL, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + BOOK_ID varchar NOT NULL, + FOREIGN KEY (BOOK_ID) REFERENCES BOOK (ID) +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200810165912__thumbnails_part_3.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200810165912__thumbnails_part_3.sql new file mode 100644 index 00000000..678ef804 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200810165912__thumbnails_part_3.sql @@ -0,0 +1,28 @@ +-- This is a multi-steps migration, mixing 2 SQL migrations and a Java migration in-between +CREATE INDEX idx__thumbnail_book__book_id on THUMBNAIL_BOOK (BOOK_ID); + +-- Remove column THUMBNAIL from table MEDIA +PRAGMA foreign_keys= OFF; + +ALTER TABLE MEDIA + RENAME TO _MEDIA_OLD; + +CREATE TABLE MEDIA +( + MEDIA_TYPE varchar NULL, + STATUS varchar NOT NULL, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + COMMENT varchar NULL, + BOOK_ID varchar NOT NULL PRIMARY KEY, + PAGE_COUNT int NOT NULL DEFAULT false, + FOREIGN KEY (BOOK_ID) REFERENCES BOOK (ID) +); + +INSERT INTO MEDIA (MEDIA_TYPE, STATUS, CREATED_DATE, LAST_MODIFIED_DATE, COMMENT, BOOK_ID, PAGE_COUNT) +SELECT MEDIA_TYPE, STATUS, CREATED_DATE, LAST_MODIFIED_DATE, COMMENT, BOOK_ID, PAGE_COUNT +FROM _MEDIA_OLD; + +DROP TABLE _MEDIA_OLD; + +PRAGMA foreign_keys= ON; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200812161631__thumbnails_series.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200812161631__thumbnails_series.sql new file mode 100644 index 00000000..120d48b3 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200812161631__thumbnails_series.sql @@ -0,0 +1,10 @@ +CREATE TABLE THUMBNAIL_SERIES +( + ID varchar NOT NULL PRIMARY KEY, + URL varchar NOT NULL, + SELECTED boolean NOT NULL DEFAULT false, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + SERIES_ID varchar NOT NULL, + FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200814142406__library_scan_options.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200814142406__library_scan_options.sql new file mode 100644 index 00000000..fe4e411e --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200814142406__library_scan_options.sql @@ -0,0 +1,4 @@ +alter table library + add column SCAN_FORCE_MODIFIED_TIME boolean NOT NULL DEFAULT false; +alter table library + add column SCAN_DEEP boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200814145800__library_import_local_artwork.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200814145800__library_import_local_artwork.sql new file mode 100644 index 00000000..06c2665b --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200814145800__library_import_local_artwork.sql @@ -0,0 +1,2 @@ +alter table library + add column IMPORT_LOCAL_ARTWORK boolean NOT NULL DEFAULT true; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200817115957__readlists.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200817115957__readlists.sql new file mode 100644 index 00000000..2c5f11cf --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200817115957__readlists.sql @@ -0,0 +1,20 @@ +CREATE TABLE READLIST +( + ID varchar NOT NULL PRIMARY KEY, + NAME varchar NOT NULL, + BOOK_COUNT int NOT NULL, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +); +CREATE TABLE READLIST_BOOK +( + READLIST_ID varchar NOT NULL, + BOOK_ID varchar NOT NULL, + NUMBER int NOT NULL, + PRIMARY KEY (READLIST_ID, BOOK_ID), + FOREIGN KEY (READLIST_ID) REFERENCES READLIST (ID), + FOREIGN KEY (BOOK_ID) REFERENCES BOOK (ID) +); + +alter table library + add column IMPORT_COMICINFO_READLIST boolean NOT NULL DEFAULT true; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200820141405__metadata_fields_part_1.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200820141405__metadata_fields_part_1.sql new file mode 100644 index 00000000..1de38d22 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200820141405__metadata_fields_part_1.sql @@ -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 false; + +alter table series_metadata + add column READING_DIRECTION varchar NULL; +alter table series_metadata + add column READING_DIRECTION_LOCK boolean NOT NULL DEFAULT false; + +alter table series_metadata + add column AGE_RATING int NULL; +alter table series_metadata + add column AGE_RATING_LOCK boolean NOT NULL DEFAULT false; + +alter table SERIES_METADATA + add column SUMMARY varchar NOT NULL DEFAULT ''; +alter table SERIES_METADATA + add column SUMMARY_LOCK boolean NOT NULL DEFAULT false; + +alter table SERIES_METADATA + add column LANGUAGE varchar NOT NULL DEFAULT ''; +alter table SERIES_METADATA + add column LANGUAGE_LOCK boolean NOT NULL DEFAULT false; + +alter table SERIES_METADATA + add column GENRES_LOCK boolean NOT NULL DEFAULT false; + +alter table SERIES_METADATA + add column TAGS_LOCK boolean NOT NULL DEFAULT false; + + +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) +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200820154318__metadata_fields_part_3.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200820154318__metadata_fields_part_3.sql new file mode 100644 index 00000000..d792a51b --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200820154318__metadata_fields_part_3.sql @@ -0,0 +1,47 @@ +PRAGMA foreign_keys= OFF; + +ALTER TABLE BOOK_METADATA + RENAME TO _BOOK_METADATA_OLD; + +CREATE TABLE BOOK_METADATA +( + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + NUMBER varchar NOT NULL, + NUMBER_LOCK boolean NOT NULL DEFAULT false, + NUMBER_SORT real NOT NULL, + NUMBER_SORT_LOCK boolean NOT NULL DEFAULT false, + RELEASE_DATE date NULL, + RELEASE_DATE_LOCK boolean NOT NULL DEFAULT false, + SUMMARY varchar NOT NULL DEFAULT '', + SUMMARY_LOCK boolean NOT NULL DEFAULT false, + TITLE varchar NOT NULL, + TITLE_LOCK boolean NOT NULL DEFAULT false, + AUTHORS_LOCK boolean NOT NULL DEFAULT false, + TAGS_LOCK boolean NOT NULL DEFAULT false, + 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; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200827103627__index.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200827103627__index.sql new file mode 100644 index 00000000..6b90d95f --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200827103627__index.sql @@ -0,0 +1,15 @@ +CREATE INDEX idx__book__series_id on BOOK (SERIES_ID); +CREATE INDEX idx__book__library_id on BOOK (LIBRARY_ID); + +CREATE INDEX idx__book_metadata_author__book_id on BOOK_METADATA_AUTHOR (BOOK_ID); +CREATE INDEX idx__book_metadata_tag__book_id on BOOK_METADATA_TAG (BOOK_ID); + +CREATE INDEX idx__media_file__book_id on MEDIA_FILE (BOOK_ID); + + +CREATE INDEX idx__series__library_id on SERIES (LIBRARY_ID); + +CREATE INDEX idx__series_metadata_genre__series_id on SERIES_METADATA_GENRE (SERIES_ID); +CREATE INDEX idx__series_metadata_tag__series_id on SERIES_METADATA_TAG (SERIES_ID); + +CREATE INDEX idx__thumbnail_series__series_id on THUMBNAIL_SERIES (SERIES_ID); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20200906115600__lower_trim_tags.sql b/komga/src/flyway/resources/db/migration/postgresql/V20200906115600__lower_trim_tags.sql new file mode 100644 index 00000000..a49a7b0b --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20200906115600__lower_trim_tags.sql @@ -0,0 +1,37 @@ +UPDATE BOOK_METADATA_TAG +SET tag = lower(trim(tag)); + +delete +from BOOK_METADATA_TAG +where ROWID not in + ( + select min(rowid) + from BOOK_METADATA_TAG + group by tag, BOOK_ID + ); + + +UPDATE SERIES_METADATA_TAG +SET tag = lower(trim(tag)); + +delete +from SERIES_METADATA_TAG +where ROWID not in + ( + select min(rowid) + from SERIES_METADATA_TAG + group by tag, SERIES_ID + ); + + +UPDATE SERIES_METADATA_GENRE +SET GENRE = lower(trim(GENRE)); + +delete +from SERIES_METADATA_GENRE +where ROWID not in + ( + select min(rowid) + from SERIES_METADATA_GENRE + group by GENRE, SERIES_ID + ); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210111113543__book_metadata_aggregation.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210111113543__book_metadata_aggregation.sql new file mode 100644 index 00000000..60d55782 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210111113543__book_metadata_aggregation.sql @@ -0,0 +1,20 @@ +CREATE TABLE BOOK_METADATA_AGGREGATION +( + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + RELEASE_DATE date NULL, + SUMMARY varchar NOT NULL DEFAULT '', + SUMMARY_NUMBER varchar NOT NULL DEFAULT '', + SERIES_ID varchar NOT NULL PRIMARY KEY, + FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) +); +CREATE TABLE BOOK_METADATA_AGGREGATION_AUTHOR +( + NAME varchar NOT NULL, + ROLE varchar NOT NULL, + SERIES_ID varchar NOT NULL, + FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) +); +INSERT INTO BOOK_METADATA_AGGREGATION(SERIES_ID) +SELECT ID +from SERIES; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210308163522__book_isbn.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210308163522__book_isbn.sql new file mode 100644 index 00000000..b03e617e --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210308163522__book_isbn.sql @@ -0,0 +1,7 @@ +alter table library + add column IMPORT_BARCODE_ISBN boolean NOT NULL DEFAULT true; + +alter table book_metadata + add column ISBN varchar NOT NULL DEFAULT ''; +alter table book_metadata + add column ISBN_LOCK boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210504171645__library_convert_to_cbz.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210504171645__library_convert_to_cbz.sql new file mode 100644 index 00000000..b2d4f3c0 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210504171645__library_convert_to_cbz.sql @@ -0,0 +1,2 @@ +alter table library + add column CONVERT_TO_CBZ boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210505150806__library_repair_extensions.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210505150806__library_repair_extensions.sql new file mode 100644 index 00000000..68383060 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210505150806__library_repair_extensions.sql @@ -0,0 +1,2 @@ +alter table library + add column REPAIR_EXTENSIONS boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210517145427__fix_rar.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210517145427__fix_rar.sql new file mode 100644 index 00000000..96e034e8 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210517145427__fix_rar.sql @@ -0,0 +1,18 @@ +-- fix media type for files analyzed with tika 1.23 or before which didn't get the rar version +update MEDIA +set MEDIA_TYPE = 'application/x-rar-compressed; version=4' +where MEDIA_TYPE = 'application/x-rar-compressed' + and STATUS = 'READY'; + +-- rar files that could have had an incorrect analysis are marked at OUTDATED to be ra-analyzed +update MEDIA +set STATUS = 'OUTDATED' +where BOOK_ID in ( + select F.BOOK_ID + from MEDIA_FILE F + left join MEDIA M on F.BOOK_ID = M.BOOK_ID + where F.FILE_NAME like '%.%' + and M.MEDIA_TYPE like 'application/x-rar-compressed%' + and lower(replace(F.FILE_NAME, rtrim(F.FILE_NAME, replace(F.FILE_NAME, '.', '')), '')) + in ('jpg', 'jpeg', 'webp', 'tiff', 'tif', 'gif', 'png', 'bmp') + ); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210525172240__index.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210525172240__index.sql new file mode 100644 index 00000000..2ba70dfc --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210525172240__index.sql @@ -0,0 +1 @@ +CREATE INDEX idx__book_metadata_aggregation_author__series_id on BOOK_METADATA_AGGREGATION_AUTHOR (SERIES_ID); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210526113555__series_book_count.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210526113555__series_book_count.sql new file mode 100644 index 00000000..ac6f342a --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210526113555__series_book_count.sql @@ -0,0 +1,29 @@ +alter table SERIES + add column BOOK_COUNT int NOT NULL DEFAULT false; + +update SERIES +set BOOK_COUNT = ( + SELECT COUNT(b.ID) + FROM BOOK b + WHERE b.SERIES_ID = SERIES.ID + ); + +CREATE TABLE READ_PROGRESS_SERIES +( + SERIES_ID varchar NOT NULL, + USER_ID varchar NOT NULL, + READ_COUNT int NOT NULL, + IN_PROGRESS_COUNT int NOT NULL, + PRIMARY KEY (SERIES_ID, USER_ID), + FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID), + FOREIGN KEY (USER_ID) REFERENCES "USER" (ID) +); + +insert into READ_PROGRESS_SERIES +select BOOK.SERIES_ID, + READ_PROGRESS.USER_ID, + sum(case when READ_PROGRESS.COMPLETED = 1 then 1 else 0 end) as READ_COUNT, + sum(case when READ_PROGRESS.COMPLETED = 0 then 1 else 0 end) as IN_PROGRESS_COUNT +from BOOK + inner join READ_PROGRESS on (BOOK.ID = READ_PROGRESS.BOOK_ID) +group by BOOK.SERIES_ID, READ_PROGRESS.USER_ID; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210527100741__index_book_created.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210527100741__index_book_created.sql new file mode 100644 index 00000000..b7c0682e --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210527100741__index_book_created.sql @@ -0,0 +1,2 @@ +create index idx__book__created_date on BOOK (CREATED_DATE); + diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210609165742__sidecars.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210609165742__sidecars.sql new file mode 100644 index 00000000..ecd70cfa --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210609165742__sidecars.sql @@ -0,0 +1,7 @@ +CREATE TABLE SIDECAR +( + URL varchar NOT NULL PRIMARY KEY, + PARENT_URL varchar NOT NULL, + LAST_MODIFIED_TIME timestamp NOT NULL, + LIBRARY_ID varchar NOT NULL +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210617114814__sidecar_cleanup.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210617114814__sidecar_cleanup.sql new file mode 100644 index 00000000..254e7418 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210617114814__sidecar_cleanup.sql @@ -0,0 +1,6 @@ +DELETE +FROM SIDECAR +WHERE LIBRARY_ID NOT IN ( + SELECT ID + FROM LIBRARY + ) diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210625155626__authentication_activity.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210625155626__authentication_activity.sql new file mode 100644 index 00000000..0b165c38 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210625155626__authentication_activity.sql @@ -0,0 +1,11 @@ +create table AUTHENTICATION_ACTIVITY +( + USER_ID varchar NULL DEFAULT NULL, + EMAIL varchar NULL DEFAULT NULL, + IP varchar NULL DEFAULT NULL, + USER_AGENT varchar NULL DEFAULT NULL, + SUCCESS boolean NOT NULL, + ERROR varchar NULL DEFAULT NULL, + DATE_TIME timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (USER_ID) references "USER" (ID) +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210706162229__trash_bin.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210706162229__trash_bin.sql new file mode 100644 index 00000000..75dc791e --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210706162229__trash_bin.sql @@ -0,0 +1,11 @@ +ALTER TABLE BOOK + ADD COLUMN FILE_HASH varchar NOT NULL DEFAULT ''; + +ALTER TABLE BOOK + ADD COLUMN DELETED_DATE timestamp NULL DEFAULT NULL; + +ALTER TABLE SERIES + ADD COLUMN DELETED_DATE timestamp NULL DEFAULT NULL; + +alter table library + add column EMPTY_TRASH_AFTER_SCAN boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210716153910__library_import_mylar_metadata.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210716153910__library_import_mylar_metadata.sql new file mode 100644 index 00000000..a83f047d --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210716153910__library_import_mylar_metadata.sql @@ -0,0 +1,2 @@ +alter table library + add column IMPORT_MYLAR_SERIES boolean NOT NULL DEFAULT true; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210726140759__cover_preference.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210726140759__cover_preference.sql new file mode 100644 index 00000000..101e523c --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210726140759__cover_preference.sql @@ -0,0 +1,2 @@ +alter table library + add column SERIES_COVER varchar NOT NULL DEFAULT 'FIRST'; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210727102041__full_text_search.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210727102041__full_text_search.sql new file mode 100644 index 00000000..3bbf602e --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210727102041__full_text_search.sql @@ -0,0 +1,83 @@ +-- FTS for BOOK_METADATA +create virtual table fts_book_metadata using fts5(title, isbn, book_id UNINDEXED, content=book_metadata, tokenize = 'porter unicode61 remove_diacritics 2'); +INSERT INTO fts_book_metadata(fts_book_metadata) VALUES('rebuild'); + +-- Triggers to keep the FTS index up to date +CREATE TRIGGER book_metadata__after_insert AFTER INSERT ON book_metadata BEGIN + INSERT INTO fts_book_metadata(rowid, title, isbn, book_id) VALUES (new.rowid, new.title, new.isbn, new.book_id); +END; +CREATE TRIGGER book_metadata__after_delete AFTER DELETE ON book_metadata BEGIN + INSERT INTO fts_book_metadata(fts_book_metadata, rowid, title, isbn, book_id) VALUES('delete', old.rowid, old.title, old.isbn, old.book_id); +END; +CREATE TRIGGER book_metadata__after_update AFTER UPDATE ON book_metadata BEGIN + INSERT INTO fts_book_metadata(fts_book_metadata, rowid, title, isbn, book_id) VALUES('delete', old.rowid, old.title, old.isbn, old.book_id); + INSERT INTO fts_book_metadata(rowid, title, isbn, book_id) VALUES (new.rowid, new.title, new.isbn, new.book_id); +END; + + +-- FTS for SERIES_METADATA +create virtual table fts_series_metadata using fts5(title, publisher, series_id UNINDEXED, content=series_metadata, tokenize = 'porter unicode61 remove_diacritics 2'); +INSERT INTO fts_series_metadata(fts_series_metadata) VALUES('rebuild'); + +-- Triggers to keep the FTS index up to date +CREATE TRIGGER series_metadata__after_insert AFTER INSERT ON series_metadata BEGIN + INSERT INTO fts_series_metadata(rowid, title, publisher, series_id) VALUES (new.rowid, new.title, new.publisher, new.series_id); +END; +CREATE TRIGGER series_metadata__after_delete AFTER DELETE ON series_metadata BEGIN + INSERT INTO fts_series_metadata(fts_series_metadata, rowid, title, publisher, series_id) VALUES('delete', old.rowid, old.title, old.publisher, old.series_id); +END; +CREATE TRIGGER series_metadata__after_update AFTER UPDATE ON series_metadata BEGIN + INSERT INTO fts_series_metadata(fts_series_metadata, rowid, title, publisher, series_id) VALUES('delete', old.rowid, old.title, old.publisher, old.series_id); + INSERT INTO fts_series_metadata(rowid, title, publisher, series_id) VALUES (new.rowid, new.title, new.publisher, new.series_id); +END; + + +-- FTS for COLLECTION +create virtual table fts_collection using fts5(name, id UNINDEXED, content=collection, tokenize = 'porter unicode61 remove_diacritics 2'); +INSERT INTO fts_collection(fts_collection) VALUES('rebuild'); + +-- Triggers to keep the FTS index up to date +CREATE TRIGGER collection__after_insert AFTER INSERT ON collection BEGIN + INSERT INTO fts_collection(rowid, name, id) VALUES (new.rowid, new.name, new.id); +END; +CREATE TRIGGER collection__after_delete AFTER DELETE ON collection BEGIN + INSERT INTO fts_collection(fts_collection, rowid, name, id) VALUES('delete', old.rowid, old.name, old.id); +END; +CREATE TRIGGER collection__after_update AFTER UPDATE ON collection BEGIN + INSERT INTO fts_collection(fts_collection, rowid, name, id) VALUES('delete', old.rowid, old.name, old.id); + INSERT INTO fts_collection(rowid, name, id) VALUES (new.rowid, new.name, new.id); +END; + + +-- FTS for READLIST +create virtual table fts_readlist using fts5(name, id UNINDEXED, content=readlist, tokenize = 'porter unicode61 remove_diacritics 2'); +INSERT INTO fts_readlist(fts_readlist) VALUES('rebuild'); + +-- Triggers to keep the FTS index up to date +CREATE TRIGGER readlist__after_insert AFTER INSERT ON readlist BEGIN + INSERT INTO fts_readlist(rowid, name, id) VALUES (new.rowid, new.name, new.id); +END; +CREATE TRIGGER readlist__after_delete AFTER DELETE ON readlist BEGIN + INSERT INTO fts_readlist(fts_readlist, rowid, name, id) VALUES('delete', old.rowid, old.name, old.id); +END; +CREATE TRIGGER readlist__after_update AFTER UPDATE ON readlist BEGIN + INSERT INTO fts_readlist(fts_readlist, rowid, name, id) VALUES('delete', old.rowid, old.name, old.id); + INSERT INTO fts_readlist(rowid, name, id) VALUES (new.rowid, new.name, new.id); +END; + + +-- FTS for BOOK_METADATA_AGGREGATION_AUTHORS +create virtual table fts_book_metadata_aggregation_author using fts5(name, series_id UNINDEXED, content=book_metadata_aggregation_author, tokenize = 'porter unicode61 remove_diacritics 2'); +INSERT INTO fts_book_metadata_aggregation_author(fts_book_metadata_aggregation_author) VALUES('rebuild'); + +-- Triggers to keep the FTS index up to date +CREATE TRIGGER book_metadata_aggregation_author__after_insert AFTER INSERT ON book_metadata_aggregation_author BEGIN + INSERT INTO fts_book_metadata_aggregation_author(rowid, name, series_id) VALUES (new.rowid, new.name, new.series_id); +END; +CREATE TRIGGER book_metadata_aggregation_author__after_delete AFTER DELETE ON book_metadata_aggregation_author BEGIN + INSERT INTO fts_book_metadata_aggregation_author(fts_book_metadata_aggregation_author, rowid, name, series_id) VALUES('delete', old.rowid, old.name, old.series_id); +END; +CREATE TRIGGER book_metadata_aggregation_author__after_update AFTER UPDATE ON book_metadata_aggregation_author BEGIN + INSERT INTO fts_book_metadata_aggregation_author(fts_book_metadata_aggregation_author, rowid, name, series_id) VALUES('delete', old.rowid, old.name, old.series_id); + INSERT INTO fts_book_metadata_aggregation_author(rowid, name, series_id) VALUES (new.rowid, new.name, new.series_id); +END; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210729173532__series_metadata_total_book_count.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210729173532__series_metadata_total_book_count.sql new file mode 100644 index 00000000..7b33d140 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210729173532__series_metadata_total_book_count.sql @@ -0,0 +1,4 @@ +alter table series_metadata + add column TOTAL_BOOK_COUNT int NULL; +alter table series_metadata + add column TOTAL_BOOK_COUNT_LOCK boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210730111835__book_metadata_aggregation_tag.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210730111835__book_metadata_aggregation_tag.sql new file mode 100644 index 00000000..3aa42d3f --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210730111835__book_metadata_aggregation_tag.sql @@ -0,0 +1,12 @@ +CREATE TABLE BOOK_METADATA_AGGREGATION_TAG +( + TAG varchar NOT NULL, + SERIES_ID varchar NOT NULL, + FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) +); + +-- aggregate existing data +insert into BOOK_METADATA_AGGREGATION_TAG +select distinct bt.TAG, b.SERIES_ID +from BOOK_METADATA_TAG bt + left join BOOK B on B.ID = bt.BOOK_ID; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210730151147__readlist_summary.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210730151147__readlist_summary.sql new file mode 100644 index 00000000..e68907cf --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210730151147__readlist_summary.sql @@ -0,0 +1,2 @@ +alter table readlist + add column SUMMARY varchar not NULL default ''; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210805174355__remove_full_text_search.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210805174355__remove_full_text_search.sql new file mode 100644 index 00000000..b0f4a6f5 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210805174355__remove_full_text_search.sql @@ -0,0 +1,24 @@ +drop table fts_book_metadata; +DROP TRIGGER book_metadata__after_insert; +DROP TRIGGER book_metadata__after_delete; +DROP TRIGGER book_metadata__after_update; + +drop table fts_series_metadata; +DROP TRIGGER series_metadata__after_insert; +DROP TRIGGER series_metadata__after_delete; +DROP TRIGGER series_metadata__after_update; + +drop table fts_collection; +DROP TRIGGER collection__after_insert; +DROP TRIGGER collection__after_delete; +DROP TRIGGER collection__after_update; + +drop table fts_readlist; +DROP TRIGGER readlist__after_insert; +DROP TRIGGER readlist__after_delete; +DROP TRIGGER readlist__after_update; + +drop table fts_book_metadata_aggregation_author; +DROP TRIGGER book_metadata_aggregation_author__after_insert; +DROP TRIGGER book_metadata_aggregation_author__after_delete; +DROP TRIGGER book_metadata_aggregation_author__after_update; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210816113108__library_unavailable.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210816113108__library_unavailable.sql new file mode 100644 index 00000000..ae206840 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210816113108__library_unavailable.sql @@ -0,0 +1,2 @@ +ALTER TABLE LIBRARY + ADD COLUMN UNAVAILABLE_DATE timestamp NULL DEFAULT NULL; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210831113524__temp_table_urls.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210831113524__temp_table_urls.sql new file mode 100644 index 00000000..1f32483f --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210831113524__temp_table_urls.sql @@ -0,0 +1,4 @@ +CREATE TABLE TEMP_URL_LIST +( + URL varchar NOT NULL +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210902100930__series_thumbnail_blob.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210902100930__series_thumbnail_blob.sql new file mode 100644 index 00000000..4e0c5758 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210902100930__series_thumbnail_blob.sql @@ -0,0 +1,20 @@ +ALTER TABLE THUMBNAIL_SERIES RENAME TO TMP_THUMBNAIL_SERIES; + +CREATE TABLE THUMBNAIL_SERIES +( + ID varchar NOT NULL PRIMARY KEY, + URL varchar NULL DEFAULT NULL, + SELECTED boolean NOT NULL DEFAULT false, + THUMBNAIL bytea NULL DEFAULT NULL, + TYPE varchar not null, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + SERIES_ID varchar NOT NULL, + FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) +); + +INSERT INTO THUMBNAIL_SERIES(ID, URL, SELECTED, CREATED_DATE, LAST_MODIFIED_DATE, SERIES_ID, TYPE) +SELECT ID, URL, SELECTED, CREATED_DATE, LAST_MODIFIED_DATE, SERIES_ID, "SIDECAR" AS TYPE +FROM TMP_THUMBNAIL_SERIES; + +DROP TABLE TMP_THUMBNAIL_SERIES; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210906163333__series_metadata_lowercase_language.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210906163333__series_metadata_lowercase_language.sql new file mode 100644 index 00000000..8af8f66f --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210906163333__series_metadata_lowercase_language.sql @@ -0,0 +1,2 @@ +update SERIES_METADATA +set language = lower(language); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210907115532__spring_session.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210907115532__spring_session.sql new file mode 100644 index 00000000..eeb03127 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210907115532__spring_session.sql @@ -0,0 +1,24 @@ +CREATE TABLE SPRING_SESSION +( + PRIMARY_ID CHARACTER(36) NOT NULL, + SESSION_ID CHARACTER(36) NOT NULL, + CREATION_TIME INTEGER NOT NULL, + LAST_ACCESS_TIME INTEGER NOT NULL, + MAX_INACTIVE_INTERVAL INTEGER NOT NULL, + EXPIRY_TIME INTEGER NOT NULL, + PRINCIPAL_NAME VARCHAR(100), + CONSTRAINT SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID) +); + +CREATE UNIQUE INDEX SPRING_SESSION_IX1 ON SPRING_SESSION (SESSION_ID); +CREATE INDEX SPRING_SESSION_IX2 ON SPRING_SESSION (EXPIRY_TIME); +CREATE INDEX SPRING_SESSION_IX3 ON SPRING_SESSION (PRINCIPAL_NAME); + +CREATE TABLE SPRING_SESSION_ATTRIBUTES +( + SESSION_PRIMARY_ID CHAR(36) NOT NULL, + ATTRIBUTE_NAME VARCHAR(200) NOT NULL, + ATTRIBUTE_BYTES bytea NOT NULL, + CONSTRAINT SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID, ATTRIBUTE_NAME), + CONSTRAINT SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID) REFERENCES SPRING_SESSION (PRIMARY_ID) ON DELETE CASCADE +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210914111439__read_progress_read_date.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210914111439__read_progress_read_date.sql new file mode 100644 index 00000000..d31b36f4 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210914111439__read_progress_read_date.sql @@ -0,0 +1,21 @@ +ALTER TABLE READ_PROGRESS RENAME TO TMP_READ_PROGRESS; + +CREATE TABLE READ_PROGRESS +( + BOOK_ID varchar NOT NULL, + USER_ID varchar NOT NULL, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PAGE int NOT NULL, + COMPLETED boolean NOT NULL, + READ_DATE timestamp NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (BOOK_ID, USER_ID), + FOREIGN KEY (BOOK_ID) REFERENCES BOOK (ID), + FOREIGN KEY (USER_ID) REFERENCES "USER" (ID) +); + +INSERT INTO READ_PROGRESS(BOOK_ID, USER_ID, CREATED_DATE, LAST_MODIFIED_DATE, PAGE, COMPLETED, READ_DATE) +SELECT BOOK_ID, USER_ID, CREATED_DATE, LAST_MODIFIED_DATE, PAGE, COMPLETED, LAST_MODIFIED_DATE +FROM TMP_READ_PROGRESS; + +DROP TABLE TMP_READ_PROGRESS; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20210926222612__authentication_activity_source.sql b/komga/src/flyway/resources/db/migration/postgresql/V20210926222612__authentication_activity_source.sql new file mode 100644 index 00000000..23d92a65 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20210926222612__authentication_activity_source.sql @@ -0,0 +1,2 @@ +ALTER TABLE AUTHENTICATION_ACTIVITY + ADD COLUMN SOURCE varchar NULL DEFAULT NULL; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20211006141333__remove_spring_session.sql b/komga/src/flyway/resources/db/migration/postgresql/V20211006141333__remove_spring_session.sql new file mode 100644 index 00000000..c376f04a --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20211006141333__remove_spring_session.sql @@ -0,0 +1,2 @@ +drop table if exists SPRING_SESSION_ATTRIBUTES; +drop table if exists SPRING_SESSION; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20211206100610__temp_table_ids.sql b/komga/src/flyway/resources/db/migration/postgresql/V20211206100610__temp_table_ids.sql new file mode 100644 index 00000000..7f6d7b09 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20211206100610__temp_table_ids.sql @@ -0,0 +1,6 @@ +CREATE TABLE TEMP_STRING_LIST +( + STRING varchar NOT NULL +); + +DROP TABLE TEMP_URL_LIST; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20211206124920__collection_and_readlist_thumbnails.sql b/komga/src/flyway/resources/db/migration/postgresql/V20211206124920__collection_and_readlist_thumbnails.sql new file mode 100644 index 00000000..400be839 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20211206124920__collection_and_readlist_thumbnails.sql @@ -0,0 +1,23 @@ +CREATE TABLE THUMBNAIL_COLLECTION +( + ID varchar NOT NULL PRIMARY KEY, + SELECTED boolean NOT NULL DEFAULT false, + THUMBNAIL bytea NOT NULL, + TYPE varchar NOT NULL, + COLLECTION_ID varchar NOT NULL, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (COLLECTION_ID) REFERENCES COLLECTION (ID) +); + +CREATE TABLE THUMBNAIL_READLIST +( + ID varchar NOT NULL PRIMARY KEY, + SELECTED boolean NOT NULL DEFAULT false, + THUMBNAIL bytea NOT NULL, + TYPE varchar NOT NULL, + READLIST_ID varchar NOT NULL, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (READLIST_ID) REFERENCES READLIST (ID) +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20211228152113__book_metadata_link.sql b/komga/src/flyway/resources/db/migration/postgresql/V20211228152113__book_metadata_link.sql new file mode 100644 index 00000000..1655e8e5 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20211228152113__book_metadata_link.sql @@ -0,0 +1,10 @@ +CREATE TABLE BOOK_METADATA_LINK +( + LABEL varchar NOT NULL, + URL varchar NOT NULL, + BOOK_ID varchar NOT NULL, + FOREIGN KEY (BOOK_ID) REFERENCES BOOK (ID) +); + +alter table book_metadata + add column LINKS_LOCK boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20220101120232__page_hash.sql b/komga/src/flyway/resources/db/migration/postgresql/V20220101120232__page_hash.sql new file mode 100644 index 00000000..9de5e685 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20220101120232__page_hash.sql @@ -0,0 +1,2 @@ +ALTER TABLE MEDIA_PAGE + ADD COLUMN FILE_HASH varchar NOT NULL DEFAULT ''; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20220105143154__library_hashing_options.sql b/komga/src/flyway/resources/db/migration/postgresql/V20220105143154__library_hashing_options.sql new file mode 100644 index 00000000..c693aa45 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20220105143154__library_hashing_options.sql @@ -0,0 +1,6 @@ +alter table library + add column HASH_FILES boolean NOT NULL DEFAULT ${library-file-hashing}; +alter table library + add column HASH_PAGES boolean NOT NULL DEFAULT false; +alter table library + add column ANALYZE_DIMENSIONS boolean NOT NULL DEFAULT true; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20220106143755__page_file_size.sql b/komga/src/flyway/resources/db/migration/postgresql/V20220106143755__page_file_size.sql new file mode 100644 index 00000000..c0d319e8 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20220106143755__page_file_size.sql @@ -0,0 +1,2 @@ +alter table media_page + add column FILE_SIZE bigint NULL; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20220128152310__page_hash.sql b/komga/src/flyway/resources/db/migration/postgresql/V20220128152310__page_hash.sql new file mode 100644 index 00000000..6b4c2375 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20220128152310__page_hash.sql @@ -0,0 +1,30 @@ +CREATE TABLE PAGE_HASH +( + HASH varchar NOT NULL, + MEDIA_TYPE varchar NOT NULL, + SIZE bigint NULL, + ACTION varchar NOT NULL, + DELETE_COUNT int NOT NULL DEFAULT false, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (HASH, MEDIA_TYPE, SIZE) +); + +CREATE TABLE PAGE_HASH_THUMBNAIL +( + HASH varchar NOT NULL, + MEDIA_TYPE varchar NOT NULL, + SIZE bigint NULL, + THUMBNAIL bytea NOT NULL, + PRIMARY KEY (HASH, MEDIA_TYPE, SIZE) +); + +UPDATE MEDIA_PAGE +SET FILE_HASH = '' +WHERE BOOK_ID IN ( + SELECT DISTINCT m.BOOK_ID + FROM MEDIA m + LEFT JOIN MEDIA_PAGE MP on m.BOOK_ID = MP.BOOK_ID + WHERE mp.FILE_HASH <> '' + AND m.MEDIA_TYPE <> 'application/zip' +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20220208193203__fix_books_with_missing_pages.sql b/komga/src/flyway/resources/db/migration/postgresql/V20220208193203__fix_books_with_missing_pages.sql new file mode 100644 index 00000000..5bbb95db --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20220208193203__fix_books_with_missing_pages.sql @@ -0,0 +1,8 @@ +UPDATE MEDIA +SET STATUS = 'OUTDATED' +WHERE BOOK_ID IN ( + SELECT M.BOOK_ID + FROM MEDIA M + LEFT JOIN MEDIA_PAGE MP on M.BOOK_ID = MP.BOOK_ID + GROUP BY M.BOOK_ID, M.PAGE_COUNT + HAVING M.PAGE_COUNT <> count(MP.BOOK_ID)); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20220218111455__historical_events.sql b/komga/src/flyway/resources/db/migration/postgresql/V20220218111455__historical_events.sql new file mode 100644 index 00000000..66a266cc --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20220218111455__historical_events.sql @@ -0,0 +1,17 @@ +CREATE TABLE HISTORICAL_EVENT +( + ID varchar PRIMARY KEY, + TYPE varchar NOT NULL, + BOOK_ID varchar NULL, + SERIES_ID varchar NULL, + TIMESTAMP timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE HISTORICAL_EVENT_PROPERTIES +( + ID varchar NOT NULL, + KEY varchar NOT NULL, + VALUE varchar NOT NULL, + PRIMARY KEY (ID, KEY), + FOREIGN KEY (ID) REFERENCES HISTORICAL_EVENT (ID) +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20220224112015__series_sharing_labels.sql b/komga/src/flyway/resources/db/migration/postgresql/V20220224112015__series_sharing_labels.sql new file mode 100644 index 00000000..81e0313a --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20220224112015__series_sharing_labels.sql @@ -0,0 +1,9 @@ +CREATE TABLE SERIES_METADATA_SHARING +( + LABEL varchar NOT NULL, + SERIES_ID varchar NOT NULL, + FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) +); + +alter table SERIES_METADATA + add column SHARING_LABELS_LOCK boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20220225164240__user_restrictions.sql b/komga/src/flyway/resources/db/migration/postgresql/V20220225164240__user_restrictions.sql new file mode 100644 index 00000000..5404395c --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20220225164240__user_restrictions.sql @@ -0,0 +1,13 @@ +CREATE TABLE USER_SHARING +( + LABEL varchar NOT NULL, + ALLOW boolean NOT NULL, + USER_ID varchar NOT NULL, + PRIMARY KEY (LABEL, ALLOW, USER_ID), + FOREIGN KEY (USER_ID) REFERENCES "USER" (ID) +); + +ALTER TABLE "USER" + add column AGE_RESTRICTION integer NULL; +ALTER TABLE "USER" + add column AGE_RESTRICTION_ALLOW_ONLY boolean NULL; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20220715213721__perf_indices.sql b/komga/src/flyway/resources/db/migration/postgresql/V20220715213721__perf_indices.sql new file mode 100644 index 00000000..c07827c7 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20220715213721__perf_indices.sql @@ -0,0 +1,31 @@ +-- missing foreign key indices +create index if not exists idx__book_metadata_link__book_id + on BOOK_METADATA_LINK (BOOK_ID); +create index if not exists idx__series_metadata_sharing__series_id + on SERIES_METADATA_SHARING (SERIES_ID); +create index if not exists idx__book_metadata_aggregation_tag__series_id + on BOOK_METADATA_AGGREGATION_TAG (SERIES_ID); +create index if not exists idx__thumbnail_collection__collection_id + on THUMBNAIL_COLLECTION (COLLECTION_ID); +create index if not exists idx__thumbnail_readlist__readlist_id + on THUMBNAIL_READLIST (READLIST_ID); +create index if not exists idx__thumbnail_series__series_id + on THUMBNAIL_SERIES (SERIES_ID); +create index if not exists idx__authentication_activity__user_id + on AUTHENTICATION_ACTIVITY (USER_ID); + +-- if you sort by it, index it +create index if not exists idx__book_metadata__number_sort + on BOOK_METADATA (NUMBER_SORT); +create index if not exists idx__series__last_modified_date + on SERIES (LAST_MODIFIED_DATE); +create index if not exists idx__series__created_date + on SERIES (CREATED_DATE); +create index if not exists idx__book_metadata__release_date + on BOOK_METADATA (RELEASE_DATE); +create index if not exists idx__book__created_date + on BOOK (CREATED_DATE); +create index if not exists idx__read_progress__last_modified_date + on READ_PROGRESS (LAST_MODIFIED_DATE); +create index if not exists idx__media__status + on MEDIA (STATUS); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230112151202__library_comicinfo_append_volume.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230112151202__library_comicinfo_append_volume.sql new file mode 100644 index 00000000..e54379e9 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230112151202__library_comicinfo_append_volume.sql @@ -0,0 +1,2 @@ +ALTER TABLE LIBRARY + add column IMPORT_COMICINFO_SERIES_APPEND_VOLUME boolean NOT NULL DEFAULT true; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230113140806__series_metadata_link.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230113140806__series_metadata_link.sql new file mode 100644 index 00000000..4c52c931 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230113140806__series_metadata_link.sql @@ -0,0 +1,13 @@ +CREATE TABLE SERIES_METADATA_LINK +( + LABEL varchar NOT NULL, + URL varchar NOT NULL, + SERIES_ID varchar NOT NULL, + FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) +); + +alter table series_metadata + add column LINKS_LOCK boolean NOT NULL DEFAULT false; + +create index idx__series_metadata_link__series_id + on SERIES_METADATA_LINK (SERIES_ID); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230116112647__series_alternate_title.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230116112647__series_alternate_title.sql new file mode 100644 index 00000000..d879f64e --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230116112647__series_alternate_title.sql @@ -0,0 +1,13 @@ +CREATE TABLE SERIES_METADATA_ALTERNATE_TITLE +( + LABEL varchar NOT NULL, + TITLE varchar NOT NULL, + SERIES_ID varchar NOT NULL, + FOREIGN KEY (SERIES_ID) REFERENCES SERIES (ID) +); + +alter table series_metadata + add column ALTERNATE_TITLES_LOCK boolean NOT NULL DEFAULT false; + +create index idx__series_metadata_alternate_title__series_id + on SERIES_METADATA_ALTERNATE_TITLE (SERIES_ID); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230221170726__readlist_ordered.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230221170726__readlist_ordered.sql new file mode 100644 index 00000000..fc5882d5 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230221170726__readlist_ordered.sql @@ -0,0 +1,2 @@ +alter table READLIST + add column ORDERED boolean NOT NULL DEFAULT true; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230310121946__series_metadata_index.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230310121946__series_metadata_index.sql new file mode 100644 index 00000000..4e869ce5 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230310121946__series_metadata_index.sql @@ -0,0 +1,2 @@ +create index if not exists idx__series_metadata__title + on SERIES_METADATA (TITLE); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230626150454__xxhash128.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230626150454__xxhash128.sql new file mode 100644 index 00000000..6c6c76fd --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230626150454__xxhash128.sql @@ -0,0 +1,4 @@ +delete from PAGE_HASH; +delete from PAGE_HASH_THUMBNAIL; +update BOOK set FILE_HASH = ''; +update MEDIA_PAGE set FILE_HASH = ''; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230626151717__missing_page_size.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230626151717__missing_page_size.sql new file mode 100644 index 00000000..c28dceea --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230626151717__missing_page_size.sql @@ -0,0 +1,8 @@ +update media +set STATUS = 'OUTDATED' +WHERE BOOK_ID in + (select distinct M.BOOK_ID + from MEDIA_PAGE P + inner join MEDIA M on P.BOOK_ID = M.BOOK_ID + where M.MEDIA_TYPE in ('application/zip', 'application/x-rar-compressed; version=4') + and P.FILE_SIZE is null); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230626170856__page_hash_remove_columns.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230626170856__page_hash_remove_columns.sql new file mode 100644 index 00000000..0e09f7cc --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230626170856__page_hash_remove_columns.sql @@ -0,0 +1,33 @@ +ALTER TABLE PAGE_HASH + RENAME TO _PAGE_HASH_OLD; + +CREATE TABLE PAGE_HASH +( + HASH varchar NOT NULL PRIMARY KEY, + SIZE bigint NULL, + ACTION varchar NOT NULL, + DELETE_COUNT int NOT NULL DEFAULT false, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +INSERT INTO PAGE_HASH(HASH, ACTION, SIZE, DELETE_COUNT, CREATED_DATE, LAST_MODIFIED_DATE) +SELECT HASH, ACTION, SIZE, DELETE_COUNT, CREATED_DATE, LAST_MODIFIED_DATE +FROM _PAGE_HASH_OLD; + +DROP TABLE _PAGE_HASH_OLD; + +ALTER TABLE PAGE_HASH_THUMBNAIL + RENAME TO _PAGE_HASH_THUMBNAIL_OLD; + +CREATE TABLE PAGE_HASH_THUMBNAIL +( + HASH varchar NOT NULL PRIMARY KEY, + THUMBNAIL bytea NOT NULL +); + +INSERT INTO PAGE_HASH_THUMBNAIL(HASH, THUMBNAIL) +SELECT HASH, THUMBNAIL +FROM _PAGE_HASH_THUMBNAIL_OLD; + +DROP TABLE _PAGE_HASH_THUMBNAIL_OLD; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230629114356__remove_library_scandeep_column.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230629114356__remove_library_scandeep_column.sql new file mode 100644 index 00000000..fa4477ed --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230629114356__remove_library_scandeep_column.sql @@ -0,0 +1,2 @@ +ALTER TABLE LIBRARY + RENAME COLUMN SCAN_DEEP to _UNUSED; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230711173700__read_announcements.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230711173700__read_announcements.sql new file mode 100644 index 00000000..41d35ada --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230711173700__read_announcements.sql @@ -0,0 +1,7 @@ +create table ANNOUNCEMENTS_READ +( + USER_ID varchar NOT NULL, + ANNOUNCEMENT_ID varchar NOT NULL, + PRIMARY KEY (USER_ID, ANNOUNCEMENT_ID), + FOREIGN KEY (USER_ID) references "USER" (ID) +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230724114349__oneshots.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230724114349__oneshots.sql new file mode 100644 index 00000000..6d0e74f1 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230724114349__oneshots.sql @@ -0,0 +1,8 @@ +alter table BOOK + add column oneshot boolean NOT NULL DEFAULT false; + +alter table SERIES + add column oneshot boolean NOT NULL DEFAULT false; + +ALTER TABLE LIBRARY + add column ONESHOTS_DIRECTORY varchar NULL DEFAULT NULL; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230918114751__library_settings.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230918114751__library_settings.sql new file mode 100644 index 00000000..5d6feee2 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230918114751__library_settings.sql @@ -0,0 +1,12 @@ +ALTER TABLE LIBRARY + RENAME COLUMN _UNUSED to SCAN_STARTUP; +UPDATE LIBRARY +SET SCAN_STARTUP = ${library-scan-startup}; +ALTER TABLE LIBRARY + add column SCAN_CBX boolean NOT NULL DEFAULT true; +ALTER TABLE LIBRARY + add column SCAN_PDF boolean NOT NULL DEFAULT true; +ALTER TABLE LIBRARY + add column SCAN_EPUB boolean NOT NULL DEFAULT true; +ALTER TABLE LIBRARY + add column SCAN_INTERVAL varchar NOT NULL DEFAULT 'EVERY_6H'; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230921112923__library_directory_exclusions.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230921112923__library_directory_exclusions.sql new file mode 100644 index 00000000..b52b72fc --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230921112923__library_directory_exclusions.sql @@ -0,0 +1,17 @@ +CREATE TABLE LIBRARY_EXCLUSIONS +( + LIBRARY_ID varchar NOT NULL, + EXCLUSION varchar NOT NULL, + PRIMARY KEY (LIBRARY_ID, EXCLUSION), + FOREIGN KEY (LIBRARY_ID) REFERENCES LIBRARY (ID) +); + +CREATE INDEX idx__library_exclusions__library_id on LIBRARY_EXCLUSIONS (LIBRARY_ID); + +INSERT INTO LIBRARY_EXCLUSIONS +WITH cte_exclusions(exclude) AS (VALUES ('#recycle'), + ('@eaDir'), + ('@Recycle')) +SELECT LIBRARY.ID, cte_exclusions.exclude +FROM LIBRARY + cross join cte_exclusions; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20230922143307__server_settings.sql b/komga/src/flyway/resources/db/migration/postgresql/V20230922143307__server_settings.sql new file mode 100644 index 00000000..9f918c4d --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20230922143307__server_settings.sql @@ -0,0 +1,14 @@ +CREATE TABLE SERVER_SETTINGS +( + KEY varchar NOT NULL PRIMARY KEY, + VALUE varchar NULL +); + +INSERT INTO SERVER_SETTINGS +VALUES ('DELETE_EMPTY_COLLECTIONS', ${delete-empty-collections}); +INSERT INTO SERVER_SETTINGS +VALUES ('DELETE_EMPTY_READLISTS', ${delete-empty-read-lists}); +INSERT INTO SERVER_SETTINGS +VALUES ('REMEMBER_ME_KEY', hex(randomblob(32))); +INSERT INTO SERVER_SETTINGS +VALUES ('REMEMBER_ME_DURATION', 365); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20231005165322__thumbnails_additional_info.sql b/komga/src/flyway/resources/db/migration/postgresql/V20231005165322__thumbnails_additional_info.sql new file mode 100644 index 00000000..859f933a --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20231005165322__thumbnails_additional_info.sql @@ -0,0 +1,36 @@ +ALTER TABLE main.THUMBNAIL_BOOK + add column WIDTH int NOT NULL DEFAULT false; +ALTER TABLE main.THUMBNAIL_BOOK + add column HEIGHT int NOT NULL DEFAULT false; +ALTER TABLE main.THUMBNAIL_BOOK + add column MEDIA_TYPE varchar NOT NULL default ''; +ALTER TABLE main.THUMBNAIL_BOOK + add column FILE_SIZE bigint NOT NULL DEFAULT false; + +ALTER TABLE main.THUMBNAIL_SERIES + add column WIDTH int NOT NULL DEFAULT false; +ALTER TABLE main.THUMBNAIL_SERIES + add column HEIGHT int NOT NULL DEFAULT false; +ALTER TABLE main.THUMBNAIL_SERIES + add column MEDIA_TYPE varchar NOT NULL default ''; +ALTER TABLE main.THUMBNAIL_SERIES + add column FILE_SIZE bigint NOT NULL DEFAULT false; + +ALTER TABLE main.THUMBNAIL_COLLECTION + add column WIDTH int NOT NULL DEFAULT false; +ALTER TABLE main.THUMBNAIL_COLLECTION + add column HEIGHT int NOT NULL DEFAULT false; +ALTER TABLE main.THUMBNAIL_COLLECTION + add column MEDIA_TYPE varchar NOT NULL default ''; +ALTER TABLE main.THUMBNAIL_COLLECTION + add column FILE_SIZE bigint NOT NULL DEFAULT false; + +ALTER TABLE main.THUMBNAIL_READLIST + add column WIDTH int NOT NULL DEFAULT false; +ALTER TABLE main.THUMBNAIL_READLIST + add column HEIGHT int NOT NULL DEFAULT false; +ALTER TABLE main.THUMBNAIL_READLIST + add column MEDIA_TYPE varchar NOT NULL default ''; +ALTER TABLE main.THUMBNAIL_READLIST + add column FILE_SIZE bigint NOT NULL DEFAULT false; + diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20231026164836__thumbnail_book_indices.sql b/komga/src/flyway/resources/db/migration/postgresql/V20231026164836__thumbnail_book_indices.sql new file mode 100644 index 00000000..e405ae3d --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20231026164836__thumbnail_book_indices.sql @@ -0,0 +1,6 @@ +create index idx__thumbnail_book__width + on THUMBNAIL_BOOK (WIDTH); +create index idx__thumbnail_book__height + on THUMBNAIL_BOOK (HEIGHT); +create index idx__thumbnail_book__file_size + on THUMBNAIL_BOOK (FILE_SIZE); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20231115163730__analyze_pdf.sql b/komga/src/flyway/resources/db/migration/postgresql/V20231115163730__analyze_pdf.sql new file mode 100644 index 00000000..50f7a8de --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20231115163730__analyze_pdf.sql @@ -0,0 +1,4 @@ +update media +set STATUS = 'OUTDATED' +where MEDIA_TYPE = 'application/pdf' + and STATUS = 'READY'; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20231116162048__epub.sql b/komga/src/flyway/resources/db/migration/postgresql/V20231116162048__epub.sql new file mode 100644 index 00000000..c179476a --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20231116162048__epub.sql @@ -0,0 +1,16 @@ +alter table MEDIA_FILE + add column MEDIA_TYPE varchar NULL; +alter table MEDIA_FILE + add column SUB_TYPE varchar NULL; +alter table MEDIA_FILE + add column FILE_SIZE bigint NULL; + +alter table MEDIA + add column EXTENSION_CLASS varchar NULL; +alter table MEDIA + add column EXTENSION_VALUE varchar NULL; + +update media +set STATUS = 'OUTDATED' +where MEDIA_TYPE = 'application/epub+zip' + and STATUS = 'READY'; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20231201115954__media_extension_blob.sql b/komga/src/flyway/resources/db/migration/postgresql/V20231201115954__media_extension_blob.sql new file mode 100644 index 00000000..970a14b7 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20231201115954__media_extension_blob.sql @@ -0,0 +1,13 @@ +update MEDIA +set EXTENSION_VALUE = null; + +update media +set STATUS = 'OUTDATED' +where MEDIA_TYPE = 'application/epub+zip' + and STATUS = 'READY'; + +ALTER TABLE MEDIA + RENAME COLUMN EXTENSION_VALUE to _UNUSED; + +alter table MEDIA + add column EXTENSION_VALUE_BLOB bytea NULL; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20231206152158__progression.sql b/komga/src/flyway/resources/db/migration/postgresql/V20231206152158__progression.sql new file mode 100644 index 00000000..90bae4fd --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20231206152158__progression.sql @@ -0,0 +1,6 @@ +ALTER TABLE READ_PROGRESS + ADD COLUMN device_id varchar default ''; +ALTER TABLE READ_PROGRESS + ADD COLUMN device_name varchar default ''; +ALTER TABLE READ_PROGRESS + ADD COLUMN locator bytea null; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20231213170042__cleanup_empty_thumbnails.sql b/komga/src/flyway/resources/db/migration/postgresql/V20231213170042__cleanup_empty_thumbnails.sql new file mode 100644 index 00000000..33293b5b --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20231213170042__cleanup_empty_thumbnails.sql @@ -0,0 +1,4 @@ +delete +from THUMBNAIL_BOOK +where TYPE = 'GENERATED' + and THUMBNAIL is null; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20231214152305__epub_divina_compatibility.sql b/komga/src/flyway/resources/db/migration/postgresql/V20231214152305__epub_divina_compatibility.sql new file mode 100644 index 00000000..f029e23b --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20231214152305__epub_divina_compatibility.sql @@ -0,0 +1,2 @@ +alter table MEDIA + add column EPUB_DIVINA_COMPATIBLE boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20231214163213__reanalyze_epub.sql b/komga/src/flyway/resources/db/migration/postgresql/V20231214163213__reanalyze_epub.sql new file mode 100644 index 00000000..9aa1d063 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20231214163213__reanalyze_epub.sql @@ -0,0 +1,9 @@ +update media +set STATUS = 'OUTDATED' +where MEDIA_TYPE = 'application/epub+zip'; + +update media +set STATUS = 'OUTDATED' +where BOOK_ID in (select ID + from BOOK + where URL like '%.epub' collate NOCASE); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20240529120933__apikey.sql b/komga/src/flyway/resources/db/migration/postgresql/V20240529120933__apikey.sql new file mode 100644 index 00000000..e196c18e --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20240529120933__apikey.sql @@ -0,0 +1,18 @@ +CREATE TABLE USER_API_KEY +( + ID varchar NOT NULL PRIMARY KEY, + USER_ID varchar NOT NULL, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + LAST_MODIFIED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + API_KEY varchar NOT NULL UNIQUE, + COMMENT varchar NOT NULL, + FOREIGN KEY (USER_ID) REFERENCES "USER" (ID) +); + +create index if not exists idx__user_api_key__user_id + on USER_API_KEY (USER_ID); + +ALTER TABLE AUTHENTICATION_ACTIVITY + ADD COLUMN API_KEY_ID varchar NULL DEFAULT NULL; +ALTER TABLE AUTHENTICATION_ACTIVITY + ADD COLUMN API_KEY_COMMENT varchar NULL DEFAULT NULL; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20240529120934__syncpoint.sql b/komga/src/flyway/resources/db/migration/postgresql/V20240529120934__syncpoint.sql new file mode 100644 index 00000000..94d77be0 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20240529120934__syncpoint.sql @@ -0,0 +1,41 @@ +CREATE TABLE SYNC_POINT +( + ID varchar NOT NULL PRIMARY KEY, + CREATED_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + USER_ID varchar NOT NULL, + API_KEY_ID varchar NULL, + FOREIGN KEY (USER_ID) REFERENCES "USER" (ID) +); + +create index if not exists idx__sync_point__user_id + on SYNC_POINT (USER_ID); + +CREATE TABLE SYNC_POINT_BOOK_REMOVED_SYNCED +( + SYNC_POINT_ID varchar NOT NULL, + BOOK_ID varchar NOT NULL, + PRIMARY KEY (SYNC_POINT_ID, BOOK_ID), + FOREIGN KEY (SYNC_POINT_ID) REFERENCES SYNC_POINT (ID) +); + +create index if not exists idx__sync_point_book_removed_status__sync_point_id + on SYNC_POINT_BOOK_REMOVED_SYNCED (SYNC_POINT_ID); + +CREATE TABLE SYNC_POINT_BOOK +( + SYNC_POINT_ID varchar NOT NULL, + BOOK_ID varchar NOT NULL, + BOOK_CREATED_DATE timestamp NOT NULL, + BOOK_LAST_MODIFIED_DATE timestamp NOT NULL, + BOOK_FILE_LAST_MODIFIED timestamp NOT NULL, + BOOK_FILE_SIZE bigint NOT NULL, + BOOK_FILE_HASH varchar NOT NULL, + BOOK_METADATA_LAST_MODIFIED_DATE timestamp NOT NULL, + BOOK_READ_PROGRESS_LAST_MODIFIED_DATE timestamp NULL, + SYNCED boolean NOT NULL default false, + PRIMARY KEY (SYNC_POINT_ID, BOOK_ID), + FOREIGN KEY (SYNC_POINT_ID) REFERENCES SYNC_POINT (ID) +); + +create index if not exists idx__sync_point_book__sync_point_id + on SYNC_POINT_BOOK (SYNC_POINT_ID); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20240614170012__user_kobo_role.sql b/komga/src/flyway/resources/db/migration/postgresql/V20240614170012__user_kobo_role.sql new file mode 100644 index 00000000..5c8e30e7 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20240614170012__user_kobo_role.sql @@ -0,0 +1,6 @@ +alter table "USER" + add column ROLE_KOBO_SYNC boolean NOT NULL DEFAULT false; + +update "USER" +set ROLE_KOBO_SYNC = 1 +where ROLE_ADMIN = 1; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20240906152500__read_progress_series_read_date.sql b/komga/src/flyway/resources/db/migration/postgresql/V20240906152500__read_progress_series_read_date.sql new file mode 100644 index 00000000..2caffc58 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20240906152500__read_progress_series_read_date.sql @@ -0,0 +1,16 @@ +alter table READ_PROGRESS_SERIES + add MOST_RECENT_READ_DATE timestamp NULL; +alter table READ_PROGRESS_SERIES + add LAST_MODIFIED_DATE timestamp NULL; + +update READ_PROGRESS_SERIES +set MOST_RECENT_READ_DATE = (select max(r.READ_DATE) + from READ_PROGRESS r + inner join BOOK b on r.BOOK_ID = b.ID + where b.SERIES_ID = READ_PROGRESS_SERIES.SERIES_ID); + +update READ_PROGRESS_SERIES +set LAST_MODIFIED_DATE = (select max(r.LAST_MODIFIED_DATE) + from READ_PROGRESS r + inner join BOOK b on r.BOOK_ID = b.ID + where b.SERIES_ID = READ_PROGRESS_SERIES.SERIES_ID); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20240909112827__syncpoint_readlists.sql b/komga/src/flyway/resources/db/migration/postgresql/V20240909112827__syncpoint_readlists.sql new file mode 100644 index 00000000..0d078cb3 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20240909112827__syncpoint_readlists.sql @@ -0,0 +1,34 @@ +CREATE TABLE SYNC_POINT_READLIST +( + SYNC_POINT_ID varchar NOT NULL, + READLIST_ID varchar NOT NULL, + READLIST_NAME varchar NOT NULL, + READLIST_CREATED_DATE timestamp NOT NULL, + READLIST_LAST_MODIFIED_DATE timestamp NOT NULL, + SYNCED boolean NOT NULL default false, + PRIMARY KEY (SYNC_POINT_ID, READLIST_ID), + FOREIGN KEY (SYNC_POINT_ID) REFERENCES SYNC_POINT (ID) +); + +create index if not exists idx__sync_point_readlist__sync_point_id + on SYNC_POINT_READLIST (SYNC_POINT_ID); + +CREATE TABLE SYNC_POINT_READLIST_BOOK +( + SYNC_POINT_ID varchar NOT NULL, + READLIST_ID varchar NOT NULL, + BOOK_ID varchar NOT NULL, + PRIMARY KEY (SYNC_POINT_ID, READLIST_ID, BOOK_ID), + FOREIGN KEY (SYNC_POINT_ID) REFERENCES SYNC_POINT (ID) +); + +create index if not exists idx__sync_point_readlist_book__sync_point_id_readlist_id + on SYNC_POINT_READLIST_BOOK (SYNC_POINT_ID, READLIST_ID); + +CREATE TABLE SYNC_POINT_READLIST_REMOVED_SYNCED +( + SYNC_POINT_ID varchar NOT NULL, + READLIST_ID varchar NOT NULL, + PRIMARY KEY (SYNC_POINT_ID, READLIST_ID), + FOREIGN KEY (SYNC_POINT_ID) REFERENCES SYNC_POINT (ID) +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20240911175419__kepub.sql b/komga/src/flyway/resources/db/migration/postgresql/V20240911175419__kepub.sql new file mode 100644 index 00000000..86032472 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20240911175419__kepub.sql @@ -0,0 +1,2 @@ +alter table MEDIA + add column EPUB_IS_KEPUB boolean NOT NULL DEFAULT false; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20240925174446__syncpoint_covers.sql b/komga/src/flyway/resources/db/migration/postgresql/V20240925174446__syncpoint_covers.sql new file mode 100644 index 00000000..dca31cd1 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20240925174446__syncpoint_covers.sql @@ -0,0 +1,2 @@ +ALTER TABLE main.SYNC_POINT_BOOK + ADD COLUMN BOOK_THUMBNAIL_ID varchar NULL; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20250108115503__user_roles.sql b/komga/src/flyway/resources/db/migration/postgresql/V20250108115503__user_roles.sql new file mode 100644 index 00000000..76aed22e --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20250108115503__user_roles.sql @@ -0,0 +1,68 @@ +CREATE TABLE USER_ROLE +( + USER_ID varchar NOT NULL, + ROLE varchar NOT NULL, + PRIMARY KEY (USER_ID, ROLE), + FOREIGN KEY (USER_ID) REFERENCES "USER" (ID) +); + +insert into USER_ROLE +select id, "ADMIN" +from user +where ROLE_ADMIN = 1; + +insert into USER_ROLE +select id, "KOREADER_SYNC" +from user +where ROLE_ADMIN = 1; + +insert into USER_ROLE +select id, "FILE_DOWNLOAD" +from user +where ROLE_FILE_DOWNLOAD = 1; + +insert into USER_ROLE +select id, "PAGE_STREAMING" +from user +where ROLE_PAGE_STREAMING = 1; + +insert into USER_ROLE +select id, "KOBO_SYNC" +from user +where ROLE_KOBO_SYNC = 1; + +-- Remove columns ROLE_ADMIN, ROLE_FILE_DOWNLOAD, ROLE_PAGE_STREAMING, ROLE_KOBO_SYNC from "USER" +PRAGMA foreign_keys= OFF; + +create table USER_dg_tmp +( + ID varchar not null + primary key, + CREATED_DATE timestamp default CURRENT_TIMESTAMP not null, + LAST_MODIFIED_DATE timestamp default CURRENT_TIMESTAMP not null, + EMAIL varchar not null + unique, + PASSWORD varchar not null, + SHARED_ALL_LIBRARIES boolean DEFAULT true not null, + AGE_RESTRICTION integer, + AGE_RESTRICTION_ALLOW_ONLY boolean +); + +insert into USER_dg_tmp(ID, CREATED_DATE, LAST_MODIFIED_DATE, EMAIL, PASSWORD, SHARED_ALL_LIBRARIES, AGE_RESTRICTION, + AGE_RESTRICTION_ALLOW_ONLY) +select ID, + CREATED_DATE, + LAST_MODIFIED_DATE, + EMAIL, + PASSWORD, + SHARED_ALL_LIBRARIES, + AGE_RESTRICTION, + AGE_RESTRICTION_ALLOW_ONLY +from "USER"; + +drop table "USER"; + +alter table USER_dg_tmp + rename to "USER"; + +PRAGMA foreign_keys= ON; diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20250108172343__koreader_hash.sql b/komga/src/flyway/resources/db/migration/postgresql/V20250108172343__koreader_hash.sql new file mode 100644 index 00000000..d9dc6bc8 --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20250108172343__koreader_hash.sql @@ -0,0 +1,6 @@ +ALTER TABLE LIBRARY + add column HASH_KOREADER boolean NOT NULL DEFAULT false; + +ALTER TABLE BOOK + ADD COLUMN FILE_HASH_KOREADER varchar NOT NULL DEFAULT ''; + diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20250205151235__client_settings.sql b/komga/src/flyway/resources/db/migration/postgresql/V20250205151235__client_settings.sql new file mode 100644 index 00000000..fcb10d7c --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20250205151235__client_settings.sql @@ -0,0 +1,15 @@ +CREATE TABLE CLIENT_SETTINGS_GLOBAL +( + KEY varchar NOT NULL PRIMARY KEY, + VALUE varchar NOT NULL, + ALLOW_UNAUTHORIZED boolean NOT NULL DEFAULT false +); + +CREATE TABLE CLIENT_SETTINGS_USER +( + USER_ID varchar NOT NULL, + KEY varchar NOT NULL, + VALUE varchar NOT NULL, + FOREIGN KEY (USER_ID) REFERENCES "USER" (ID), + PRIMARY KEY (KEY, USER_ID) +); diff --git a/komga/src/flyway/resources/db/migration/postgresql/V20250730173126__remove_temp_string_table.sql b/komga/src/flyway/resources/db/migration/postgresql/V20250730173126__remove_temp_string_table.sql new file mode 100644 index 00000000..ed9da7fb --- /dev/null +++ b/komga/src/flyway/resources/db/migration/postgresql/V20250730173126__remove_temp_string_table.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS TEMP_STRING_LIST; diff --git a/komga/src/test/kotlin/org/gotson/komga/infrastructure/datasource/PostgreSQLIntegrationTest.kt b/komga/src/test/kotlin/org/gotson/komga/infrastructure/datasource/PostgreSQLIntegrationTest.kt index eaf6180d..2bb8b184 100644 --- a/komga/src/test/kotlin/org/gotson/komga/infrastructure/datasource/PostgreSQLIntegrationTest.kt +++ b/komga/src/test/kotlin/org/gotson/komga/infrastructure/datasource/PostgreSQLIntegrationTest.kt @@ -54,9 +54,4 @@ class PostgreSQLIntegrationTest { fun `should use PostgreSQL UDF provider`() { assertThat(databaseUdfProvider).isInstanceOf(PostgresUdfProvider::class.java) } - - @Test - fun `should provide correct database type`() { - assertThat(databaseUdfProvider.getDatabaseType()).isEqualTo(DatabaseType.POSTGRESQL) - } }