62 lines
5.4 KiB
HTML
62 lines
5.4 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Migration to relax foreign key constraint on downloads.item_id Allows downloading items that haven’t been synced to local database yet"><title>MIGRATION_005 in jellytau_lib::storage::schema - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-17e0aaed.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="jellytau_lib" data-themes="" data-resource-suffix="" data-rustdoc-version="1.97.1 (8bab26f4f 2026-07-14)" data-channel="1.97.1" data-search-js="search-fd9372ac.js" data-stringdex-js="stringdex-2da4960a.js" data-settings-js="settings-170eb4bf.js" ><script src="../../../static.files/storage-41dd4d93.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-fcd733ba.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-f7c3ffd8.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc constant"><a class="skip-main-content" href="#main-content">Skip to main content</a><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">MIGRATION_005</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../jellytau_lib/index.html">jellytau_<wbr>lib</a><span class="version">0.10.1</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In jellytau_<wbr>lib::<wbr>storage::<wbr>schema</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content" tabindex="-1"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../index.html">jellytau_lib</a>::<wbr><a href="../index.html">storage</a>::<wbr><a href="index.html">schema</a></div><h1>Constant <span class="constant">MIGRATION_<wbr>005</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/jellytau_lib/storage/schema.rs.html#378-437">Source</a> </span></div><pre class="rust item-decl"><code>const MIGRATION_005: &<a class="primitive" href="https://doc.rust-lang.org/1.97.1/std/primitive.str.html">str</a> = r#"
|
||
-- Recreate downloads table without foreign key constraint on item_id
|
||
-- This allows downloading items that haven't been synced locally yet
|
||
|
||
CREATE TABLE IF NOT EXISTS downloads_new (
|
||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||
item_id TEXT NOT NULL, -- No foreign key constraint - item may not be synced yet
|
||
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||
|
||
-- File info
|
||
file_path TEXT NOT NULL,
|
||
file_size INTEGER,
|
||
mime_type TEXT,
|
||
|
||
-- Download state
|
||
status TEXT DEFAULT 'pending', -- pending, downloading, completed, failed, paused
|
||
progress REAL DEFAULT 0, -- 0.0 to 1.0
|
||
|
||
-- Transcoding options used
|
||
bitrate INTEGER,
|
||
container TEXT,
|
||
|
||
-- Timestamps
|
||
queued_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
||
started_at TEXT,
|
||
completed_at TEXT,
|
||
|
||
-- Error tracking
|
||
error_message TEXT,
|
||
retry_count INTEGER DEFAULT 0,
|
||
|
||
-- Priority and progress tracking (from migration 004)
|
||
priority INTEGER DEFAULT 0,
|
||
bytes_downloaded INTEGER DEFAULT 0,
|
||
|
||
UNIQUE(item_id, user_id)
|
||
);
|
||
|
||
-- Copy existing data
|
||
INSERT OR IGNORE INTO downloads_new (
|
||
id, item_id, user_id, file_path, file_size, mime_type, status, progress,
|
||
bitrate, container, queued_at, started_at, completed_at, error_message,
|
||
retry_count, priority, bytes_downloaded
|
||
)
|
||
SELECT
|
||
id, item_id, user_id, file_path, file_size, mime_type, status, progress,
|
||
bitrate, container, queued_at, started_at, completed_at, error_message,
|
||
retry_count, priority, bytes_downloaded
|
||
FROM downloads;
|
||
|
||
-- Drop old table and rename new one
|
||
DROP TABLE IF EXISTS downloads;
|
||
ALTER TABLE downloads_new RENAME TO downloads;
|
||
|
||
-- Recreate indexes
|
||
CREATE INDEX IF NOT EXISTS idx_downloads_status ON downloads(status);
|
||
CREATE INDEX IF NOT EXISTS idx_downloads_queue
|
||
ON downloads(status, priority DESC, queued_at ASC)
|
||
WHERE status IN ('pending', 'downloading');
|
||
"#;</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Migration to relax foreign key constraint on downloads.item_id
|
||
Allows downloading items that haven’t been synced to local database yet</p>
|
||
</div></details></section></div></main></body></html> |