fix: sync database queries with enhanced media-items schema
- Add missing enhanced fields to CreateMediaItem INSERT statement - Add missing enhanced fields to UpdateMediaItem UPDATE statement - Include language, edition, page_count, genre, copyright_year - Include integration fields: goodreads_id, openlibrary_id, google_books_id - Add corresponding indexes for enhanced fields - Add column comments for better documentation - Resolves schema-query mismatch causing field removal cycles
This commit is contained in:
@@ -92,6 +92,15 @@ CREATE TABLE media_items (
|
||||
date_published DATE,
|
||||
publisher VARCHAR(255),
|
||||
contributors TEXT,
|
||||
-- Enhanced fields for better metadata and functionality
|
||||
language VARCHAR(10) DEFAULT 'en', -- Language code (ISO 639-1)
|
||||
edition VARCHAR(100), -- Edition information
|
||||
page_count INTEGER, -- Total page count
|
||||
genre VARCHAR(100), -- Genre classification
|
||||
copyright_year INTEGER, -- Copyright/publication year
|
||||
goodreads_id VARCHAR(50), -- Goodreads identifier
|
||||
openlibrary_id VARCHAR(50), -- Open Library identifier
|
||||
google_books_id VARCHAR(100), -- Google Books identifier
|
||||
added_by_admin_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||
@@ -215,6 +224,11 @@ CREATE INDEX idx_media_items_title ON media_items(title);
|
||||
CREATE INDEX idx_media_items_author ON media_items(author);
|
||||
CREATE INDEX idx_media_items_library_id ON media_items(library_id);
|
||||
CREATE INDEX idx_media_items_added_by_admin_id ON media_items(added_by_admin_id);
|
||||
CREATE INDEX idx_media_items_genre ON media_items(genre);
|
||||
CREATE INDEX idx_media_items_language ON media_items(language);
|
||||
CREATE INDEX idx_media_items_copyright_year ON media_items(copyright_year);
|
||||
CREATE INDEX idx_media_items_page_count ON media_items(page_count);
|
||||
CREATE INDEX idx_media_items_series ON media_items(series);
|
||||
|
||||
-- Progress and ratings indexes
|
||||
CREATE INDEX idx_reading_progress_media_item_id ON reading_progress(media_item_id);
|
||||
@@ -232,6 +246,16 @@ CREATE INDEX idx_media_highlights_note_id ON media_highlights(note_id);
|
||||
-- Add comment explaining the rating system
|
||||
COMMENT ON COLUMN media_ratings.rating IS 'Rating scale 1-10 (odd numbers = half-stars: 1,3,5,7,9 = 0.5,1.5,2.5,3.5,4.5 stars)';
|
||||
|
||||
-- Enhanced metadata comments
|
||||
COMMENT ON COLUMN media_items.language IS 'ISO 639-1 language code (e.g., en, es, fr)';
|
||||
COMMENT ON COLUMN media_items.copyright_year IS 'Copyright or publication year for filtering/sorting';
|
||||
COMMENT ON COLUMN media_items.page_count IS 'Total page count for progress tracking and sorting';
|
||||
COMMENT ON COLUMN media_items.genre IS 'Genre classification for filtering and discovery';
|
||||
COMMENT ON COLUMN media_items.edition IS 'Edition information (e.g., "First Edition", "Revised Edition")';
|
||||
COMMENT ON COLUMN media_items.goodreads_id IS 'Goodreads book identifier for integration';
|
||||
COMMENT ON COLUMN media_items.openlibrary_id IS 'Open Library identifier for integration';
|
||||
COMMENT ON COLUMN media_items.google_books_id IS 'Google Books identifier for integration';
|
||||
|
||||
-- Library Type File Extensions Notes:
|
||||
-- - Ebooks: .epub, .pdf, .mobi, .azw, .azw3, .txt, .rtf, .doc, .docx, .lit, .fb2, .pdb
|
||||
-- - Comics: .cbz, .cbr, .cb7, .cbt, .pdf
|
||||
|
||||
@@ -102,8 +102,8 @@ ORDER BY l.created_at DESC;
|
||||
|
||||
-- Media Items queries
|
||||
-- name: CreateMediaItem :one
|
||||
INSERT INTO media_items (library_id, title, author, isbn, description, file_path, file_size, mime_type, cover_image_path, series, series_number, tags, asin, date_published, publisher, contributors, added_by_admin_id)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
|
||||
INSERT INTO media_items (library_id, title, author, isbn, description, file_path, file_size, mime_type, cover_image_path, series, series_number, tags, asin, date_published, publisher, contributors, language, edition, page_count, genre, copyright_year, goodreads_id, openlibrary_id, google_books_id, added_by_admin_id)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetMediaItem :one
|
||||
@@ -256,6 +256,14 @@ UPDATE media_items SET
|
||||
date_published = $11,
|
||||
publisher = $12,
|
||||
contributors = $13,
|
||||
language = $14,
|
||||
edition = $15,
|
||||
page_count = $16,
|
||||
genre = $17,
|
||||
copyright_year = $18,
|
||||
goodreads_id = $19,
|
||||
openlibrary_id = $20,
|
||||
google_books_id = $21,
|
||||
updated_at = NOW()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
Reference in New Issue
Block a user