add sql patching facilities
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.
This commit is contained in:
parent
ea8d97f901
commit
2c30a67e83
7 changed files with 272 additions and 18 deletions
37
unwind/sql/00000000-init-4.sql
Normal file
37
unwind/sql/00000000-init-4.sql
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
-- denormalize movie media_type
|
||||
|
||||
CREATE TABLE _migrate_movies (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
original_title TEXT,
|
||||
release_year INTEGER NOT NULL,
|
||||
media_type TEXT NOT NULL,
|
||||
imdb_id TEXT NOT NULL UNIQUE,
|
||||
score INTEGER,
|
||||
runtime INTEGER,
|
||||
genres TEXT NOT NULL,
|
||||
updated TEXT NOT NULL
|
||||
);;
|
||||
|
||||
INSERT INTO _migrate_movies
|
||||
SELECT
|
||||
id,
|
||||
title,
|
||||
original_title,
|
||||
release_year,
|
||||
(SELECT name FROM mediatypes WHERE id=media_type_id) AS media_type,
|
||||
imdb_id,
|
||||
score,
|
||||
runtime,
|
||||
genres,
|
||||
updated
|
||||
FROM movies
|
||||
WHERE true;;
|
||||
|
||||
DROP TABLE movies;;
|
||||
|
||||
ALTER TABLE _migrate_movies
|
||||
RENAME TO movies;;
|
||||
|
||||
DROP VIEW movies_view;;
|
||||
DROP TABLE mediatypes;;
|
||||
Loading…
Add table
Add a link
Reference in a new issue