From a9946caa0df69c7799e5909272968337453360e4 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 29 Jan 2026 07:34:52 +0100 Subject: init: remove database migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It never really quite worked, and it's honestly plain easier to move in/out the backup file than trying to figure out fake migration paths. Signed-off-by: Miquel Sabaté Solà --- lib/mihi/src/lib.rs | 26 +++--------- lib/mihi/src/migrate.rs | 102 ------------------------------------------------ 2 files changed, 5 insertions(+), 123 deletions(-) delete mode 100644 lib/mihi/src/migrate.rs (limited to 'lib') diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs index b6abf2f..e965fdf 100644 --- a/lib/mihi/src/lib.rs +++ b/lib/mihi/src/lib.rs @@ -10,8 +10,6 @@ use rusqlite::types::{FromSql, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; use rusqlite::Result; use rusqlite::{params, Connection}; -mod migrate; - /// Returns the configuration path for the application, and it even creates it /// if it doesn't exist already. pub fn get_config_path() -> Result { @@ -337,21 +335,6 @@ pub fn add_language(language: String) -> Result<(), String> { } } -/// Ensure that in the config path there is a fully initialized database. -pub fn init_database() -> Result<(), String> { - let name = &std::env::var("MIHI_DATABASE").unwrap_or("database.sqlite3".to_string()); - let path = get_config_path()?.join(name); - let conn = match Connection::open(path) { - Ok(handle) => handle, - Err(e) => return Err(format!("could not initialize the database: {e}")), - }; - - match migrate::init(conn) { - Ok(_) => Ok(()), - Err(e) => Err(format!("bad database schema file: {e}")), - } -} - /// Defines in which way two words are related. #[derive(Clone, Debug)] pub enum RelationKind { @@ -1245,11 +1228,12 @@ fn get_connection() -> Result { let name = &std::env::var("MIHI_DATABASE").unwrap_or("database.sqlite3".to_string()); let path = get_config_path()?.join(name); - match Connection::open(path) { + match Connection::open(&path) { Ok(handle) => Ok(handle), - Err(_) => Err( - "could not fetch the database. Ensure that you have called 'init' first".to_string(), - ), + Err(_) => Err(format!( + "could not fetch the database in '{}'", + path.display() + )), } } diff --git a/lib/mihi/src/migrate.rs b/lib/mihi/src/migrate.rs deleted file mode 100644 index b1ff0c3..0000000 --- a/lib/mihi/src/migrate.rs +++ /dev/null @@ -1,102 +0,0 @@ -use rusqlite::{Connection, Result}; - -/// Use the given `connection` in order to initialize the database. -pub fn init(connection: Connection) -> Result { - connection.execute( - r#" -CREATE TABLE IF NOT EXISTS "words" ( - "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, - "particle" varchar, - "enunciated" varchar, - "declension_id" integer, - "conjugation_id" integer, - "kind" varchar, - "category" integer, - "regular" boolean DEFAULT 1, - "locative" boolean DEFAULT 0, - "gender" integer, - "created_at" datetime(6) NOT NULL, - "updated_at" datetime(6) NOT NULL, - "suffix" varchar, - "language_id" integer NOT NULL, - "succeeded" integer DEFAULT 0 NOT NULL, - "steps" integer DEFAULT 0 NOT NULL, - "translation" jsonb DEFAULT '{}', - "pending" boolean DEFAULT 0, - "flags" jsonb DEFAULT '{}', - "weight" integer DEFAULT 0 NOT NULL, - - CHECK (weight >= 0 AND weight <= 10), - - FOREIGN KEY ("conjugation_id") REFERENCES "conjugations" ("id"), - FOREIGN KEY ("declension_id") REFERENCES "declensions" ("id") -); -"#, - (), - )?; - - connection.execute( - r#" -CREATE UNIQUE INDEX IF NOT EXISTS "index_words_on_enunciated" ON "words" ("enunciated"); -"#, - (), - )?; - - connection.execute( - r#" -CREATE TABLE IF NOT EXISTS "exercises" ( - "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, - "title" varchar NOT NULL, - "enunciate" text NOT NULL, - "solution" text NOT NULL, - "lessons" text NOT NULL, - "kind" integer DEFAULT 0, - "created_at" datetime(6) NOT NULL, - "updated_at" datetime(6) NOT NULL -); -"#, - (), - )?; - - connection.execute( - r#" -CREATE UNIQUE INDEX IF NOT EXISTS "index_exercises_on_title" ON "exercises" ("title"); -"#, - (), - )?; - - connection.execute( - r#" -CREATE TABLE IF NOT EXISTS "tags" ( - "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, - "name" varchar NOT NULL, - "created_at" datetime(6) NOT NULL, - "updated_at" datetime(6) NOT NULL -); -"#, - (), - )?; - - connection.execute( - r#" -CREATE TABLE IF NOT EXISTS "tag_associations" ( - "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, - "word_id" integer NOT NULL, - "tag_id" integer NOT NULL, - "created_at" datetime(6) NOT NULL, - "updated_at" datetime(6) NOT NULL -); -"#, - (), - )?; - - connection.execute( - r#" -CREATE UNIQUE INDEX IF NOT EXISTS "index_tags_on_name" ON "tags" ("name"); -CREATE UNIQUE INDEX IF NOT EXISTS "word_tag_unique" ON tag_associations (word_id, tag_id); -"#, - (), - )?; - - Ok(0) -} -- cgit v1.2.3