diff --git a/app/src/main/sqldelight/tachiyomi/migrations/17.sqm b/app/src/main/sqldelight/tachiyomi/migrations/17.sqm index 15afa33831..e6eb8ce3ec 100644 --- a/app/src/main/sqldelight/tachiyomi/migrations/17.sqm +++ b/app/src/main/sqldelight/tachiyomi/migrations/17.sqm @@ -1,5 +1,4 @@ import kotlin.Boolean; -import kotlin.Float; import kotlin.Long; CREATE TABLE extension_repos ( @@ -13,9 +12,6 @@ CREATE TABLE extension_repos ( --- >> Rename hideTitle to hide_title DROP INDEX IF EXISTS mangas_url_index; DROP INDEX IF EXISTS library_favorite_index; -DROP INDEX IF EXISTS chapters_manga_id_index; -DROP INDEX IF EXISTS chapters_unread_by_manga_index; -DROP INDEX IF EXISTS history_history_chapter_id_index; ALTER TABLE mangas RENAME TO mangas_tmp; CREATE TABLE mangas( @@ -47,100 +43,8 @@ SELECT initialized, viewer, hideTitle, chapter_flags, date_added, filtered_scanlators, update_strategy FROM mangas_tmp; -ALTER TABLE chapters RENAME TO chapters_tmp; -CREATE TABLE chapters( - _id INTEGER NOT NULL PRIMARY KEY, - manga_id INTEGER NOT NULL, - url TEXT NOT NULL, - name TEXT NOT NULL, - scanlator TEXT, - read INTEGER AS Boolean NOT NULL, - bookmark INTEGER AS Boolean NOT NULL, - last_page_read INTEGER NOT NULL, - pages_left INTEGER NOT NULL, - chapter_number REAL AS Float NOT NULL, - source_order INTEGER NOT NULL, - date_fetch INTEGER AS Long NOT NULL, - date_upload INTEGER AS Long NOT NULL, - FOREIGN KEY(manga_id) REFERENCES mangas (_id) - ON DELETE CASCADE -); -INSERT INTO chapters - (_id, manga_id, url, name, scanlator, read, bookmark, last_page_read, pages_left, chapter_number, source_order, - date_fetch, date_upload) -SELECT - _id, manga_id, url, name, scanlator, read, bookmark, last_page_read, pages_left, chapter_number, source_order, - date_fetch, date_upload -FROM chapters_tmp; - -ALTER TABLE history RENAME TO history_tmp; -CREATE TABLE history( - history_id INTEGER NOT NULL PRIMARY KEY, - history_chapter_id INTEGER NOT NULL UNIQUE, - history_last_read INTEGER AS Long, - history_time_read INTEGER AS Long, - FOREIGN KEY(history_chapter_id) REFERENCES chapters (_id) - ON DELETE CASCADE -); - -INSERT INTO history - (history_id, history_chapter_id, history_last_read, history_time_read) -SELECT - history_id, history_chapter_id, history_last_read, history_time_read -FROM history_tmp; - -ALTER TABLE mangas_categories RENAME TO mangas_categories_tmp; -CREATE TABLE mangas_categories( - _id INTEGER NOT NULL PRIMARY KEY, - manga_id INTEGER NOT NULL, - category_id INTEGER NOT NULL, - FOREIGN KEY(category_id) REFERENCES categories (_id) - ON DELETE CASCADE, - FOREIGN KEY(manga_id) REFERENCES mangas (_id) - ON DELETE CASCADE -); -INSERT INTO mangas_categories - (_id, manga_id, category_id) -SELECT - _id, manga_id, category_id -FROM mangas_categories_tmp; - -ALTER TABLE manga_sync RENAME TO manga_sync_tmp; -CREATE TABLE manga_sync( - _id INTEGER NOT NULL PRIMARY KEY, - manga_id INTEGER NOT NULL, - sync_id INTEGER NOT NULL, - remote_id INTEGER NOT NULL, - library_id INTEGER, - title TEXT NOT NULL, - last_chapter_read REAL NOT NULL, - total_chapters INTEGER NOT NULL, - status INTEGER NOT NULL, - score REAL AS Float NOT NULL, - remote_url TEXT NOT NULL, - start_date INTEGER AS Long NOT NULL, - finish_date INTEGER AS Long NOT NULL, - UNIQUE (manga_id, sync_id) ON CONFLICT REPLACE, - FOREIGN KEY(manga_id) REFERENCES mangas (_id) - ON DELETE CASCADE -); -INSERT INTO manga_sync - (_id, manga_id, sync_id, remote_id, library_id, title, last_chapter_read, total_chapters, status, score, remote_url, - start_date, finish_date) -SELECT - _id, manga_id, sync_id, remote_id, library_id, title, last_chapter_read, total_chapters, status, score, remote_url, - start_date, finish_date -FROM manga_sync_tmp; - -CREATE INDEX chapters_manga_id_index ON chapters(manga_id); -CREATE INDEX chapters_unread_by_manga_index ON chapters(manga_id, read) WHERE read = 0; -CREATE INDEX history_history_chapter_id_index ON history(history_chapter_id); -CREATE INDEX library_favorite_index ON mangas(favorite) WHERE favorite = 1; CREATE INDEX mangas_url_index ON mangas(url); +CREATE INDEX library_favorite_index ON mangas(favorite) WHERE favorite = 1; DROP TABLE IF EXISTS mangas_tmp; -DROP TABLE IF EXISTS chapters_tmp; -DROP TABLE IF EXISTS history_tmp; -DROP TABLE IF EXISTS mangas_categories_tmp; -DROP TABLE IF EXISTS manga_sync_tmp; --- << Rename hideTitle to hide_title diff --git a/app/src/main/sqldelight/tachiyomi/migrations/18.sqm b/app/src/main/sqldelight/tachiyomi/migrations/18.sqm new file mode 100644 index 0000000000..7575d736e3 --- /dev/null +++ b/app/src/main/sqldelight/tachiyomi/migrations/18.sqm @@ -0,0 +1,103 @@ +import kotlin.Boolean; +import kotlin.Float; +import kotlin.Long; + +--- >> Fix migration 17 mistake +DROP INDEX IF EXISTS chapters_manga_id_index; +DROP INDEX IF EXISTS chapters_unread_by_manga_index; +DROP INDEX IF EXISTS history_history_chapter_id_index; + +ALTER TABLE chapters RENAME TO chapters_tmp; +CREATE TABLE chapters( + _id INTEGER NOT NULL PRIMARY KEY, + manga_id INTEGER NOT NULL, + url TEXT NOT NULL, + name TEXT NOT NULL, + scanlator TEXT, + read INTEGER AS Boolean NOT NULL, + bookmark INTEGER AS Boolean NOT NULL, + last_page_read INTEGER NOT NULL, + pages_left INTEGER NOT NULL, + chapter_number REAL AS Float NOT NULL, + source_order INTEGER NOT NULL, + date_fetch INTEGER AS Long NOT NULL, + date_upload INTEGER AS Long NOT NULL, + FOREIGN KEY(manga_id) REFERENCES mangas (_id) + ON DELETE CASCADE +); +INSERT INTO chapters + (_id, manga_id, url, name, scanlator, read, bookmark, last_page_read, pages_left, chapter_number, source_order, + date_fetch, date_upload) +SELECT + _id, manga_id, url, name, scanlator, read, bookmark, last_page_read, pages_left, chapter_number, source_order, + date_fetch, date_upload +FROM chapters_tmp; + +ALTER TABLE history RENAME TO history_tmp; +CREATE TABLE history( + history_id INTEGER NOT NULL PRIMARY KEY, + history_chapter_id INTEGER NOT NULL UNIQUE, + history_last_read INTEGER AS Long, + history_time_read INTEGER AS Long, + FOREIGN KEY(history_chapter_id) REFERENCES chapters (_id) + ON DELETE CASCADE +); + +INSERT INTO history + (history_id, history_chapter_id, history_last_read, history_time_read) +SELECT + history_id, history_chapter_id, history_last_read, history_time_read +FROM history_tmp; + +ALTER TABLE mangas_categories RENAME TO mangas_categories_tmp; +CREATE TABLE mangas_categories( + _id INTEGER NOT NULL PRIMARY KEY, + manga_id INTEGER NOT NULL, + category_id INTEGER NOT NULL, + FOREIGN KEY(category_id) REFERENCES categories (_id) + ON DELETE CASCADE, + FOREIGN KEY(manga_id) REFERENCES mangas (_id) + ON DELETE CASCADE +); +INSERT INTO mangas_categories + (_id, manga_id, category_id) +SELECT + _id, manga_id, category_id +FROM mangas_categories_tmp; + +ALTER TABLE manga_sync RENAME TO manga_sync_tmp; +CREATE TABLE manga_sync( + _id INTEGER NOT NULL PRIMARY KEY, + manga_id INTEGER NOT NULL, + sync_id INTEGER NOT NULL, + remote_id INTEGER NOT NULL, + library_id INTEGER, + title TEXT NOT NULL, + last_chapter_read REAL NOT NULL, + total_chapters INTEGER NOT NULL, + status INTEGER NOT NULL, + score REAL AS Float NOT NULL, + remote_url TEXT NOT NULL, + start_date INTEGER AS Long NOT NULL, + finish_date INTEGER AS Long NOT NULL, + UNIQUE (manga_id, sync_id) ON CONFLICT REPLACE, + FOREIGN KEY(manga_id) REFERENCES mangas (_id) + ON DELETE CASCADE +); +INSERT INTO manga_sync + (_id, manga_id, sync_id, remote_id, library_id, title, last_chapter_read, total_chapters, status, score, remote_url, + start_date, finish_date) +SELECT + _id, manga_id, sync_id, remote_id, library_id, title, last_chapter_read, total_chapters, status, score, remote_url, + start_date, finish_date +FROM manga_sync_tmp; + +CREATE INDEX chapters_manga_id_index ON chapters(manga_id); +CREATE INDEX chapters_unread_by_manga_index ON chapters(manga_id, read) WHERE read = 0; +CREATE INDEX history_history_chapter_id_index ON history(history_chapter_id); + +DROP TABLE IF EXISTS chapters_tmp; +DROP TABLE IF EXISTS history_tmp; +DROP TABLE IF EXISTS mangas_categories_tmp; +DROP TABLE IF EXISTS manga_sync_tmp; +--- << Fix migration 17 mistake