Switch to H2 DB

This commit is contained in:
aditya.chandel
2025-01-17 10:58:42 -07:00
parent 0a37e0ec65
commit f5e1c1e7c8
9 changed files with 44 additions and 29 deletions
@@ -1,3 +1,4 @@
-- Create the library table
CREATE TABLE IF NOT EXISTS library
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
@@ -6,6 +7,7 @@ CREATE TABLE IF NOT EXISTS library
icon VARCHAR(64) NOT NULL
);
-- Create the library_path table
CREATE TABLE IF NOT EXISTS library_path
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
@@ -14,6 +16,7 @@ CREATE TABLE IF NOT EXISTS library_path
CONSTRAINT fk_library_path FOREIGN KEY (library_id) REFERENCES library (id)
);
-- Create the book table
CREATE TABLE IF NOT EXISTS book
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
@@ -27,11 +30,14 @@ CREATE TABLE IF NOT EXISTS book
epub_progress VARCHAR(1000) NULL,
CONSTRAINT fk_library FOREIGN KEY (library_id) REFERENCES library (id) ON DELETE CASCADE,
CONSTRAINT unique_file_library UNIQUE (file_name, library_id),
INDEX idx_library_id (library_id),
INDEX idx_last_read_time (last_read_time)
CONSTRAINT unique_file_library UNIQUE (file_name, library_id)
);
-- Create indexes for the book table
CREATE INDEX IF NOT EXISTS idx_library_id ON book (library_id);
CREATE INDEX IF NOT EXISTS idx_last_read_time ON book (last_read_time);
-- Create the book_metadata table
CREATE TABLE IF NOT EXISTS book_metadata
(
book_id BIGINT NOT NULL PRIMARY KEY,
@@ -50,6 +56,7 @@ CREATE TABLE IF NOT EXISTS book_metadata
CONSTRAINT fk_book_metadata FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE
);
-- Create the author table
CREATE TABLE IF NOT EXISTS author
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
@@ -57,12 +64,14 @@ CREATE TABLE IF NOT EXISTS author
CONSTRAINT unique_name UNIQUE (name)
);
-- Create the category table
CREATE TABLE IF NOT EXISTS category
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE
);
-- Create the book_viewer_setting table
CREATE TABLE IF NOT EXISTS book_viewer_setting
(
book_id BIGINT PRIMARY KEY,
@@ -73,6 +82,7 @@ CREATE TABLE IF NOT EXISTS book_viewer_setting
CONSTRAINT fk_book_viewer_setting FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE
);
-- Create the book_metadata_category_mapping table
CREATE TABLE IF NOT EXISTS book_metadata_category_mapping
(
book_id BIGINT NOT NULL,
@@ -82,18 +92,21 @@ CREATE TABLE IF NOT EXISTS book_metadata_category_mapping
CONSTRAINT fk_book_metadata_category_mapping_category FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE
);
-- Create the book_metadata_author_mapping table
CREATE TABLE IF NOT EXISTS book_metadata_author_mapping
(
book_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
PRIMARY KEY (book_id, author_id),
CONSTRAINT fk_book_metadata_author_mapping_book FOREIGN KEY (book_id) REFERENCES book_metadata (book_id) ON DELETE CASCADE,
CONSTRAINT fk_book_metadata_author_mapping_author FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE,
INDEX idx_book_metadata_id (book_id),
INDEX idx_author_id (author_id)
CONSTRAINT fk_book_metadata_author_mapping_author FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE
);
-- Create indexes for the book_metadata_author_mapping table
CREATE INDEX IF NOT EXISTS idx_book_metadata_id ON book_metadata_author_mapping (book_id);
CREATE INDEX IF NOT EXISTS idx_author_id ON book_metadata_author_mapping (author_id);
-- Create the shelf table
CREATE TABLE IF NOT EXISTS shelf
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
@@ -102,6 +115,7 @@ CREATE TABLE IF NOT EXISTS shelf
icon VARCHAR(64) NOT NULL
);
-- Create the book_shelf_mapping table
CREATE TABLE IF NOT EXISTS book_shelf_mapping
(
book_id BIGINT NOT NULL,
@@ -111,11 +125,12 @@ CREATE TABLE IF NOT EXISTS book_shelf_mapping
CONSTRAINT fk_book_shelf_mapping_shelf FOREIGN KEY (shelf_id) REFERENCES shelf (id) ON DELETE CASCADE
);
-- Create the app_settings table
CREATE TABLE app_settings
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
category VARCHAR(255) NOT NULL,
key1 VARCHAR(255) NOT NULL,
value TEXT NOT NULL,
UNIQUE (category, key1)
name VARCHAR(255) NOT NULL,
val TEXT NOT NULL,
UNIQUE (category, name)
);
@@ -1,12 +1,12 @@
INSERT INTO booklore.shelf (name, icon)
INSERT INTO shelf (name, icon)
VALUES ('Favorites', 'heart');
INSERT INTO app_settings (category, key1, value)
INSERT INTO app_settings (category, name, val)
VALUES ('epub', 'theme', 'white'),
('epub', 'fontSize', '120'),
('epub', 'font', 'serif');
INSERT INTO app_settings (category, key1, value)
INSERT INTO app_settings (category, name, val)
VALUES ('pdf', 'spread', 'odd'),
('pdf', 'zoom', 'page-fit'),
('pdf', 'sidebar', 'true');