migrations: more database migrations for various database fixes
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I8567eec6980b2b5453687bcbd07a61206a6a6964
This commit is contained in:
parent
c4adc4e3e0
commit
56d44e120a
8 changed files with 418 additions and 0 deletions
18
migrations/sqlite/V9__fix_indexes_and_constraints.sql
Normal file
18
migrations/sqlite/V9__fix_indexes_and_constraints.sql
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
-- Drop redundant indexes (already covered by UNIQUE constraints)
|
||||
DROP INDEX IF EXISTS idx_users_username;
|
||||
DROP INDEX IF EXISTS idx_user_libraries_user_id;
|
||||
|
||||
-- Add missing indexes for comments table
|
||||
CREATE INDEX IF NOT EXISTS idx_comments_media ON comments(media_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_comments_parent ON comments(parent_comment_id);
|
||||
|
||||
-- Remove duplicates before adding unique index (keep the first row)
|
||||
DELETE FROM external_metadata
|
||||
WHERE rowid NOT IN (
|
||||
SELECT MIN(rowid)
|
||||
FROM external_metadata
|
||||
GROUP BY media_id, source
|
||||
);
|
||||
|
||||
-- Add unique index for external_metadata to prevent duplicates
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_external_metadata_source ON external_metadata(media_id, source);
|
||||
Loading…
Add table
Add a link
Reference in a new issue