This includes the patches to get from the initial version of the database to its current state - for the purpose of documentation. Beware, if you already have an existing database, running this code will likely result in an error and/or lead to some minor data loss. You need to follow these steps to fix your DB: 1. delete all *.sql files from unwind/sql/ 2. remove the .disabled suffix from unwind/sql/00000001-fix-db.sql.disabled 3. start the application once, this will fix up the database 4. revert all changes to unwind/sql/ – or leave it, it doesn't matter.
36 lines
873 B
SQL
36 lines
873 B
SQL
PRAGMA foreign_keys = ON;;
|
|
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id TEXT NOT NULL PRIMARY KEY,
|
|
imdb_id TEXT NOT NULL UNIQUE,
|
|
name TEXT NOT NULL
|
|
);;
|
|
|
|
CREATE TABLE IF NOT EXISTS movies (
|
|
id TEXT NOT NULL PRIMARY KEY,
|
|
title TEXT NOT NULL,
|
|
release_year NUMBER NOT NULL,
|
|
media_type TEXT NOT NULL,
|
|
imdb_id TEXT NOT NULL UNIQUE,
|
|
score NUMBER NOT NULL,
|
|
runtime NUMBER,
|
|
genres TEXT NOT NULL,
|
|
updated TEXT NOT NULL
|
|
);;
|
|
|
|
CREATE TABLE IF NOT EXISTS ratings (
|
|
id TEXT NOT NULL PRIMARY KEY,
|
|
movie_id TEXT NOT NULL,
|
|
user_id TEXT NOT NULL,
|
|
score NUMBER NOT NULL,
|
|
rating_date TEXT NOT NULL,
|
|
favorite NUMBER,
|
|
finished NUMBER,
|
|
FOREIGN KEY(movie_id) REFERENCES movies(id),
|
|
FOREIGN KEY(user_id) REFERENCES users(id)
|
|
);;
|
|
|
|
CREATE UNIQUE INDEX IF NOT EXISTS ratings_index ON ratings (
|
|
movie_id,
|
|
user_id
|
|
);;
|