//! SQL migration strings for the `quotesdb` schema. //! //! These strings are run once on startup via [`super::QuoteRepository::run_migrations`]. //! Both the `D1Repository` (WASM) and `NativeRepository` (native) execute these //! in sequence. /// Creates the `quotes` table if it does not already exist. /// /// Stores one row per quote with all core fields. The `auth_code` is stored /// plaintext for simple passphrase-based ownership verification. pub const CREATE_QUOTES: &str = "\ CREATE TABLE IF NOT EXISTS quotes ( id TEXT PRIMARY KEY, text TEXT NOT NULL, author TEXT NOT NULL, source TEXT, date TEXT, auth_code TEXT NOT NULL, created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')) )"; /// Creates the `quote_tags` join table if it does not already exist. /// /// Uses `ON DELETE CASCADE` so tags are removed automatically when a quote /// is deleted. The composite primary key prevents duplicate tags per quote. pub const CREATE_QUOTE_TAGS: &str = "\ CREATE TABLE IF NOT EXISTS quote_tags ( quote_id TEXT NOT NULL REFERENCES quotes(id) ON DELETE CASCADE, tag TEXT NOT NULL, PRIMARY KEY (quote_id, tag) )"; /// Creates an index on `quote_tags.quote_id` to speed up tag lookups. pub const CREATE_TAG_INDEX: &str = "\ CREATE INDEX IF NOT EXISTS idx_quote_tags_quote_id ON quote_tags(quote_id)"; /// Creates a case-insensitive index on `quotes.author` for filter queries. pub const CREATE_AUTHOR_INDEX: &str = "\ CREATE INDEX IF NOT EXISTS idx_quotes_author ON quotes(author COLLATE NOCASE)"; /// Creates the `admin_config` key/value table for global configuration. /// /// Stores a single row for the admin auth code under key `admin_auth_code`. pub const CREATE_ADMIN_CONFIG: &str = "\ CREATE TABLE IF NOT EXISTS admin_config ( key TEXT PRIMARY KEY, value TEXT NOT NULL )";