mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2026-03-03 07:00:51 +01:00
Add DB migrations and run them on startup
Enable sqlx "migrate" feature and add SQL migrations to create the database schema: pg_trgm extension, sources, genres, authors, sequences, books, junction tables, annotations, and supporting indexes
This commit is contained in:
14
migrations/20260116092210_create_book_sequences_table.sql
Normal file
14
migrations/20260116092210_create_book_sequences_table.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Create book_sequences junction table
|
||||
CREATE TABLE IF NOT EXISTS book_sequences (
|
||||
id SERIAL PRIMARY KEY,
|
||||
position SMALLINT NOT NULL,
|
||||
sequence INTEGER NOT NULL,
|
||||
book INTEGER NOT NULL,
|
||||
CONSTRAINT uc_book_sequences_book_sequence UNIQUE (book, sequence),
|
||||
CONSTRAINT fk_book_sequences_sequences_sequence_id FOREIGN KEY (sequence) REFERENCES sequences(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
CONSTRAINT fk_book_sequences_books_book_id FOREIGN KEY (book) REFERENCES books(id) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Create indexes for book_sequences
|
||||
CREATE INDEX IF NOT EXISTS book_sequences_sequence ON book_sequences (sequence);
|
||||
CREATE INDEX IF NOT EXISTS book_sequences_book ON book_sequences (book);
|
||||
Reference in New Issue
Block a user