24 lines
1.0 KiB
SQL
24 lines
1.0 KiB
SQL
-- A grab may target a whole season: one season-pack torrent satisfies every
|
|
-- episode in it (DESIGN.md §13 phase 6). SQLite cannot alter a CHECK, so the
|
|
-- table is rebuilt.
|
|
CREATE TABLE grabs_new (
|
|
id INTEGER PRIMARY KEY,
|
|
release_id INTEGER NOT NULL REFERENCES releases (id),
|
|
target_kind TEXT NOT NULL CHECK (target_kind IN ('movie', 'episode', 'season')),
|
|
target_id INTEGER NOT NULL,
|
|
infohash TEXT NOT NULL UNIQUE,
|
|
state TEXT NOT NULL DEFAULT 'sent'
|
|
CHECK (state IN ('sent', 'downloaded', 'imported', 'failed')),
|
|
grabbed_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
imported_at TEXT
|
|
) STRICT;
|
|
|
|
INSERT INTO grabs_new (id, release_id, target_kind, target_id, infohash, state, grabbed_at, imported_at)
|
|
SELECT id, release_id, target_kind, target_id, infohash, state, grabbed_at, imported_at FROM grabs;
|
|
|
|
DROP TABLE grabs;
|
|
ALTER TABLE grabs_new RENAME TO grabs;
|
|
|
|
CREATE INDEX grabs_state ON grabs (state);
|
|
CREATE INDEX grabs_target ON grabs (target_kind, target_id);
|