mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2026-03-02 22:55:21 +01:00
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
14 lines
661 B
SQL
14 lines
661 B
SQL
-- Create book_authors junction table
|
|
CREATE TABLE IF NOT EXISTS book_authors (
|
|
id SERIAL PRIMARY KEY,
|
|
author INTEGER NOT NULL,
|
|
book INTEGER NOT NULL,
|
|
CONSTRAINT uc_book_authors_book_author UNIQUE (book, author),
|
|
CONSTRAINT fk_book_authors_authors_author_id FOREIGN KEY (author) REFERENCES authors(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
|
CONSTRAINT fk_book_authors_books_book_id FOREIGN KEY (book) REFERENCES books(id) ON UPDATE CASCADE ON DELETE CASCADE
|
|
);
|
|
|
|
-- Create indexes for book_authors
|
|
CREATE INDEX IF NOT EXISTS book_authors_author ON book_authors (author);
|
|
CREATE INDEX IF NOT EXISTS book_authors_book ON book_authors (book);
|