DROP VIEW IF EXISTS libraryUpdateErrorView;

CREATE TABLE IF NOT EXISTS libraryUpdateError (
    _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    manga_id INTEGER NOT NULL UNIQUE,
    message_id INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS libraryUpdateErrorMessage (
    _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    message TEXT NOT NULL UNIQUE
);

CREATE VIEW libraryUpdateErrorView AS
SELECT
    mangas._id AS mangaId,
    mangas.title AS mangaTitle,
    mangas.source,
    mangas.favorite,
    mangas.thumbnail_url AS thumbnailUrl,
    mangas.cover_last_modified AS coverLastModified,
    libraryUpdateError._id AS errorId,
    libraryUpdateError.message_id AS messageId
FROM mangas JOIN libraryUpdateError
ON mangas._id = libraryUpdateError.manga_id
WHERE favorite = 1;